private void load(TaskProgressReporter reporter)
        {
            MediaService.GetVideoFilePath(this.VideoModel.Url, out string path, reporter);
            this.VideoFilePath = path;

            Task.Run(() => { MediaService.GetAudioFilePath(this.VideoModel.Url, out _); });
        }
Ejemplo n.º 2
0
        public static bool GetVideoFilePath(string youtubeUrl, out string path, TaskProgressReporter reporter)
        {
            ensureExistingDirectory(VideoFolder);

            path = downloadedVideoPath(youtubeUrl);

            if (inDownloadingProgress.ContainsKey(youtubeUrl))
            {
                while (path == null)
                {
                    Thread.Sleep(200);
                    path = downloadedVideoPath(youtubeUrl);
                }

                while (inDownloadingProgress.ContainsKey(youtubeUrl))
                {
                    inDownloadingProgress.TryRemove(youtubeUrl, out _);
                }
            }

            if (path != null)
            {
                return(path.Contains(SuccessSuffix));
            }

            getVideoFilePath(youtubeUrl, out path, out string failurePath);

            bool downloaded = YoutubeService.DownloadVideoViaYoutubeExplode(youtubeUrl, path, failurePath, reporter);

            if (!downloaded)
            {
                path = failurePath;
            }

            while (inDownloadingProgress.ContainsKey(youtubeUrl))
            {
                inDownloadingProgress.TryRemove(youtubeUrl, out _);
            }

            return(downloaded);
        }
Ejemplo n.º 3
0
        public static bool DownloadVideoViaYoutubeExplode(string url, string successPath, string failurePath, TaskProgressReporter reporter)
        {
            try
            {
                reporter?.ReportInDeterminate("getting links");

                string             id            = YoutubeClient.ParseVideoId(url);
                YoutubeClient      client        = new YoutubeClient();
                MediaStreamInfoSet streamInfoSet = client.GetVideoMediaStreamInfosAsync(id).Result;

                MuxedStreamInfo streamInfo = streamInfoSet.Muxed.First(m => m.Container.GetFileExtension().ToLower() == "mp4");
                //string ext = streamInfo.Container.GetFileExtension();
                client.DownloadMediaStreamAsync(streamInfo, successPath, reporter == null
                    ? null
                    : new Progress <double>(d => reporter.ReportDeterminate((int)(d * 100), "downloading"))).Wait();
                return(true);
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception);
                File.Create(failurePath).Close();
                return(false);
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Copy constructor.
 /// </summary>
 /// <param name="o">The source object for the copy.</param>
 protected TaskGroup(TaskGroup o)
 {
     _Key      = o.Key;
     _Progress = o._Progress;
 }