diff --git a/src/DailymotionScript.ts b/src/DailymotionScript.ts index 215274ddacf7624fa1ab8f9715c90f09f4987edd..188f8c4c72d0039a8ecdde769acd750d7903a69c 100644 --- a/src/DailymotionScript.ts +++ b/src/DailymotionScript.ts @@ -3,6 +3,7 @@ let _settings: IDailymotionPluginSettings; const LIKE_PLAYLIST_ID = "LIKE_PLAYLIST_ID"; const FAVORITES_PLAYLIST_ID = "FAVORITES_PLAYLIST_ID"; +const RECENTLY_WATCHED_PLAYLIST_ID = "RECENTLY_WATCHED_PLAYLIST_ID"; import { @@ -48,7 +49,8 @@ import { getAnonymousUserTokenSingleton, getQuery, getLikePlaylist, - getFavoritesPlaylist + getFavoritesPlaylist, + getRecentlyWatchedPlaylist } from './util'; import { @@ -227,7 +229,10 @@ source.getContentDetails = function (url) { //Playlist source.isPlaylistUrl = (url): boolean => { - return url.startsWith(BASE_URL_PLAYLIST) || url === LIKE_PLAYLIST_ID || url === FAVORITES_PLAYLIST_ID; + return url.startsWith(BASE_URL_PLAYLIST) || + url === LIKE_PLAYLIST_ID || + url === FAVORITES_PLAYLIST_ID || + url === RECENTLY_WATCHED_PLAYLIST_ID; }; source.searchPlaylists = (query, type, order, filters) => { @@ -249,6 +254,10 @@ source.getPlaylist = (url: string): PlatformPlaylistDetails => { return getFavoritesPlaylist(config.id, httpClient, usePlatformAuth); } + if(url === RECENTLY_WATCHED_PLAYLIST_ID) { + return getRecentlyWatchedPlaylist(config.id, httpClient, usePlatformAuth); + } + const xid = url.split('/').pop(); const variables = { @@ -423,7 +432,8 @@ function getPlaylistsByUsername(userName, headers, usePlatformAuth = false) { [ LIKE_PLAYLIST_ID, - FAVORITES_PLAYLIST_ID + FAVORITES_PLAYLIST_ID, + RECENTLY_WATCHED_PLAYLIST_ID ].forEach(playlistId => { if (!authenticatedPlaylistCollection.includes(playlistId)) { diff --git a/src/gqlQueries.ts b/src/gqlQueries.ts index aa9fe5586223ccb6aaeb710d8610939ffeeae9ef..72c04791dcc5ff5378bb306798051cd144c35b92 100644 --- a/src/gqlQueries.ts +++ b/src/gqlQueries.ts @@ -993,7 +993,7 @@ export const GET_FAVORITES_GQL_QUERY = ` } __typename } - watchLaterMedias(first: 30, page: $page) { + watchLaterMedias(first: 100, page: $page) { edges { node { ... on Video { @@ -1024,6 +1024,7 @@ export const GET_FAVORITES_GQL_QUERY = ` id xid title + isOnAir thumbnail(height: PORTRAIT_1080) { url } @@ -1056,4 +1057,47 @@ export const GET_FAVORITES_GQL_QUERY = ` } + ` + + + export const GET_RECENTLY_WATCHED_GQL_QUERY = ` + query USER_WATCH_LATER_VIDEOS_QUERY($page: Int!) { + me { + id + stats { + id + watchedVideos { + id + total + __typename + } + __typename + } + watchedVideos(first: 100, page: $page) { + edges { + node { + id + xid + title + duration + thumbnail(height: PORTRAIT_1080) { + url + } + aspectRatio + channel { + id + logoURLx25: logoURL(size: "x25") + displayName + accountType + } + } + } + pageInfo { + hasNextPage + nextPage + } + } + } +} + ` \ No newline at end of file diff --git a/src/util.ts b/src/util.ts index 505391d3a968ba3d9b8ab110402b9efa496a747d..cb403795b68ab76165c784eb098028a357924d60 100644 --- a/src/util.ts +++ b/src/util.ts @@ -16,7 +16,7 @@ import { BASE_URL_API_AUTH, DURATION_THRESHOLDS, } from './constants' -import { GET_FAVORITES_GQL_QUERY, GET_LIKED_VIDEOS_GQL_QUERY } from './gqlQueries'; +import { GET_FAVORITES_GQL_QUERY, GET_LIKED_VIDEOS_GQL_QUERY, GET_RECENTLY_WATCHED_GQL_QUERY } from './gqlQueries'; export function getPreferredCountry(preferredCountryIndex) { const countryName = COUNTRY_NAMES[preferredCountryIndex]; @@ -388,4 +388,30 @@ export function getFavoritesPlaylist(pluginId: string, httpClient: IHttp, usePla } return SourceCollectionToGrayjayPlaylistDetails(pluginId, collection as Collection, videos); -} \ No newline at end of file +} + +export function getRecentlyWatchedPlaylist(pluginId: string, httpClient: IHttp, usePlatformAuth: boolean = false): PlatformPlaylistDetails { + + const videos: PlatformVideo[] = getPages<Maybe<User>, PlatformVideo>( + httpClient, + GET_RECENTLY_WATCHED_GQL_QUERY, + 'USER_WATCH_LATER_VIDEOS_QUERY', + { + page: 1 + }, + usePlatformAuth, + (jsonResponse) => jsonResponse?.data?.me,//set root + (me) => (me?.watchedVideos?.edges.length ?? 0) > 0 ?? false,//hasNextCallback + (me, currentPage) => ++currentPage, //getNextPage + (me) => me?.watchedVideos?.edges.map(edge => { + return SourceVideoToGrayjayVideo(pluginId, edge.node as Video); + })); + + const collection = { + "id": generateUUIDv4(), + "name": "Recently Watched", + "creator": {} + } + + return SourceCollectionToGrayjayPlaylistDetails(pluginId, collection as Collection, videos); +}