private async Task <string> GetChannelID(IEnumerable <AuthenticationToken> tokens) { var flow = new ForceOfflineGoogleAuthorizationCodeFlow( new GoogleAuthorizationCodeFlow.Initializer { ClientSecrets = new ClientSecrets { ClientId = _configuration.GetSection("Google")["id"], ClientSecret = _configuration.GetSection("Google")["secret"] }, Scopes = new string[] { YouTubeService.Scope.YoutubeReadonly }, DataStore = new FileDataStore("ViviWebsite") }); var token = new TokenResponse { AccessToken = tokens.Where(x => x.Name == "access_token").First().Value, RefreshToken = tokens.Where(x => x.Name == "refresh_token").First().Value }; var credential = new UserCredential(flow, Environment.UserName, token); var youtubeService = new YouTubeService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = "ViviWebsite" }); return(await YouTubeApiService.GetChannelID(youtubeService)); }
public VodSearchEngine(FightingGameVodRepository repo, YouTubeApiService apiSvc, UshioConstants constants) { _fightingGameVodRepository = repo; _youTubeApiService = apiSvc; _ushioConstants = constants.InitializeVodChannelInfo(); _rnd = new Random(); _vodTitleParser = new VodTitleParser(); }
public async Task <ActionResult> GetSongInfo(IFormCollection collection, string pk = "", string rk = "") { var newSong = new NewSong(); if (!string.IsNullOrWhiteSpace(collection["YTLink"])) { var ytLink = collection["YTLink"].ToString(); var song = await YouTubeApiService.GetSongInfo(configuration, ytLink); var songExists = false; var youTubeLink = collection["YTLink"].ToString(); var videoID = YouTubeApiService.GetYouTubeVideoID(youTubeLink); var table = TableStorageService.ConnectToTable(Constants.AllSongsTableName); TableContinuationToken tableContinuationToken = null; do { var tableQuerySegment = await table.ExecuteQuerySegmentedAsync(new TableQuery <AllSongs>(), tableContinuationToken); var songs = tableQuerySegment.Results; songExists = songs.Any(x => x.YouTubeLink.Contains(videoID) && x.RowKey != rk); tableContinuationToken = tableQuerySegment.ContinuationToken; } while (tableContinuationToken != null && !songExists); if (!songExists) { newSong.OriginalGame = song.OriginalGame; newSong.OriginalTitle = song.OriginalTitle; newSong.YouTubeLink = song.YouTubeLink; newSong.Channel = song.Channel; newSong.Duration = song.Duration; newSong.YTLink = ytLink; newSong.PartitionKey = pk; newSong.RowKey = rk; //TODO: tags para dos casos: new y edit } else { return(RedirectToAction("Index", "Playlist", new { ac = "The YouTube video URL already exists in the playlist!", type = "danger" })); } } if (string.IsNullOrWhiteSpace(pk) || string.IsNullOrWhiteSpace(rk)) { return(View("Create", newSong)); } else { return(View("Edit", newSong)); } }
// Checks URL text box for a video or playlist link and adds the videos to the queue private void buttonAddVideos_Click(object sender, RoutedEventArgs e) { labelUrlStatus.Content = "Loading..."; labelUrlStatus.Refresh(); string videoID = LinkParser.GetVideoIDFromURL(textBoxURL.Text); string playlistID = LinkParser.GetPlaylistIDFromURL(textBoxURL.Text); // Check which IDs were found if (videoID != null && playlistID != null) { // Ask if user would like to load the attached playlist var result = MessageBox.Show( "This link contains a playlist. Would you like to load the playlist?", "Playlist Detected", MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { // Loads playlist instead of video videoID = null; } } if (videoID != null) { // Get video and add to list var video = YouTubeApiService.GetVideo(videoID); var videoListEntry = new VideoListEntry(video); VideoList.Add(videoListEntry); labelUrlStatus.Content = $"\"{video.Title}\" successfully added!"; } else if (playlistID != null) { // Get playlist and add all videos to list var videos = YouTubeApiService.GetPlaylist(playlistID); foreach (var video in videos) { var videoListEntry = new VideoListEntry(video); VideoList.Add(videoListEntry); } labelUrlStatus.Content = $"Playlist successfully added!"; } else { labelUrlStatus.Content = "Invalid link!"; } }
public FightingGameVodCommands(FightingGameVodRepository fgVodRepo, YouTubeApiService ytApiSvc, UshioConstants constants) { vodSearchEngine = new VodSearchEngine(fgVodRepo, ytApiSvc, constants); ushioConstants = constants; }