Skip to content

Commit

Permalink
Merge branch 'feature/related-content' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
pyby committed Dec 1, 2020
2 parents 48a2b6f + f660f48 commit e6a7b47
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 32 deletions.
11 changes: 8 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,22 @@ A wide list of parameters are available.

#### Recommendation for a media

* `/api/v2/playlist/recommendation/continuousPlayback/{urn}` : get media list object.
* `/api/v2/playlist/recommendation/continuousPlayback/{urn}` : get recommended medias for a continuous playback purpose.
* `standalone` (optional, boolean): Recommendation for the playback mode. Default is `false`.
* Returns a `recommendedList` object.

* *Deprecated* `/api/v1/playlist/recommendation/continuousPlayback/{urn}` : get media list object.
* `/api/v2/playlist/recommendation/relatedContent/{urn}` : get recommended medias for a related content purpose.
* `standalone` (optional, boolean): Recommendation for the playback mode. Default is `false`.
* Returns a `recommendedList` object.

* *Deprecated* `/api/v1/playlist/recommendation/continuousPlayback/{urn}` : get recommended medias for a continuous playback purpose. * `standalone` (optional, boolean): Recommendation for the playback mode. Default is `false`.
* `format` (optional, string): If set to `urn`, it returns an URN list. Default is `media` and redirects to an IL media list response.

More informations about the [recommendation engine](RECOMMENDATION.md) is available.

#### Personnal recommendation for a user

* `/api/v2/playlist/personalRecommendation` : get media list object.
* `/api/v2/playlist/personalRecommendation` : get personal recommended medias.
* `userId` (optional, string): `UserId` to use for a personal recommendation.
* Returns a `recommendedList` object.

Expand Down
44 changes: 36 additions & 8 deletions docs/RECOMMENDATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,43 @@ Playfff is the middleware to deliver recommendations for Play SRG mobile applica

Since July 2018, Play Android (2.0.207 and more) and Play iOS (2.8.3-272 and more) applications currently use this recommendation service.

## Recommendation type

### Media recommendation list for a media
## Media recommendation list for a media

The API doesn't not support paginations, therefore mobile applications didn't implement pagination. The media recommendation list must have at least 49 items, the 50th is the requested media.

#### RTS videos
### Purposes

- `continuousPlayback` is used to display one proposition, with a count down and an autoplay.
- `relatedContent` is used to display some propositions in a swimlane or a grid, without an autoplay.

| BU Content | Continuous playback | Related content |
| :--- | :---: | :---: |
| RSI audios | Pfff RE | Pfff RE |
| RSI videos | Pfff RE | Pfff RE |
| RTR audios | Pfff RE | Pfff RE |
| RTR videos | Pfff RE | Pfff RE |
| RTS audios | Pfff RE | Pfff RE |
| RTS videos | **RTS RE** | **RTS RE** |
| SRF audios | Pfff RE | **SRF RE** |
| SRF videos | Pfff RE | **SRF RE** |
| SWI videos | Pfff RE | Pfff RE |
| Event videos | N/A | N/A |
| Swisstxt videos | N/A | N/A |

### Recommendation engines used

#### RTS recommendation engine (RTS RE)

- For RTS videos, it asks `rts-datalab.azure-api` recommendation `continuous_playback_endscreen` service.
- For RTS videos, it can ask `rts-datalab.azure-api` recommendation `continuous_playback_endscreen` service, without personalization.

#### RSI, RTR, SRF, SWI videos and RSI, RTR, RTS and SRF audios
#### SRF recommendation engine (SRF RE)

- It asks Playfff recommendation. Based on IL requests, without personalization. Here is how it works:
- For SRF videos and SRF audios, it can ask `IL-MediaList` recommendation `Recommended-byUrn` service, without personalization.

#### Playfff recommendation engine (Pfff RE)

- For RSI, RTR, RTS, SRF, SWI videos and RSI, RTR, RTS, SRF audios, it can ask `Playfff` recommendation.
- Based on IL requests, without personalization. Here is how it works:
- Get `IL-Media`. It returns an empty list if it's a `LIVESTREAM` or a `SCHEDULED_LIVESTREAM`.
- Get `IL-EpisodeComposition` with last 100 episodes. Sort episodes with a date ascending order.
- Determine if the media is a full length or a clip.
Expand All @@ -40,10 +64,14 @@ The API doesn't not support paginations, therefore mobile applications didn't im

- No recommendation provided. It returns an empty list.

### Media recommendation list for a user
## Media recommendation list for a user

The API doesn't not support paginations, therefore mobile applications didn't implement pagination. The media recommendation list must have at least 50 items.

#### RTS

- With and without an `userId`, it asks `rts-datalab.azure-api` recommendation `play_home_personal_rec` service.

#### Other BUs

- Nothing implemented.
47 changes: 33 additions & 14 deletions src/main/java/ch/srgssr/playfff/service/RecommendationService.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,38 @@ public RecommendationService() {

public RecommendedList getRecommendedUrns(String purpose, String urnString, boolean standalone) {
IlUrn urn = new IlUrn(urnString);
switch (urn.getMam()) {
case RTS:
if (urn.getMediaType() == MediaType.VIDEO) {
return rtsVideoRecommendedList(purpose, urnString, standalone);
} else if (urn.getMediaType() == MediaType.AUDIO) {
return pfffRecommendedList(urnString, MediaType.AUDIO, standalone);
}
break;
case RSI:
case RTR:
case SRF:
case SWI:
return pfffRecommendedList(urnString, urn.getMediaType(), standalone);
if (purpose.equals("relatedContent")) {
switch (urn.getMam()) {
case RTS:
if (urn.getMediaType() == MediaType.VIDEO) {
return rtsVideoRecommendedList(purpose, urnString, standalone);
} else if (urn.getMediaType() == MediaType.AUDIO) {
return pfffRecommendedList(urnString, MediaType.AUDIO, standalone);
}
break;
case SRF:
return srfRecommendedList(purpose, urnString, standalone);
case RSI:
case RTR:
case SWI:
return pfffRecommendedList(urnString, urn.getMediaType(), standalone);
}
}
else {
switch (urn.getMam()) {
case RTS:
if (urn.getMediaType() == MediaType.VIDEO) {
return rtsVideoRecommendedList(purpose, urnString, standalone);
} else if (urn.getMediaType() == MediaType.AUDIO) {
return pfffRecommendedList(urnString, MediaType.AUDIO, standalone);
}
break;
case RSI:
case RTR:
case SRF:
case SWI:
return pfffRecommendedList(urnString, urn.getMediaType(), standalone);
}
}
return new RecommendedList();
}
Expand Down Expand Up @@ -196,7 +215,7 @@ public RecommendedList rtsPlayHomePersonalRecommendation(String userId) {
return new RecommendedList(result.getTitle(), url.getHost(), result.getRecommendationId(), result.getUrns());
}

private RecommendedList srfVideoRecommendedList(String purpose, String urn, boolean standalone) {
private RecommendedList srfRecommendedList(String purpose, String urn, boolean standalone) {
long timestamp = System.currentTimeMillis();

Environment environment = Environment.PROD;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
public class RecommendationIntegrationTest {
private MockMvc mvc;

private final String continuousplaybackPurpose = "continuousplayback";
private final String relatedContentPurpose = "relatedContent";

@Autowired
private WebApplicationContext context;

Expand All @@ -45,33 +48,39 @@ public void setup() {
public void getRecommendationRTSVideo() throws Exception {
String mediaURN = "urn:rts:video:9691670";

getRecommendation(mediaURN);
getRecommendation(mediaURN, continuousplaybackPurpose);

getRecommendation(mediaURN, relatedContentPurpose);
}

@Test
public void getRecommendationRTSVAudioFull() throws Exception {
String mediaURN = "urn:rts:audio:9866170";

getRecommendation(mediaURN);
getRecommendation(mediaURN, continuousplaybackPurpose);

getRecommendation(mediaURN, relatedContentPurpose);
}

@Test
public void getRecommendationRTSVAudioClip() throws Exception {
String mediaURN = "urn:rts:audio:10163388";

getRecommendation(mediaURN);
getRecommendation(mediaURN, continuousplaybackPurpose);

getRecommendation(mediaURN, relatedContentPurpose);
}

@Test
public void getRecommendationSRF() throws Exception {
String mediaURN = "urn:srf:video:859dc7e6-a155-41da-9d34-8f4eb800f73c";

getRecommendation(mediaURN);
}
getRecommendation(mediaURN, continuousplaybackPurpose);

public void getRecommendation(String mediaURN) throws Exception {
String purpose = "continuousplayback";
getRecommendation(mediaURN, relatedContentPurpose);
}

public void getRecommendation(String mediaURN, String purpose) throws Exception {
mvc.perform(get("/api/v1/playlist/recommendation/" + purpose + "/" + mediaURN)).andExpect(status().isFound()).andExpect(content().string(""));

checkRecommendationWithRedirect(purpose, mediaURN, "false");
Expand Down

0 comments on commit e6a7b47

Please sign in to comment.