private async void OnFetchFromURL(object sender, RoutedEventArgs e) { string URL = URLInputTextBox.Text; if (CSTube.Extract.isVideoURL(URL)) { // Record as music item CSTube.Video video = new CSTube.Video(URL); MediaItem item = MediaItem.fromCTVideo(video); curMediaList.Add(item); UpdateMediaList(); // Fetch music data and update list once ready await video.FetchInformation(); item.UpdateFromCTVideo(video); UpdateMediaList(); } else if (CSTube.Extract.isPlaylistURL(URL)) { // Fetch playlist items and record them, then continuously update them Debug.Log("Cannot load all playlist videos yet, Google API implementation missing!"); } else { Debug.Log("ERROR: URL does not point to a valid youtube video!"); } }
public static Task FetchPTVideosDataAsync(List <MediaItem> music) { StartPostLogging(true); Task fetchTask = Task.Factory.StartNew(() => { Parallel.ForEach(music, (MediaItem item) => { CSTube.Video video = new CSTube.Video(item.URL); video.FetchInformation().Wait(); item.UpdateFromCTVideo(video); postLogger.Log(video.ToString()); }); }); return(fetchTask.ContinueWith((Task t) => { EndPostLogging(); Debug.Log("Finished asynchronous PT video data fetch for " + music.Count + " videos!"); }, TaskScheduler.FromCurrentSynchronizationContext())); }