public async Task <Dictionary <string, VideoViewModel> > GetVideos(List <HistoryVideo> historyVideos) { PopulatePastVideoSearchesDict(); Dictionary <string, VideoViewModel> apiVideosDict = new Dictionary <string, VideoViewModel>(); foreach (var historyVideo in historyVideos) { string id = historyVideo.GetVideoID(); if (!apiVideosDict.ContainsKey(id)) { if (PastVideoSearchesDict.ContainsKey(id)) { apiVideosDict.Add(id, PastVideoSearchesDict[id]); } else { ApiVideo apiVideo = await GetVideoDataFromApi(id); if (apiVideo.Items.Length > 0) { VideoViewModel viewModel = VideoViewModel.FromApiVideo(apiVideo); await WriteVideoViewModelToFile(viewModel); apiVideosDict.Add(id, viewModel); PastVideoSearchesDict.Add(id, viewModel); } } } } return(apiVideosDict); }
protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); var(resp, httpResp) = await Backend.VideoList(new VideoListRequest() { Ids = new[] { VideoId } }); if (httpResp.IsSuccessStatusCode) { video = resp.Data.Videos.FirstOrDefault(); if (video == null) { errorMessage = "An error occurred while getting video details."; } string plainDesc = video?.Description ?? ""; FormattedDescription = new MarkupString(plainDesc.FormatAsHtml()); } else { errorMessage = "An error occurred while getting video details: " + resp.Message; } videoStreamUri = await Backend.VideoViewUrl(VideoId); }
public async Task <ApiVideo> GetVideoDataFromApi(string videoId) { string googleKey = Environment.GetEnvironmentVariable("$GOOGLE_APIKEY_YOUTUBE_WRAPPED", EnvironmentVariableTarget.Machine); Uri uri = new Uri(@"https://youtube.googleapis.com/youtube/v3/videos?part=snippet%2CcontentDetails&id=" + videoId + "&key=" + googleKey); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); request.AutomaticDecompression = DecompressionMethods.GZip; //request.UserAgent = "12345"; string responseString = string.Empty; using (HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync()) using (Stream stream = response.GetResponseStream()) using (StreamReader reader = new StreamReader(stream)) { responseString = reader.ReadToEnd(); ApiVideo apiVideo = JsonConvert.DeserializeObject <ApiVideo>(responseString); return(apiVideo); } }
private void NotifyVideoUpdated(ApiVideo video) { VideoUpdated?.Invoke(this, video); }
public VideoViewModel(ApiVideo apiVideo) { ApiVideo = apiVideo; }
public async Task NotifyVideoUpdated(UserAccount userAccount, ApiVideo video) { await ForUser(userAccount).NotifyVideoUpdated(video); }