private void AddPlaylistToList(string playlistURL)
        {
            string playlistID = Regex.Match(playlistURL, @"(PL|UU|UC)[\w-]*").Value;

            if (playlistID.StartsWith("UC"))
            {
                playlistID = playlistID.Replace("UC", "UU");
            }
            else if (playlistURL.Contains("/user/"))
            {
                playlistID = GetChannelId(playlistURL).Replace("UC", "UU");
            }

            if (string.IsNullOrEmpty(playlistID))
            {
                MessageBox.Show($"Could not find a playlist ID for {playlistURL}");
                return;
            }

            Subscription playlistSubscription = YouTubeFunctions.GetPlaylistAsSubscription(playlistID);

            playlistSubscription.FilterRegex = textBoxRegex.Text;

            Add(playlistSubscription);
        }
        private void ButtonGetYTSubscriptions_Click(object sender, EventArgs e)
        {
            if (Settings.Instance.FirstTimeNotifySyncSetting)
            {
                MessageBox.Show("Tip: In the Settings, you can turn on \"Sync subscriptions with YouTube\" where the program will " +
                                "automatically start tracking any new channels you subscribe to on YouTube (and stop tracking " +
                                "unsubscribed ones)");
                Settings.Instance.FirstTimeNotifySyncSetting = false;
            }

            Cursor.Current = Cursors.WaitCursor;

            List <Subscription> existingSubs = GetGridSubs();

            Task <List <Subscription> > getUserSubs = Task.Run(() => YouTubeFunctions.GetUserSubscriptionsAsync(CancellationToken.None, true));

            getUserSubs.Wait();
            List <Subscription> userSubs = getUserSubs.Result;

            foreach (Subscription sub in userSubs)
            {
                //Make sure it is not already in the list
                if (existingSubs.FirstOrDefault(p => p.PlaylistIdToWatch == sub.PlaylistIdToWatch) == null)
                {
                    Add(sub);
                }
            }

            gridPlaylists.FirstDisplayedScrollingRowIndex = gridPlaylists.RowCount - 1; //Scroll to bottom of list to show item was added
            Cursor.Current = Cursors.Default;
        }
Exemple #3
0
        public Main(bool start = false)
        {
            InitializeComponent();
            this.HandleCreated += Form1_HandleCreated;

            if (!Directory.Exists(Common.UserSettings))
            {
                Directory.CreateDirectory(Common.UserSettings);
            }

            Log("Reading settings...");
            Settings.ReadSettings();

            Common.InitializePocket();
            InitializeTimer();

            if (YouTubeFunctions.Service == null)
            {
                Log("Authorizing YouTube...");
                YouTubeFunctions.AuthService();
            }

            if (Settings.Instance.FirstTimeShowSubscriptionManager)
            {
                MessageBox.Show("Welcome to YouTube Subscription Downloader!\n\nSince this is your first time running the program, " +
                                "we'll show you the Subscription Manager where you can set up your tracked subscriptions");

                SubscriptionManager manager = new SubscriptionManager();
                manager.ShowDialog();

                Settings.Instance.FirstTimeShowSubscriptionManager = false;
            }
            if (File.Exists(Common.SubscriptionsPath)) //Don't show the message if there are no subscriptions saved (eg first time startup)
            {
                Log("Getting subscriptions...");
                Common.DeserializeSubscriptions();

                if (!Settings.Instance.CheckForMissedUploads)
                {
                    Common.TrackedSubscriptions.ForEach(p => p.LastVideoPublishDate = DateTime.Now);
                }
            }

            Log("Ready!");

            if (Settings.Instance.StartIterationsOnStartup || start)
            {
                Start(cancelTokenSource.Token);
            }
        }
Exemple #4
0
        private void CheckForNewVideoFromSubscriptionsAsync(CancellationToken token, bool showNotifications = true)
        {
            if (!Common.HasInternetConnection())
            {
                Log("!!NO INTERNET CONNECTION!!");
                return;
            }

            if (Settings.Instance.SyncSubscriptionsWithYouTube)
            {
                YouTubeFunctions.UpdateYTSubscriptions().Wait();
            }

            bool tempNotificationSetting = Settings.Instance.ShowNotifications;

            if (!showNotifications)
            {
                Settings.Instance.ShowNotifications = false;
            }

            foreach (Subscription sub in Common.TrackedSubscriptions)
            {
                if (token.IsCancellationRequested)
                {
                    return;
                }

                List <PlaylistItem> newUploads = YouTubeFunctions.GetMostRecentUploadsAsync(sub, sub.LastVideoPublishDate).Result;
                foreach (PlaylistItem item in newUploads)
                {
                    PlaylistItemSnippet newUploadDetails = item.Snippet;
                    Log("New uploaded detected: " + sub.Title + " (" + newUploadDetails.Title + ")");
                    DoActionsForNewUpload(newUploadDetails, sub, token);
                }

                if (newUploads.Count > 0)
                {
                    sub.LastVideoPublishDate = (DateTime)newUploads.First().Snippet.PublishedAt;
                }
            }

            Settings.Instance.ShowNotifications = tempNotificationSetting;

            Common.SerializeSubscriptions();
        }
Exemple #5
0
 private void DownloadYouTubeVideo(string youTubeVideoId, string destinationFolder, CancellationToken token)
 {
     Log("Downloading video...");
     _ = YouTubeFunctions.DownloadYouTubeVideoAsync(youTubeVideoId, destinationFolder, token);
 }