Exemplo n.º 1
0
        void ExtractionProgress(double ProgressPercentage, Downloadable d)
        {
            d.Preparing = false;
            string title       = d.DisplayName;
            double percentcalc = Math.Round(85 + ProgressPercentage * 0.15, 2);

            if (percentcalc > 99.9)
            {
                percentcalc = 100;
            }

            lock (listlock)
            {
                videos[d.Index].SetPercent(percentcalc);
                globalPercentage = 0;
                for (int i = 0; i < videos.Count; i = i + 1)
                {
                    if (videos[i].PercentCompletion == -1)
                    {
                        globalPercentage += 100;
                    }
                    else
                    {
                        globalPercentage += videos[i].PercentCompletion;
                    }
                }
                globalPercentage /= (videos.Count * 100);
                globalPercentage *= 100;
            }
        }
Exemplo n.º 2
0
        void DownloadAudioFrom(Downloadable InVideo, int count)
        {
            InVideo.Preparing = true;
            ListDelegate ld = new ListDelegate(Program.frm.UpdateList);

            Program.frm.Invoke(ld);

            string link        = InVideo.Url;
            string countPrefix = count.ToString();

            countPrefix = countPrefix.PadLeft(padLeft, '0');

            VideoInfo video = DownloadUrlResolver.GetDownloadUrls(link);

            if (video.RequiresDecryption)
            {
                DownloadUrlResolver.DecryptDownloadUrl(video);
            }

            char[] legalTitleArray = video.Title.ToCharArray();
            string legalTitle      = "";

            foreach (char c in legalTitleArray)
            {
                if (!(c == '/' || c == '\\' || c == ':' || c == '*' || c == '?' || c == '"' || c == '<' || c == '>' || c == '|'))
                {
                    legalTitle += c;
                }
            }

            if (incremental)
            {
                var audioDownloader = new AudioDownloader(video, savePath + @"\" + countPrefix + " " + legalTitle + video.AudioExtension);
                audioDownloader.DownloadProgressChanged        += (sender, _args) => DownloadProgress(_args.ProgressPercentage, InVideo);
                audioDownloader.AudioExtractionProgressChanged += (sender, _args) => ExtractionProgress(_args.ProgressPercentage, InVideo);
                audioDownloader.Execute();
            }
            else
            {
                var audioDownloader = new AudioDownloader(video, savePath + @"\" + legalTitle + video.AudioExtension);
                audioDownloader.DownloadProgressChanged        += (sender, _args) => DownloadProgress(_args.ProgressPercentage, InVideo);
                audioDownloader.AudioExtractionProgressChanged += (sender, _args) => ExtractionProgress(_args.ProgressPercentage, InVideo);
                audioDownloader.Execute();
            }

            lock (threadLocker)
            {
                Program.frm.remaining--;
            }
        }
Exemplo n.º 3
0
        private void btnDownload_Click(object sender, EventArgs e)
        {
            if (isdisabled)
            {
                return;
            }
            if (pd.savePath == "")
            {
                ssInfoLabel.Text = "Please choose a download location";
                return;
            }

            List <Downloadable> downloading = new List <Downloadable>();

            for (int i = 0; i < lstVideos.CheckedItems.Count; i = i + 1)
            {
                Downloadable d = (Downloadable)lstVideos.CheckedItems[i];
                d.Index = i;
                downloading.Add(d);
            }

            if (downloading.Count > 0)
            {
                remaining = downloading.Count;

                lstVideos.Items.Clear();
                for (int i = 0; i < downloading.Count; i = i + 1)
                {
                    lstVideos.Items.Add(downloading[i]);
                    lstVideos.SetItemChecked(i, true);
                }

                pd.StartThreads(downloading);

                DisableControls();
                isdisabled = true;

                Thread updatethread = new Thread(UpdateListThread);
                updatethread.Start();
            }
            else
            {
                return;
            }
        }
Exemplo n.º 4
0
        public List <Downloadable> GetVideosByQuery(string searchQuery)
        {
            List <Downloadable> videos = new List <Downloadable>();

            var youtubeService = new YouTubeService(new BaseClientService.Initializer()
            {
                ApiKey          = apikey,
                ApplicationName = "VideoGrabber"
            });

            var nextPageToken = "";

            vidCount = 0;
            while (nextPageToken != null)
            {
                var searchRequest = youtubeService.Search.List("snippet");
                searchRequest.Q          = searchQuery;
                searchRequest.MaxResults = 50;

                try
                {
                    var searchResponse = searchRequest.Execute();
                    int indexcount     = 0;
                    foreach (var searchItem in searchResponse.Items)
                    {
                        if (searchItem.Snippet.Description == "This video is unavailable." && searchItem.Snippet.Title == "Deleted video")
                        {
                            continue;
                        }
                        if (searchItem.Id.VideoId != null)
                        {
                            Downloadable newVideo = new Downloadable(emptyPath + searchItem.Id.VideoId, searchItem.Snippet.Title, indexcount, searchItem.Id.VideoId);
                            videos.Add(newVideo);
                            indexcount++;
                            vidCount++;

                            if (vidCount >= maxVids)
                            {
                                break;
                            }
                        }
                    }

                    if (vidCount >= maxVids)
                    {
                        break;
                    }
                    nextPageToken = searchResponse.NextPageToken;
                }
                catch
                {
                    //something went wrong
                    return(null);
                }
            }

            if (videos.Count < 100)
            {
                padLeft = 2;
            }
            else if (videos.Count < 999)
            {
                padLeft = 3;
            }
            else
            {
                padLeft = 4;
            }

            return(videos);
        }
Exemplo n.º 5
0
        public List <Downloadable> GetVideosByPlaylist(string playlistID)
        {
            List <Downloadable> videos = new List <Downloadable>();

            var youtubeService = new YouTubeService(new BaseClientService.Initializer()
            {
                ApiKey          = apikey,
                ApplicationName = "VideoGrabber"
            });

            var nextPageToken = "";

            vidCount = 0;
            while (nextPageToken != null)
            {
                var playlistRequest = youtubeService.PlaylistItems.List("snippet,contentDetails");

                playlistRequest.PlaylistId = playlistID;
                playlistRequest.MaxResults = 50;
                playlistRequest.PageToken  = nextPageToken;

                try
                {
                    var playlistResponse = playlistRequest.Execute();
                    int indexcount       = 0;
                    foreach (var playlistItem in playlistResponse.Items)
                    {
                        if (playlistItem.Snippet.Description == "This video is unavailable." && playlistItem.Snippet.Title == "Deleted video")
                        {
                            continue;
                        }

                        Downloadable newVideo = new Downloadable(emptyPath + playlistItem.ContentDetails.VideoId, playlistItem.Snippet.Title, indexcount, playlistItem.ContentDetails.VideoId);
                        videos.Add(newVideo);
                        indexcount++;
                        vidCount++;

                        if (vidCount >= maxVids)
                        {
                            break;
                        }
                    }

                    if (vidCount >= maxVids)
                    {
                        break;
                    }
                    nextPageToken = playlistResponse.NextPageToken;
                }
                catch
                {
                    //a wrong playlist id got entered
                    return(null);
                }
            }

            if (videos.Count < 100)
            {
                padLeft = 2;
            }
            else if (videos.Count < 999)
            {
                padLeft = 3;
            }
            else
            {
                padLeft = 4;
            }

            return(videos);
        }
        void ExtractionProgress(double ProgressPercentage, Downloadable d)
        {
            d.Preparing = false;
            string title = d.DisplayName;
            double percentcalc = Math.Round(85 + ProgressPercentage * 0.15, 2);
            if (percentcalc > 99.9) percentcalc = 100;

            lock (listlock)
            {
                videos[d.Index].SetPercent(percentcalc);
                globalPercentage = 0;
                for (int i = 0; i < videos.Count; i = i + 1)
                {
                    if (videos[i].PercentCompletion == -1)
                    {
                        globalPercentage += 100;
                    }
                    else
                    {
                        globalPercentage += videos[i].PercentCompletion;
                    }
                }
                globalPercentage /= (videos.Count * 100);
                globalPercentage *= 100;
            }
        }
        void DownloadAudioFrom(Downloadable InVideo, int count)
        {
            InVideo.Preparing = true;
            ListDelegate ld = new ListDelegate(Program.frm.UpdateList);
            Program.frm.Invoke(ld);

            string link = InVideo.Url;
            string countPrefix = count.ToString();
            countPrefix = countPrefix.PadLeft(padLeft, '0');

            VideoInfo video = DownloadUrlResolver.GetDownloadUrls(link);

            if (video.RequiresDecryption)
            {
                DownloadUrlResolver.DecryptDownloadUrl(video);
            }

            char[] legalTitleArray = video.Title.ToCharArray();
            string legalTitle = "";

            foreach (char c in legalTitleArray)
            {
                if (!(c == '/' || c == '\\' || c == ':' || c == '*' || c == '?' || c == '"' || c == '<' || c == '>' || c == '|'))
                {
                    legalTitle += c;
                }
            }

            if (incremental)
            {
                var audioDownloader = new AudioDownloader(video, savePath + @"\" + countPrefix + " " + legalTitle + video.AudioExtension);
                audioDownloader.DownloadProgressChanged += (sender, _args) => DownloadProgress(_args.ProgressPercentage, InVideo);
                audioDownloader.AudioExtractionProgressChanged += (sender, _args) => ExtractionProgress(_args.ProgressPercentage, InVideo);
                audioDownloader.Execute();
            }
            else
            {
                var audioDownloader = new AudioDownloader(video, savePath + @"\" + legalTitle + video.AudioExtension);
                audioDownloader.DownloadProgressChanged += (sender, _args) => DownloadProgress(_args.ProgressPercentage, InVideo);
                audioDownloader.AudioExtractionProgressChanged += (sender, _args) => ExtractionProgress(_args.ProgressPercentage, InVideo);
                audioDownloader.Execute();
            }

            lock (threadLocker)
            {
                Program.frm.remaining--;
            }
        }
        public List<Downloadable> GetVideosByQuery(string searchQuery)
        {
            List<Downloadable> videos = new List<Downloadable>();

            var youtubeService = new YouTubeService(new BaseClientService.Initializer()
            {
                ApiKey = apikey,
                ApplicationName = "VideoGrabber"
            });

            var nextPageToken = "";
            vidCount = 0;
            while (nextPageToken != null)
            {
                var searchRequest = youtubeService.Search.List("snippet");
                searchRequest.Q = searchQuery;
                searchRequest.MaxResults = 50;

                try
                {
                    var searchResponse = searchRequest.Execute();
                    int indexcount = 0;
                    foreach (var searchItem in searchResponse.Items)
                    {
                        if (searchItem.Snippet.Description == "This video is unavailable." && searchItem.Snippet.Title == "Deleted video")
                        {
                            continue;
                        }
                        if (searchItem.Id.VideoId != null)
                        {
                            Downloadable newVideo = new Downloadable(emptyPath + searchItem.Id.VideoId, searchItem.Snippet.Title, indexcount, searchItem.Id.VideoId);
                            videos.Add(newVideo);
                            indexcount++;
                            vidCount++;

                            if (vidCount >= maxVids) break;
                        }
                    }

                    if (vidCount >= maxVids) break;
                    nextPageToken = searchResponse.NextPageToken;
                }
                catch
                {
                    //something went wrong
                    return null;
                }
            }

            if (videos.Count < 100)
            {
                padLeft = 2;
            }
            else if (videos.Count < 999)
            {
                padLeft = 3;
            }
            else
            {
                padLeft = 4;
            }

            return videos;
        }
        public List<Downloadable> GetVideosByPlaylist(string playlistID)
        {
            List<Downloadable> videos = new List<Downloadable>();

            var youtubeService = new YouTubeService(new BaseClientService.Initializer()
            {
                ApiKey = apikey,
                ApplicationName = "VideoGrabber"
            });

            var nextPageToken = "";
            vidCount = 0;
            while (nextPageToken != null)
            {
                var playlistRequest = youtubeService.PlaylistItems.List("snippet,contentDetails");

                playlistRequest.PlaylistId = playlistID;
                playlistRequest.MaxResults = 50;
                playlistRequest.PageToken = nextPageToken;

                try
                {
                    var playlistResponse = playlistRequest.Execute();
                    int indexcount = 0;
                    foreach (var playlistItem in playlistResponse.Items)
                    {
                        if (playlistItem.Snippet.Description == "This video is unavailable." && playlistItem.Snippet.Title == "Deleted video")
                        {
                            continue;
                        }

                        Downloadable newVideo = new Downloadable(emptyPath + playlistItem.ContentDetails.VideoId, playlistItem.Snippet.Title, indexcount, playlistItem.ContentDetails.VideoId);
                        videos.Add(newVideo);
                        indexcount++;
                        vidCount++;

                        if (vidCount >= maxVids) break;
                    }

                    if (vidCount >= maxVids) break;
                    nextPageToken = playlistResponse.NextPageToken;
                }
                catch
                {
                    //a wrong playlist id got entered
                    return null;
                }
            }

            if (videos.Count < 100)
            {
                padLeft = 2;
            }
            else if (videos.Count < 999)
            {
                padLeft = 3;
            }
            else
            {
                padLeft = 4;
            }

            return videos;
        }