From 15bed353e5752e38436d333feb516bb60cd80dfc Mon Sep 17 00:00:00 2001 From: Stefan Cruz <17972991+stefancruz@users.noreply.github.com> Date: Sat, 22 Jun 2024 14:51:20 +0100 Subject: [PATCH] refact: refact getPlaylistsByUsername so it can later be reused --- src/DailymotionScript.ts | 44 ++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/DailymotionScript.ts b/src/DailymotionScript.ts index 7b3e0b4..4378be7 100644 --- a/src/DailymotionScript.ts +++ b/src/DailymotionScript.ts @@ -251,11 +251,11 @@ source.getPlaylist = (url: string): PlatformPlaylistDetails => { return getLikePlaylist(config.id, httpClient, usePlatformAuth, thumbnailResolutionIndex); } - if(url === FAVORITES_PLAYLIST_ID) { + if (url === FAVORITES_PLAYLIST_ID) { return getFavoritesPlaylist(config.id, httpClient, usePlatformAuth, thumbnailResolutionIndex); } - if(url === RECENTLY_WATCHED_PLAYLIST_ID) { + if (url === RECENTLY_WATCHED_PLAYLIST_ID) { return getRecentlyWatchedPlaylist(config.id, httpClient, usePlatformAuth, thumbnailResolutionIndex); } @@ -396,11 +396,28 @@ source.getUserPlaylists = (): string[] => { const userName = (jsonResponse?.data?.me?.channel as Channel)?.name; - return getPlaylistsByUsername(userName, headers, true); + const playlists = getPlaylistsByUsername(userName, headers, true); + + [ + LIKE_PLAYLIST_ID, + FAVORITES_PLAYLIST_ID, + RECENTLY_WATCHED_PLAYLIST_ID + ].forEach(playlistId => { + + if (!authenticatedPlaylistCollection.includes(playlistId)) { + authenticatedPlaylistCollection.push(playlistId); + } + + if (!playlists.includes(playlistId)) { + playlists.push(playlistId); + } + }); + + return playlists; } -function getPlaylistsByUsername(userName, headers, usePlatformAuth = false) { +function getPlaylistsByUsername(userName, headers, usePlatformAuth = false): string[] { const collections = executeGqlQuery( @@ -421,7 +438,7 @@ function getPlaylistsByUsername(userName, headers, usePlatformAuth = false) { } ); - const playlists = collections.data.channel.collections.edges.map(edge => { + const playlists: string[] = collections.data.channel.collections.edges.map(edge => { const playlistUrl = `${BASE_URL_PLAYLIST}/${edge.node.xid}`; if (!authenticatedPlaylistCollection.includes(playlistUrl)) { authenticatedPlaylistCollection.push(playlistUrl); @@ -429,23 +446,6 @@ function getPlaylistsByUsername(userName, headers, usePlatformAuth = false) { return playlistUrl; }); - - [ - LIKE_PLAYLIST_ID, - FAVORITES_PLAYLIST_ID, - RECENTLY_WATCHED_PLAYLIST_ID - ].forEach(playlistId => { - - if (!authenticatedPlaylistCollection.includes(playlistId)) { - authenticatedPlaylistCollection.push(playlistId); - } - - if (!playlists.includes(playlistId)) { - playlists.push(playlistId); - } - }); - - return playlists; } -- GitLab