-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from SRGSSR/develop
📻 Recommendation for RTS audio content
- Loading branch information
Showing
22 changed files
with
1,469 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
Playfff - Recommendation | ||
============= | ||
|
||
## About | ||
|
||
Playfff is the middleware to deliver recommendations for Play SRG mobile applications. | ||
|
||
## Compatibility | ||
|
||
Since July 2018, Play Android (2.0.207 and more) and Play iOS (2.8.3-272 and more) applications currently use it. | ||
|
||
## Recommendation type | ||
|
||
### Media ecommendation list for a media | ||
|
||
The API doesn't not support paginations, so mobile applications didn't implement pagination. The media recommendation list must have at least 49 items, the 50th is the requested media itself. | ||
|
||
#### RTS `urn.contains(":rts:")` | ||
|
||
- For videos `urn.contains(":video:")`, ask Peach recommendation `continuous_playback_mobile`. | ||
- For audios `urn.contains(":audio:")`: | ||
- Get `IL-Media`. It returns an empty list if it's a `LIVESTREAM` or a `SCHEDULED_LIVESTREAM`. | ||
- Get `IL-EpisodeComposition`, last 100 episodes. Sort in date ascending order. | ||
- Determine if the media is a full length or a clip. Separate full length list and the clip list. | ||
- Get the media position in the related lists. Split oldests and newests. | ||
- Recommendation list: | ||
- Newest medias in date ascending order. Then: | ||
- if `nextUrl` exists (show has more than 100 episodes), oldest medias in date descending order. - else (show has less than 100 episodes), oldest medias in date ascending order. | ||
|
||
#### Other BUs | ||
|
||
- No recommendation provided. It returns an empty list. | ||
|
||
## License | ||
|
||
To be defined. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.example.pfff.model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonValue; | ||
|
||
/** | ||
* Copyright (c) SRG SSR. All rights reserved. | ||
* <p> | ||
* License information is available from the LICENSE file. | ||
*/ | ||
public enum Environment { | ||
PROD("il.srgssr.ch"), | ||
STAGE("il-stage.srgssr.ch"), | ||
TEST("il-test.srgssr.ch"), | ||
MMF("play-mmf.herokuapp.com"); | ||
|
||
Environment(String url) { | ||
this.name = name().toLowerCase(); | ||
this.baseUrl = url; | ||
} | ||
|
||
private String name; | ||
private String baseUrl; | ||
|
||
public static Environment fromValue(String v) { | ||
return valueOf(v.toUpperCase()); | ||
} | ||
|
||
public String getBaseUrl() { | ||
return baseUrl; | ||
} | ||
|
||
@JsonValue | ||
@Override | ||
public String toString() { | ||
return name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
src/main/java/com/example/pfff/service/IntegrationLayerRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package com.example.pfff.service; | ||
|
||
import ch.srg.il.domain.v2_0.EpisodeComposition; | ||
import ch.srg.il.domain.v2_0.Media; | ||
import ch.srg.il.domain.v2_0.Show; | ||
import ch.srg.jaxb.SrgUnmarshaller; | ||
import com.example.pfff.model.Environment; | ||
import org.assertj.core.util.VisibleForTesting; | ||
import org.eclipse.persistence.oxm.MediaType; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.boot.web.client.RestTemplateBuilder; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import java.net.URI; | ||
import java.time.ZonedDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
/** | ||
* Copyright (c) SRG SSR. All rights reserved. | ||
* <p> | ||
* License information is available from the LICENSE file. | ||
*/ | ||
@Service | ||
public class IntegrationLayerRequest { | ||
private static final Logger logger = LoggerFactory.getLogger(IntegrationLayerRequest.class); | ||
public static final int PORT = 80; | ||
|
||
private RestTemplate restTemplate; | ||
|
||
public IntegrationLayerRequest(RestTemplateBuilder restTemplateBuilder) { | ||
restTemplate = restTemplateBuilder.build(); | ||
} | ||
|
||
public EpisodeComposition getEpisodeCompositionLatestByShow(String showURN, ZonedDateTime maxPublishedDate, int pageSize, Environment environment) { | ||
String path = "/integrationlayer/2.0/episodeComposition/latestByShow/byUrn/" + showURN + ".json"; | ||
String query = "pageSize=" + pageSize; | ||
if (maxPublishedDate != null) { | ||
query += "&maxPublishedDate=" + DateTimeFormatter.ofPattern("yyyy-MM-dd").format(maxPublishedDate); | ||
} | ||
try { | ||
URI uri = new URI("http", null, environment.getBaseUrl(), PORT, path, query, null); | ||
ResponseEntity<String> responseEntity = restTemplate.getForEntity(uri, String.class); | ||
SrgUnmarshaller unmarshaller = new SrgUnmarshaller(); | ||
return unmarshaller.unmarshal(responseEntity.getBody(), MediaType.APPLICATION_JSON, EpisodeComposition.class); | ||
} catch (Exception e) { | ||
logger.warn("http://{}{} : {}", environment.getBaseUrl(), path, e.getMessage()); | ||
return null; | ||
} | ||
} | ||
|
||
public Media getMedia(String mediaURN, Environment environment) { | ||
String path = "/integrationlayer/2.0/media/byUrn/" + mediaURN + ".json"; | ||
try { | ||
URI uri = new URI("http", null, environment.getBaseUrl(), PORT, path, null, null); | ||
ResponseEntity<String> responseEntity = restTemplate.getForEntity(uri, String.class); | ||
SrgUnmarshaller unmarshaller = new SrgUnmarshaller(); | ||
return unmarshaller.unmarshal(responseEntity.getBody(), MediaType.APPLICATION_JSON, Media.class); | ||
} catch (Exception e) { | ||
logger.warn("http://{}{} : {}", environment.getBaseUrl(), path, e.getMessage()); | ||
return null; | ||
} | ||
} | ||
|
||
public Show getShow(String showURN, Environment environment) { | ||
String path = "/integrationlayer/2.0/show/byUrn/" + showURN + ".json"; | ||
try { | ||
URI uri = new URI("http", null, environment.getBaseUrl(), PORT, path, null, null); | ||
ResponseEntity<String> responseEntity = restTemplate.getForEntity(uri, String.class); | ||
SrgUnmarshaller unmarshaller = new SrgUnmarshaller(); | ||
return unmarshaller.unmarshal(responseEntity.getBody(), MediaType.APPLICATION_JSON, Show.class); | ||
} catch (Exception e) { | ||
logger.warn("http://{}{} : {}", environment.getBaseUrl(), path, e.getMessage()); | ||
return null; | ||
} | ||
} | ||
|
||
@VisibleForTesting | ||
public RestTemplate getRestTemplate() { | ||
return restTemplate; | ||
} | ||
|
||
@VisibleForTesting | ||
public void setRestTemplate(RestTemplate restTemplate) { | ||
this.restTemplate = restTemplate; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.