コード例 #1
0
        private async Task <bool> DownloadTrailerAsync(Movie movie)
        {
            try
            {
                YoutubeClient  youtube        = new YoutubeClient();
                StreamManifest streamManifest = await youtube.Videos.Streams.GetManifestAsync(movie.TrailerURL);

                // Get highest quality muxed stream
                IVideoStreamInfo streamInfo = streamManifest.GetMuxed().WithHighestVideoQuality();

                if (streamInfo != null)
                {
                    // Download the stream to file
                    await youtube.Videos.Streams.DownloadAsync(streamInfo, Path.Combine(movie.FilePath, $"{movie.Title}-trailer.{streamInfo.Container}"));

                    return(true);
                }

                return(false);
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error downloading trailer for {movie.Title}\n{ex.Message}");
                await _hubContext.Clients.All.SendAsync("downloadAllTrailers", movie);

                return(false);
            }
        }
コード例 #2
0
        private async Task DownloadMuxedFromStreamsAsync(IVideoStreamInfo videoStreamInfo, IAudioStreamInfo audioStreamInfo, string file)
        {
            var videoStream = await client.Videos.Streams.GetAsync(videoStreamInfo);

            var audioStream = await client.Videos.Streams.GetAsync(audioStreamInfo);

            var videoPipeName = "ffvideopipe";
            var audioPipeName = "ffaudiopipe";
            var args          = $@"-y -i \\.\pipe\{videoPipeName} -i \\.\pipe\{audioPipeName} -c copy -map 0:v:0 -map 1:a:0 {file}.{videoStreamInfo.Container.Name}";

            var videoPipe = new NamedPipeServerStream(videoPipeName, PipeDirection.Out, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 10000, 10000);
            var audioPipe = new NamedPipeServerStream(audioPipeName, PipeDirection.Out, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 10000, 10000);

            var process = new Process
            {
                StartInfo =
                {
                    FileName              = "ffmpeg",
                    Arguments             = args,
                    UseShellExecute       = false,
                    CreateNoWindow        = true,
                    RedirectStandardInput = true
                }
            };

            process.Start();

            videoPipe.WaitForConnection();
            var videoCopy = videoStream.CopyToAsync(videoPipe);

            audioPipe.WaitForConnection();
            var audioCopy = audioStream.CopyToAsync(audioPipe);

            Task.WaitAll(videoCopy, audioCopy);
            videoPipe.Flush();
            audioPipe.Flush();
            videoPipe.Dispose();
            audioPipe.Dispose();

            process.WaitForExit();
        }
コード例 #3
0
        private async Task <List <FileDownloadingInfo> > InitDownloadingAsync(IList <Video> videos, string directory, DownloadQuality quality, string audioExtForced)
        {
            List <FileDownloadingInfo> result = new List <FileDownloadingInfo>();

            //_client.DownloadClosedCaptionTrackAsync();

            //ThreadPool.SetMaxThreads(Environment.ProcessorCount, Environment.ProcessorCount);

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            foreach (var vid in videos)
            {
                try
                {
                    StreamManifest infoSet = await _client.Videos.Streams.GetManifestAsync(vid.Id);

                    string vidTitle = RemoveProhibitedChars(vid.Title);

                    switch (quality)
                    {
                    case DownloadQuality.Default:
                    case DownloadQuality.MuxedBest:

                        IEnumerable <MuxedStreamInfo> muxedStreams = infoSet.GetMuxedStreams();
                        IVideoStreamInfo muxedHighestQuality       = muxedStreams.GetWithHighestVideoQuality();
                        string           ext = muxedHighestQuality.Container.Name;
                        //string ext = "mkv";
                        string path = directory + "/" + vidTitle + "." + ext;

                        var file = new FileDownloadingInfo()
                        {
                            Name = vidTitle, StreamInfo = muxedHighestQuality
                        };
                        InitStreamDownloading(file, path, vid);
                        result.Add(file);
                        break;

                    case DownloadQuality.SeparateBest:

                        IEnumerable <IVideoStreamInfo> videoStreams = infoSet.GetVideoStreams();
                        IEnumerable <IAudioStreamInfo> audioStreams = infoSet.GetAudioStreams();
                        IStreamInfo highestBitRate      = audioStreams.GetWithHighestBitrate();
                        IStreamInfo videoHighestQuality = videoStreams.GetWithHighestVideoQuality();

                        string extVideo = videoHighestQuality.Container.Name;

                        string pathVideo = directory + "/" + vidTitle + "." + extVideo;

                        string extAudio  = highestBitRate.Container.Name;
                        string pathAudio = directory + "/" + vidTitle + "." + extAudio;

                        if (audioExtForced == String.Empty)
                        {
                            if (pathAudio.Equals(pathVideo))
                            {
                                pathAudio += ".audio." + extAudio;
                            }
                        }
                        else
                        {
                            pathAudio += "." + audioExtForced;
                        }

                        FileDownloadingInfo audio = new FileDownloadingInfo()
                        {
                            Name = vidTitle + "(audio)", StreamInfo = highestBitRate
                        };
                        FileDownloadingInfo video = new FileDownloadingInfo()
                        {
                            Name       = vidTitle,
                            StreamInfo = videoHighestQuality
                        };

                        if (File.Exists(pathAudio))
                        {
                            _logger.Log("File " + pathAudio + "already exists!. Consider removing or renaming.");
                        }
                        else
                        {
                            InitStreamDownloading(audio, pathAudio, vid);
                            result.Add(audio);
                        }

                        if (File.Exists(pathVideo))
                        {
                            _logger.Log("File " + pathVideo + "already exists!. Consider removing or renaming.");
                        }
                        else
                        {
                            InitStreamDownloading(video, pathVideo, vid);
                            result.Add(video);
                        }

                        break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(quality), quality, null);
                    }
                }
                catch (Exception ex)
                {
                    _logger.Log(ex.InnerException?.Message);
                }
            }

            return(result);
        }
コード例 #4
0
        async Task Video_Download(string Link, string Link_ID_Only, string OutDir, TextBlock Message_T)
        {
            //動画と音声を別々にダウンロード
            //動画の場合はダウンロード後ffmpegで合わせる
            var video = await youtube.Videos.GetAsync(Link);

            var title          = Sub_Code.File_Replace_Name(video.Title);
            var streamManifest = await youtube.Videos.Streams.GetManifestAsync(Link_ID_Only);

            var streamInfo = streamManifest.GetAudioOnlyStreams().GetWithHighestBitrate();

            if (streamInfo != null)
            {
                Message_T.Text = "音声を取得しています...";
                await Task.Delay(50);

                var stream = await youtube.Videos.Streams.GetAsync(streamInfo);

                await youtube.Videos.Streams.DownloadAsync(streamInfo, OutDir + "Temp.webm");

                Sub_Code.Audio_Encode_To_Other(OutDir + "Temp.webm", OutDir + "Temp.mp3", "mp3", true);
            }
            if (Type_L.SelectedIndex == 1)
            {
                Message_T.Text = "動画を取得しています...";
                await Task.Delay(50);

                IVideoStreamInfo streamInfo2 = streamManifest.GetVideoOnlyStreams().Where(s => s.Container == Container.Mp4).GetWithHighestVideoQuality();
                if (streamInfo2 != null)
                {
                    await youtube.Videos.Streams.DownloadAsync(streamInfo2, OutDir + "Temp.mp4");

                    Message_T.Text = "動画と音声を結合しています...";
                    await Task.Delay(50);

                    Sub_Code.Audio_Video_Convert(OutDir + "Temp.mp4", OutDir + "Temp.mp3", OutDir + title + ".mp4");
                    if (List_Add_C.IsChecked.Value)
                    {
                        Sub_Code.AutoListAdd.Add(OutDir + title + ".mp4");
                    }
                }
                else
                {
                    Message_Feed_Out("動画を取得できなかったため音声のみ保存しました。");
                    Sub_Code.File_Move(OutDir + "Temp.mp3", OutDir + title + ".mp3", true);
                    if (List_Add_C.IsChecked.Value)
                    {
                        Sub_Code.AutoListAdd.Add(OutDir + title + ".mp3");
                    }
                }
            }
            else
            {
                Sub_Code.File_Move(OutDir + "Temp.mp3", OutDir + title + ".mp3", true);
                if (List_Add_C.IsChecked.Value)
                {
                    Sub_Code.AutoListAdd.Add(OutDir + title + ".mp3");
                }
            }
            File.Delete(OutDir + "Temp.mp3");
            File.Delete(OutDir + "Temp.mp4");
        }
コード例 #5
0
 public VideoDownloadInfo(IVideoStreamInfo video, IAudioStreamInfo audio)
 {
     Video = video;
     Audio = audio;
 }
コード例 #6
0
ファイル: AbstractCam.cs プロジェクト: x-company/CamManager
 public virtual void SetSubVideoStreamInfo(StreamType streamType, IVideoStreamInfo streamInfo)
 {
 }
コード例 #7
0
        private void LoadValues(IVideoStreamInfo info)
        {
            if(info == null)
                return;

            // Resolution
            cmbResolution.Active = ((int)info.Resolution) - 1;
            if(info.Resolution == Resolution.HD_720)
                cmbResolution.Active = 0;
            else if(info.Resolution == Resolution.VGA_640_480)
                cmbResolution.Active = 1;
            else if(info.Resolution == Resolution.VGA_640_360)
                cmbResolution.Active = 2;
            else if(info.Resolution == Resolution.QVGA_320_240)
                cmbResolution.Active = 3;
            else if(info.Resolution == Resolution.QVGA_320_180)
                cmbResolution.Active = 4;

            // Bitrate
            var kvp = _bitrates.FirstOrDefault(x => x.Value == info.BitRate);
            cmbBitrate.Active = IsMainStream() ? _mainBitrates.ToList().IndexOf(kvp.Key) : _subBitrates.ToList().IndexOf(kvp.Key);

            // Framerate
            cmbFramerate.Active = info.FrameRate - 1;

            // GOP
            cmbGroupOfPics.Active = info.GOP - 10;

            // VBR
            cmbVariableBitrate.Active = info.IsVBR ? 0 : 1;
        }