コード例 #1
0
ファイル: Tests.cs プロジェクト: Neos-Metaverse/NYouTubeDL
        public void TestIsVideoDownload()
        {
            YoutubeDL ydlClient = new YoutubeDL();

            ydlClient.GetDownloadInfo(@"https://www.youtube.com/watch?v=dQw4w9WgXcQ");

            VideoDownloadInfo info = ydlClient.Info as VideoDownloadInfo;

            Assert.NotEqual(info, null);
        }
コード例 #2
0
ファイル: DownloadTable.cs プロジェクト: wxlg1117/Yodel
        private void VideoDownloadChanged(object sender, PropertyChangedEventArgs e)
        {
            lock (this.tableLock)
            {
                VideoDownloadInfo videoInfo = (VideoDownloadInfo)sender;

                if (!string.IsNullOrEmpty(videoInfo.Id) && !string.IsNullOrEmpty(videoInfo.Title))
                {
                    this.videoRows[videoInfo.Id] =
                        $"<tr><td><img src=\"{videoInfo.Thumbnail ?? videoInfo.Thumbnails?.FirstOrDefault()?.Url}\" width=\"100\"></td><td>{videoInfo.Title.Trim()}</td><td>{videoInfo.VideoSize}</td><td><div class=\"progress\"><div class=\"determinate\" style=\"width: {videoInfo.VideoProgress}%\"></div</td><td>{videoInfo.Eta}</td><td>{videoInfo.DownloadRate}</td></tr>";
                }
            }

            this.TableUpdateEvent?.Invoke(this.Table, EventArgs.Empty);
        }
コード例 #3
0
        public async Task <VideoDownloadInfo> GetContentUriAsync(string contentId, string contentTitle, IList <MimeTypeEnum> mimeTypes, IList <FileTypeEnum> fileTypes)
        {
            // Check for unknown mime and file types.
            if ((mimeTypes?.Count ?? 0) < 1 || mimeTypes.Contains(MimeTypeEnum.Unknown))
            {
                mimeTypes.Clear();
                mimeTypes.Add(MimeTypeEnum.Audio);
                mimeTypes.Add(MimeTypeEnum.MuxedAudioVideo);
            }

            if ((fileTypes?.Count ?? 0) < 1 || fileTypes.Contains(FileTypeEnum.Unknown))
            {
                fileTypes.Clear();
                fileTypes.Add(FileTypeEnum.M4a);
                fileTypes.Add(FileTypeEnum.Mp4);
                fileTypes.Add(FileTypeEnum.Webm);
            }

            // Decode and parse.
            string dom = await _decoder.GetVideoInfoDomAsync(contentId);

            VideoDownloadInfo info = _decoder.GetVideoDownloadInfo(contentId, contentTitle, dom);

            // Validate by assigning a rank to the 'mimeTypes' and 'fileTypes' that were passed in.
            // When 'IVideoInfoDomDecoder.GetVideoDownloadInfo.Videos.Count' does not equal or exceed the generated rank, the urls are thrown away.
            if (info.Availability == VideoAvailabilityEnum.Available && (info.Videos?.Count ?? 0) > 0)
            {
                int rank = ItagRank.GenerateRank(mimeTypes, fileTypes);
                if (info.Videos.Count < rank)
                {
                    info = new VideoDownloadInfo(
                        VideoAvailabilityEnum.NotAvailable,
                        contentId,
                        contentTitle,
                        "Desired file types were not found.",
                        null);
                }
            }

            return(info);
        }
コード例 #4
0
        private async System.Threading.Tasks.Task UploadSingleFile(VideoDownloadInfo file)
        {
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(file.VideoUrl);

            req.Method = "HEAD";
            HttpWebResponse resp = (HttpWebResponse)(req.GetResponse());

            totalBytes = resp.ContentLength;

            uploadedBytes   = 0;
            percentComplete = 0;

            Decimal fileSizeInMB  = Convert.ToDecimal(totalBytes) / (1024.0m * 1024.0m);
            var     totalfileSize = Math.Round(fileSizeInMB, 2);

            notificationManager = (NotificationManager)GetSystemService(NotificationService);
            notificationBuilder = new Notification.Builder(ApplicationContext);
            notificationBuilder.SetOngoing(true)
            .SetSmallIcon(Resource.Drawable.ic_file_download_white_18dp)
            .SetContentTitle("Downloading")
            .SetContentText(

                Math.Round((Convert.ToDecimal(uploadedBytes) / (1024.0m * 1024.0m)), 2) + " MB of " + totalfileSize + " MB")
            .SetProgress(100, percentComplete, false);

            notification   = notificationBuilder.Build();
            notificationID = new System.Random().Next(10000, 99999);
            notificationManager.Notify(notificationID, notification);

            timer          = new System.Timers.Timer();
            timer.Elapsed += Timer_Elapsed;
            timer.Interval = 1000;
            timer.Enabled  = true;
            timer.Start();

            wClient = new WebClient();
            wClient.DownloadFileCompleted   += new AsyncCompletedEventHandler(Completed);
            wClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);

            await wClient.DownloadFileTaskAsync(new Uri(file.VideoUrl), GetOutputVideoPath(file.VideoFileName));           // Defines the URL and destination directory for the downloaded file
        }
コード例 #5
0
        /// <summary>
        /// Downloads the best adaptive video from Youtube
        /// </summary>
        /// <param name="videoId">The video id</param>
        /// <returns></returns>
        public async Task DownloadHighestVideo(string videoId)
        {
            videoId = videoId.NormalizeYoutubeVideoId();

            var video = await client.GetVideoAsync(videoId);

            var videoStreamInfos = await client.GetVideoMediaStreamInfosAsync(videoId);

            // get adaptive videostream with best videoquality
            var videoStreamInfo = videoStreamInfos.Video
                                  .OrderBy(x => x.VideoQuality)
                                  .ThenBy(x => x.Bitrate)
                                  .LastOrDefault();

            AudioStreamInfo audioStreamInfo = null;

            // get adaptive audiostream with highest bitrate
            if (videoStreamInfo.Container == Container.WebM)
            {
                audioStreamInfo = videoStreamInfos.Audio
                                  .Where(x => x.AudioEncoding == AudioEncoding.Vorbis || x.AudioEncoding == AudioEncoding.Opus)
                                  .OrderBy(x => x.Bitrate)
                                  .LastOrDefault();
            }
            else
            {
                audioStreamInfo = videoStreamInfos.Audio
                                  .Where(x => x.AudioEncoding == AudioEncoding.Aac)
                                  .OrderBy(x => x.Bitrate)
                                  .LastOrDefault();
            }

            // temporary filenames for downloading adaptive files
            var tmpAudioFileName = Path.Combine(DownloadPath, $"{video.Title}__audio".GetValidFileName());
            var tmpVideoFileName = Path.Combine(DownloadPath, $"{video.Title}__video".GetValidFileName());

            // get the final filename
            var fileExtension = videoStreamInfo.Container.GetFileExtension();
            var fileName      = Path.Combine(DownloadPath, $"{video.Title}.{fileExtension}".GetValidFileName());

            VideoDownloadInfo?.Invoke(this, new VideoDownloadInfoArgs(video.Title, fileName, audioStreamInfo.Size, videoStreamInfo.Size));

            // download progress calculation
            double audioDownloadProgress = 0;
            double videoDownloadProgress = 0;

            var totalFileSize = audioStreamInfo.Size + videoStreamInfo.Size;
            var audioWeight   = (double)Math.Round((100m / totalFileSize) * audioStreamInfo.Size, 2);
            var videoWeight   = (double)Math.Round((100m / totalFileSize) * videoStreamInfo.Size, 2);

            var audioProgress = new Progress <double>(x =>
            {
                audioDownloadProgress = (audioWeight * x);
                Progress?.Report(audioDownloadProgress + videoDownloadProgress);
            });

            var videoProgress = new Progress <double>(x =>
            {
                videoDownloadProgress = (videoWeight * x);
                Progress?.Report(audioDownloadProgress + videoDownloadProgress);
            });

            //var audioProgress = new Progress<DownloadProgress>(x =>
            //{
            //    audioDownloadProgress = (audioWeight * x.Percentage);
            //    Debug.WriteLine("SPEED: " + x.Speed);
            //    Progress?.Report(audioDownloadProgress + videoDownloadProgress);
            //});

            //var videoProgress = new Progress<DownloadProgress>(x =>
            //{
            //    videoDownloadProgress = (videoWeight * x.Percentage);
            //    Debug.WriteLine("SPEED: " + x.Speed);
            //    Progress?.Report(audioDownloadProgress + videoDownloadProgress);
            //});

            try
            {
                //var downloader = new MediaStreamDownloader();
                //await downloader.DownloadMediaStream(client, audioStreamInfo, tmpAudioFileName, audioProgress, CancellationToken);
                //await downloader.DownloadMediaStream(client, videoStreamInfo, tmpVideoFileName, videoProgress, CancellationToken);

                // downloading adaptive streams
                await client.DownloadMediaStreamAsync(audioStreamInfo, tmpAudioFileName, audioProgress, CancellationToken);

                await client.DownloadMediaStreamAsync(videoStreamInfo, tmpVideoFileName, videoProgress, CancellationToken);

                // muxing videofile with audiofile
                MuxingStarted?.Invoke(this, EventArgs.Empty);
                using (var muxer = new Muxer(OverwriteFiles, FFmpegPath))
                {
                    // TODO: Log
                    muxer.DataReceived += (s, e) => { Debug.WriteLine(e.Data?.ToString()); };
                    muxer.Mux(tmpVideoFileName, tmpAudioFileName, fileName, LogLevel.error);
                }
                MuxingFinished?.Invoke(this, EventArgs.Empty);
            }
            finally
            {
                if (File.Exists(tmpAudioFileName))
                {
                    File.Delete(tmpAudioFileName);
                }
                if (File.Exists(tmpVideoFileName))
                {
                    File.Delete(tmpVideoFileName);
                }
            }
        }