/// <summary>
        /// Creates an instance of <see cref="YoutubeConverter"/>.
        /// </summary>
        public YoutubeConverter(IYoutubeClient youtubeClient, string ffmpegFilePath)
        {
            _youtubeClient = youtubeClient.GuardNotNull(nameof(youtubeClient));

            ffmpegFilePath.GuardNotNull(nameof(ffmpegFilePath));
            _ffmpeg = new FfmpegCli(ffmpegFilePath);
        }
示例#2
0
        private static void DownloadAllCaptions(IYoutubeClient client, Video video, string downloadFolder, string videoFileNameBase, IProgress <double> progress)
        {
            var closedCaptionTrackInfos = client.GetVideoClosedCaptionTrackInfosAsync(video.Id).Result;

            DownloadCaptionsForLanguage(client, closedCaptionTrackInfos, "en", downloadFolder, videoFileNameBase, progress);
            DownloadCaptionsForLanguage(client, closedCaptionTrackInfos, "ko", downloadFolder, videoFileNameBase, progress);
        }
示例#3
0
        public HomeViewModel(IYoutubeClient youtubeClient, IMainViewModel parentMainViewModel)
        {
            _youtubeClient       = youtubeClient;
            _parentMainViewModel = parentMainViewModel;

            SearchAndReloadVideoList("Google");
        }
示例#4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="client">YoutubeClient instance</param>
        /// <param name="ffmpegExePath">//Path to the ffmpeg.exe file used to mux audio&video stream. It should be located in wwwrooot/ffmpeg.exe</param>
        public YoutubeClientHelper(IYoutubeClient client, string ffmpegExePath)
        {
            this.client = client;


            converter = new YoutubeConverter(client, ffmpegExePath);
        }
 public void RegisterClient(IYoutubeClient client)
 {
     if (!RegisteredClients.Any(c => c.Id == client.Id))
     {
         LOGGER.Info($"Adding youtube client credentials with name '{client.Name}'");
         Clients.Add(client);
     }
 }
示例#6
0
        public YoutubeClientHelper(IYoutubeClient client, string installLocation)
        {
            this.client = client;

            string ffmpegExePath = installLocation + "\\ffmpeg.exe"; //Path to the ffmpeg.exe file used to mux audio&video stream.

            converter = new YoutubeConverter(client, ffmpegExePath);
        }
示例#7
0
        public Uri CreateAuthUri(IYoutubeClient client, YoutubeRedirectUri redirectUri, GoogleScope scope)
        {
            string scopeString       = JoinScopes(scope);
            string redirectUriString = redirectUri.GetAttribute <EnumMemberAttribute>().Value;
            string authRequestString = $"https://accounts.google.com/o/oauth2/auth?client_id={client.Id}&redirect_uri={redirectUriString}&scope={scopeString}&response_type=code&approval_prompt=force&access_type=offline";

            return(new Uri(authRequestString));
        }
 public void UnregisterClient(IYoutubeClient client)
 {
     if (Clients.Contains(client))
     {
         LOGGER.Info($"Removing youtube client credential with name '{client.Name}'");
         Clients.Remove(client);
     }
 }
示例#9
0
        public PlaylistServiceForm(IPlaylistServiceConnectionContainer container, IYoutubeClient client)
        {
            LOGGER.Info($"Initializing new instance of PlaylistServiceForm");

            Client    = client;
            Container = container;

            InitializeComponent();
        }
示例#10
0
        /// <summary>
        /// Creates an instance of <see cref="YoutubeConverter"/>.
        /// </summary>
        public YoutubeConverter(IYoutubeClient youtubeClient, string ffmpegFilePath)
        {
            _youtubeClient = youtubeClient;
            _ffmpeg        = new FfmpegCli(ffmpegFilePath);

            // Ensure running on desktop OS
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) &&
                !RuntimeInformation.IsOSPlatform(OSPlatform.Linux) &&
                !RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                throw new PlatformNotSupportedException("YoutubeExplode.Converter works only on desktop operating systems.");
            }
        }
示例#11
0
 public YoutubeScrapProvider(
     IYoutubeClient youtube,
     ILogger <YoutubeScrapProvider> logger,
     string tempFolder,
     string outputFolder,
     string converterFilePath)
 {
     this.youtube      = youtube;
     this.logger       = logger;
     this.tempFolder   = tempFolder;
     this.outputFolder = outputFolder;
     this.converterCli = new Cli(converterFilePath);
 }
示例#12
0
 private static void DownloadCaptionsForLanguage(IYoutubeClient client, IReadOnlyList <ClosedCaptionTrackInfo> closedCaptionTrackInfos, string languageCode, string downloadFolder, string videoFileNameBase, IProgress <double> progress)
 {
     closedCaptionTrackInfos
     .SingleOrDefault(info => !info.IsAutoGenerated && info.Language.Code == languageCode)
     .Do(closedCaptionTrackInfo =>
     {
         Console.WriteLine();
         Console.WriteLine($"  0.00% \t{closedCaptionTrackInfo.Language} captions");
         Console.SetCursorPosition(0, Console.CursorTop - 1);
         client.DownloadClosedCaptionTrackAsync(closedCaptionTrackInfo,
                                                Path.Combine(downloadFolder, $"{videoFileNameBase}.{languageCode}.srt"),
                                                progress)
         .Wait();
     });
 }
示例#13
0
        public IYoutubeAccount ConnectToAccount(string code, bool mailsAllowed, IYoutubeClient client, YoutubeRedirectUri redirectUri)
        {
            LOGGER.Info($"Connecting to account, mails allowed: {mailsAllowed}, redirect uri: {redirectUri}");

            var    uri     = redirectUri.GetAttribute <EnumMemberAttribute>().Value;
            string content = $"code={code}&client_id={client.Id}&client_secret={client.Secret}&redirect_uri={uri}&grant_type=authorization_code";
            var    bytes   = Encoding.UTF8.GetBytes(content);

            // Request erstellen
            WebRequest request = WebRequest.Create("https://www.googleapis.com/oauth2/v4/token");

            request.Method      = "POST";
            request.ContentType = "application/x-www-form-urlencoded";

            string result = WebService.Communicate(request, bytes);

            QuotaProblemHandler.ThrowOnQuotaLimitReached(result);

            IYoutubeAccount account      = null;
            var             authResponse = JsonConvert.DeserializeObject <YoutubeAuthResponse>(result);

            IYoutubeAccountAccess access = new YoutubeAccountAccess();

            access.Client = client;
            access.HasSendMailPrivilegue = mailsAllowed;

            if (authResponse != null && !string.IsNullOrWhiteSpace(authResponse.access_token))
            {
                access.AccessToken    = authResponse.access_token;
                access.RefreshToken   = authResponse.refresh_token;
                access.TokenType      = authResponse.token_type;
                access.ExpirationDate = DateTime.Now.AddSeconds(authResponse.expires_in);
                access.ClientId       = client.Id;

                LOGGER.Info($"Connection successful, loading account details");

                var accountDetails = GetAccountDetails(access);
                var acc            = accountDetails.items.First();
                account = YoutubeAccount.Create(acc.id, acc.snippet.country, acc.snippet.title);

                account.Access.Add(access);
            }

            LOGGER.Info($"Connected to account with id: {account.Id} and title: '{account.Title}'");

            return(account);
        }
示例#14
0
        private static void DownloadVideo(IYoutubeClient client, Video video, string downloadFolder, string videoFileNameBase, IProgress <double> progress)
        {
            var converter = new YoutubeConverter(client, Ffmpeg.DefaultFilePath);

            var mediaStreamInfoSet = client.GetVideoMediaStreamInfosAsync(video.Id).Result;
            var videoStreamInfo    = mediaStreamInfoSet.Video.OrderByDescending(info => info.VideoQuality).ThenByDescending(info => info.Framerate).First();
            var audioStreamInfo    = mediaStreamInfoSet.Audio.OrderByDescending(info => info.Bitrate).First();

            var extension = videoStreamInfo.Container.GetFileExtension();

            converter.DownloadAndProcessMediaStreamsAsync(
                new MediaStreamInfo[] { videoStreamInfo, audioStreamInfo },
                Path.Combine(downloadFolder, videoFileNameBase + $".{extension}"),
                extension,
                progress)
            .Wait();
        }
 public YoutubeService(IYoutubeClient youtubeClient)
 {
     _youtubeClient = youtubeClient;
 }
 /// <summary>
 /// Creates an instance of <see cref="YoutubeConverter"/>.
 /// </summary>
 public YoutubeConverter(IYoutubeClient youtubeClient, string ffmpegFilePath)
 {
     _youtubeClient = youtubeClient;
     _ffmpeg        = new FfmpegCli(ffmpegFilePath);
 }
 public YouTubeExplodeScrapper(IYoutubeClient youtubeClient)
 {
     _youtubeClient = youtubeClient;
 }
 public void RemoveClient(IYoutubeClient client)
 {
     YoutubeClientService.RemoveClient(client);
 }
示例#19
0
 public YoutubeService(IYoutubeClient youtubeClient, IConfiguration configuration)
 {
     this.youtubeClient = youtubeClient;
     this.configuration = configuration;
 }
 /// <summary>
 /// Creates an instance of <see cref="YoutubeConverter"/>.
 /// </summary>
 public YoutubeConverter(IYoutubeClient youtubeClient)
     : this(youtubeClient, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ffmpeg"))
 {
 }
示例#21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="YoutubeRepository"/> class.
 /// </summary>
 /// <param name="client">injected client.</param>
 /// <param name="quality">injected quality.</param>
 public YoutubeRepository(IYoutubeClient client, AudioQuality quality)
 {
     this.client  = client;
     this.quality = quality;
 }