Example #1
0
        public async Task <IResponceList> Search(string searchString, int maxResult, string nextPageToken, string culture, SearchType searchType, SearchFilter searchFilter)
        {
            var request = _youTubeService.Search.List("snippet,id");

            request.Key               = _youTubeServiceControl.ApiKey;
            request.PageToken         = nextPageToken;
            request.MaxResults        = SEARCH_PAGE_MAX_RESULT;
            request.Type              = searchType.ToTypeString();
            request.Q                 = searchString;
            request.Order             = searchFilter.Order;
            request.PublishedAfter    = searchFilter.PublishedAfter;
            request.PublishedBefore   = searchFilter.PublishedBefore;
            request.RegionCode        = I18nLanguages.GetRegionCode(culture);
            request.RelevanceLanguage = I18nLanguages.GetHl(culture);

            if (searchType == SearchType.Video)
            {
                request.VideoDuration   = searchFilter.VideoDuration;
                request.VideoDefinition = searchFilter.VideoDefinition;
            }

            var response = await request.ExecuteAsync();

            if (searchType == SearchType.Video)
            {
                var ids = new StringBuilder();
                foreach (var item in response.Items)
                {
                    ids.AppendLine(item.Id.VideoId);
                    ids.AppendLine(",");
                }
                var videoDetails = await GetVideoDetails(ids.ToString());

                return(new MVideoList(response, videoDetails));
            }

            if (searchType == SearchType.Channel)
            {
                return(new MChannelList(response));
            }

            if (searchType == SearchType.Playlist)
            {
                var ids = new StringBuilder();
                foreach (var item in response.Items)
                {
                    ids.AppendLine(item.Id.PlaylistId);
                    ids.AppendLine(",");
                }
                var list = await GetPlaylistList(ids.ToString(), response.NextPageToken);

                return(list);
            }

            return(MVideoList.Empty);
        }
Example #2
0
        public async Task <IEnumerable <IGuideCategory> > GetGuideCategories(string culture)
        {
            var categoriesListRequest = _youTubeService.GuideCategories.List("snippet");

            categoriesListRequest.Key        = _youTubeServiceControl.ApiKey;
            categoriesListRequest.RegionCode = I18nLanguages.GetRegionCode(culture);
            categoriesListRequest.Hl         = I18nLanguages.GetHl(culture);;

            GuideCategoryListResponse categoriesListResponse = await categoriesListRequest.ExecuteAsync();

            return(categoriesListResponse.Items.Select(category => new MGuideCategory(category)).Cast <IGuideCategory>().ToList());
        }
Example #3
0
        public async Task <IChannelList> GetChannels(string categoryId, string culture, int maxPageResult, string nextPageToken)
        {
            var channelListRequest = _youTubeService.Channels.List("snippet,statistics,brandingSettings");

            channelListRequest.Key        = _youTubeServiceControl.ApiKey;
            channelListRequest.Hl         = I18nLanguages.GetHl(culture);
            channelListRequest.CategoryId = categoryId;
            channelListRequest.MaxResults = maxPageResult;
            channelListRequest.PageToken  = nextPageToken;

            var channelListResponse = await channelListRequest.ExecuteAsync();

            return(new MChannelList(channelListResponse));
        }
Example #4
0
        public async Task <IEnumerable <IVideoCategory> > GetCategories(string culture)
        {
            var categoriesListRequest = _youTubeService.VideoCategories.List("snippet");

            categoriesListRequest.Key        = _youTubeServiceControl.ApiKey;
            categoriesListRequest.RegionCode = I18nLanguages.GetRegionCode(culture);
            categoriesListRequest.Hl         = I18nLanguages.GetHl(culture);

            var categoriesListResponse = await categoriesListRequest.ExecuteAsync();

            var items = categoriesListResponse.Items.Where(c => c.Snippet != null && c.Snippet.Assignable == true);

            return(items.Select(category => new MVideoCategory(category)));//.Cast<IVideoCategory>().ToList();
        }
Example #5
0
        public async Task <IVideoList> GetMostPopular(string culture, int maxResult, string pageToken)
        {
            try
            {
                var videoRequest = _youTubeService.Videos.List("snippet,contentDetails,statistics");
                videoRequest.RegionCode = I18nLanguages.GetRegionCode(culture);
                videoRequest.Chart      = VideosResource.ListRequest.ChartEnum.MostPopular;
                videoRequest.Hl         = I18nLanguages.GetHl(culture);;
                videoRequest.Key        = _youTubeServiceControl.ApiKey;
                videoRequest.MaxResults = maxResult;
                videoRequest.PageToken  = pageToken;

                var videoResponse = await videoRequest.ExecuteAsync();

                return(new MVideoList(videoResponse));
            }
            catch (Exception)
            {
                return(await GetMostPopularWeb(I18nLanguages.GetRegionCode(culture), maxResult, pageToken));
            }
        }