private IEnumerator <IVideo> GetVideosInternal(IVideoRequestType requestType, int timeoutMs, int maxPerPage, VideoContext context) { string baseUrl; if (requestType is MyFavoritesRequestType) { // format the url for downloading baseUrl = String.Format( CultureInfo.InvariantCulture, "http://gdata.youtube.com/feeds/api/users/{0}/favorites", _videoAuth.Username); } else if (requestType is MyVideosRequestType) { baseUrl = String.Format( CultureInfo.InvariantCulture, "http://gdata.youtube.com/feeds/api/users/{0}/uploads", _videoAuth.Username); } else { throw new Exception("Unknown request type."); } int page = 1; while (true) { string queryString = string.Format(CultureInfo.InvariantCulture, "?max-results={0}&start-index={1}", maxPerPage, ((page - 1) * maxPerPage + 1)); string requestUrl = baseUrl + queryString; YouTubeVideo[] videos; int totalResults; // download the document Stream videoListStream = CallYouTubeApi(requestUrl, timeoutMs); // parse it into a list of videos videos = ParseVideoList(videoListStream, out totalResults); context.Available = totalResults; if (videos.Length == 0) { context.Full = true; yield break; } foreach (YouTubeVideo video in videos) { yield return(video); } page++; } }
private VideoBuffer GetBuffer(IVideoRequestType requestType, int timeoutMs, int pageSize) { if (!_ytVideoBuffers.ContainsKey(requestType)) { VideoContext context = new VideoContext(); _ytVideoBuffers[requestType] = new VideoBuffer(GetVideosInternal(requestType, timeoutMs, pageSize, context), context); } return(_ytVideoBuffers[requestType] as VideoBuffer); }
public void SelectEntry(string typeName) { for (int i = 0; i < Items.Count; i++) { IVideoRequestType requestType = (IVideoRequestType)Items[i]; if (requestType.TypeName == typeName) { SelectedIndex = i; return; } } }
public IVideo[] GetVideos(IVideoRequestType requestType, int timeoutMs, int maxPerPage, int page, out int videosAvailable) { VideoBuffer buffer = GetBuffer(requestType, timeoutMs, maxPerPage); // Insure we have enough videos in the Arraylist to satisfy the request int maxRequest = page * maxPerPage; buffer.FetchMore(maxRequest - buffer.Videos.Count); videosAvailable = buffer.Available; int startRequest = (page - 1) * maxPerPage; int count = maxPerPage; if (startRequest + maxPerPage > buffer.Videos.Count) { count = buffer.Videos.Count - startRequest; } // Deal with out of range return buffer.Videos.GetRange(startRequest, count).ToArray(); }
public IVideo[] GetVideos(IVideoRequestType requestType, int timeoutMs, int maxPerPage, int page, out int videosAvailable) { VideoBuffer buffer = GetBuffer(requestType, timeoutMs, maxPerPage); // Insure we have enough videos in the Arraylist to satisfy the request int maxRequest = page * maxPerPage; buffer.FetchMore(maxRequest - buffer.Videos.Count); videosAvailable = buffer.Available; int startRequest = (page - 1) * maxPerPage; int count = maxPerPage; if (startRequest + maxPerPage > buffer.Videos.Count) { count = buffer.Videos.Count - startRequest; } // Deal with out of range return(buffer.Videos.GetRange(startRequest, count).ToArray()); }
private VideoBuffer GetBuffer(IVideoRequestType requestType, int timeoutMs, int pageSize) { if (!_ytVideoBuffers.ContainsKey(requestType)) { VideoContext context = new VideoContext(); _ytVideoBuffers[requestType] = new VideoBuffer(GetVideosInternal(requestType, timeoutMs, pageSize, context), context); } return _ytVideoBuffers[requestType] as VideoBuffer; }
private IEnumerator<IVideo> GetVideosInternal(IVideoRequestType requestType, int timeoutMs, int maxPerPage, VideoContext context) { string baseUrl; if (requestType is MyFavoritesRequestType) { // format the url for downloading baseUrl = String.Format( CultureInfo.InvariantCulture, "http://gdata.youtube.com/feeds/api/users/{0}/favorites", _videoAuth.Username); } else if (requestType is MyVideosRequestType) { baseUrl = String.Format( CultureInfo.InvariantCulture, "http://gdata.youtube.com/feeds/api/users/{0}/uploads", _videoAuth.Username); } else { throw new Exception("Unknown request type."); } int page = 1; while (true) { string queryString = string.Format(CultureInfo.InvariantCulture, "?max-results={0}&start-index={1}", maxPerPage, ((page - 1) * maxPerPage + 1)); string requestUrl = baseUrl + queryString; YouTubeVideo[] videos; int totalResults; // download the document Stream videoListStream = CallYouTubeApi(requestUrl, timeoutMs); // parse it into a list of videos videos = ParseVideoList(videoListStream, out totalResults); context.Available = totalResults; if (videos.Length == 0) { context.Full = true; yield break; } foreach (YouTubeVideo video in videos) yield return video; page++; } }
public void SetEntries(IVideoRequestType[] requestTypes) { Items.Clear(); foreach (IVideoRequestType requestType in requestTypes) Items.Add(requestType); }