From 33f7ab8cd12ec145b41399f230150743e4e02816 Mon Sep 17 00:00:00 2001 From: Tyler Mayoff Date: Thu, 19 Jun 2025 21:12:10 -0400 Subject: [PATCH] cleanup and added api key as a setting, this will probably need documenting how to set this up in the Google Cloud Console --- .../Youtube/YoutubeImportListBase.cs | 4 ++-- .../ImportLists/Youtube/YoutubePlaylist.cs | 20 ++++++------------- .../Youtube/YoutubePlaylistSettings.cs | 3 ++- .../Youtube/YoutubeSettingsBase.cs | 13 ------------ 4 files changed, 10 insertions(+), 30 deletions(-) diff --git a/src/NzbDrone.Core/ImportLists/Youtube/YoutubeImportListBase.cs b/src/NzbDrone.Core/ImportLists/Youtube/YoutubeImportListBase.cs index 83ba1d2cc..01bb42105 100644 --- a/src/NzbDrone.Core/ImportLists/Youtube/YoutubeImportListBase.cs +++ b/src/NzbDrone.Core/ImportLists/Youtube/YoutubeImportListBase.cs @@ -13,7 +13,7 @@ using NzbDrone.Core.Parser.Model; namespace NzbDrone.Core.ImportLists.Youtube { public abstract class YoutubeImportListBase : ImportListBase - where TSettings : YoutubeSettingsBase, new() + where TSettings : YoutubePlaylistSettings, new() { private IHttpClient _httpClient; @@ -36,7 +36,7 @@ namespace NzbDrone.Core.ImportLists.Youtube using (var service = new YouTubeService(new BaseClientService.Initializer() { - ApiKey = "" + ApiKey = Settings.YoutubeApiKey, })) { releases = Fetch(service); diff --git a/src/NzbDrone.Core/ImportLists/Youtube/YoutubePlaylist.cs b/src/NzbDrone.Core/ImportLists/Youtube/YoutubePlaylist.cs index 417f41b05..1a0027f79 100644 --- a/src/NzbDrone.Core/ImportLists/Youtube/YoutubePlaylist.cs +++ b/src/NzbDrone.Core/ImportLists/Youtube/YoutubePlaylist.cs @@ -32,15 +32,15 @@ namespace NzbDrone.Core.ImportLists.Youtube public IList Fetch(YouTubeService service, string playlistId) { - // TODO playlist var results = new List(); var req = service.PlaylistItems.List("contentDetails,snippet"); req.PlaylistId = playlistId; req.MaxResults = 50; - - while (true) + var page = 0; + var playlist = req.Execute(); + do { - var playlist = req.Execute(); + page++; req.PageToken = playlist.NextPageToken; foreach (var song in playlist.Items) @@ -61,12 +61,9 @@ namespace NzbDrone.Core.ImportLists.Youtube results.Add(listItem); } - if (playlist.NextPageToken == null) - { - break; - } + playlist = req.Execute(); } - + while (playlist.NextPageToken != null && page < 10); return results; } @@ -97,10 +94,5 @@ namespace NzbDrone.Core.ImportLists.Youtube { return (playlistItem.ContentDetails.VideoPublishedAtDateTimeOffset ?? DateTimeOffset.UnixEpoch).DateTime; } - - public override object RequestAction(string action, IDictionary query) - { - return base.RequestAction(action, query); - } } } diff --git a/src/NzbDrone.Core/ImportLists/Youtube/YoutubePlaylistSettings.cs b/src/NzbDrone.Core/ImportLists/Youtube/YoutubePlaylistSettings.cs index 9e3a4fb51..12c5eab17 100644 --- a/src/NzbDrone.Core/ImportLists/Youtube/YoutubePlaylistSettings.cs +++ b/src/NzbDrone.Core/ImportLists/Youtube/YoutubePlaylistSettings.cs @@ -23,7 +23,8 @@ namespace NzbDrone.Core.ImportLists.Youtube PlaylistIds = System.Array.Empty(); } - // public override string Scope => "playlist-read-private"; + [FieldDefinition(1, Label = "Youtube API key", Type = FieldType.Textbox)] + public string YoutubeApiKey { get; set; } [FieldDefinition(1, Label = "Playlists", Type = FieldType.Textbox)] public IEnumerable PlaylistIds { get; set; } diff --git a/src/NzbDrone.Core/ImportLists/Youtube/YoutubeSettingsBase.cs b/src/NzbDrone.Core/ImportLists/Youtube/YoutubeSettingsBase.cs index 76015da92..73fd4191b 100644 --- a/src/NzbDrone.Core/ImportLists/Youtube/YoutubeSettingsBase.cs +++ b/src/NzbDrone.Core/ImportLists/Youtube/YoutubeSettingsBase.cs @@ -1,6 +1,4 @@ -using System; using FluentValidation; -using NzbDrone.Core.Annotations; using NzbDrone.Core.Validation; namespace NzbDrone.Core.ImportLists.Youtube @@ -17,17 +15,6 @@ namespace NzbDrone.Core.ImportLists.Youtube public string BaseUrl { get; set; } - public virtual string Scope => ""; - - [FieldDefinition(0, Label = "Access Token", Type = FieldType.Textbox, Hidden = HiddenType.Hidden)] - public string AccessToken { get; set; } - - [FieldDefinition(0, Label = "Refresh Token", Type = FieldType.Textbox, Hidden = HiddenType.Hidden)] - public string RefreshToken { get; set; } - - [FieldDefinition(0, Label = "Expires", Type = FieldType.Textbox, Hidden = HiddenType.Hidden)] - public DateTime Expires { get; set; } - public NzbDroneValidationResult Validate() { return new NzbDroneValidationResult(Validator.Validate((TSettings)this));