Beispiel #1
0
        public DetailsPage(YouTubeItem item)
        {
            InitializeComponent();
            var url = "https://www.youtube.com/watch?v=" + item.videoId;

            loadVideo_wv.Source = url;
        }
        private async Task <List <YouTubeItem> > GetVideoDetailsAsync(List <string> videoIds)
        {
            const string ApiKey     = "AIzaSyB7cpaKiojWIKVz6rTYNRn_CiRI0GWt8q0";
            string       detailsUrl = "https://www.googleapis.com/youtube/v3/videos?part=snippet,statistics&key=" + ApiKey + "&id={0}";

            try
            {
                var videoIdString = string.Join(",", videoIds);
                var youtubeItems  = new List <YouTubeItem>();

                using (var httpClient = new HttpClient())
                {
                    var json = await httpClient.GetStringAsync(string.Format(detailsUrl, videoIdString));

                    var response = JsonConvert.DeserializeObject <YouTubeApiDetailsRoot>(json);

                    foreach (var item in response.items)
                    {
                        var youTubeItem = new YouTubeItem()
                        {
                            Title                = item.snippet.title,
                            Description          = item.snippet.description,
                            ChannelTitle         = item.snippet.channelTitle,
                            PublishedAt          = item.snippet.publishedAt,
                            VideoId              = item.id,
                            DefaultThumbnailUrl  = item.snippet?.thumbnails?.@default?.url,
                            MediumThumbnailUrl   = item.snippet?.thumbnails?.medium?.url,
                            HighThumbnailUrl     = item.snippet?.thumbnails?.high?.url,
                            StandardThumbnailUrl = item.snippet?.thumbnails?.standard?.url,
                            MaxResThumbnailUrl   = item.snippet?.thumbnails?.maxres?.url,
                            ViewCount            = item.statistics?.viewCount,
                            LikeCount            = item.statistics?.likeCount,
                            DislikeCount         = item.statistics?.dislikeCount,
                            FavoriteCount        = item.statistics?.favoriteCount,
                            CommentCount         = item.statistics?.commentCount,
                            Tags = item.snippet?.tags
                        };

                        youtubeItems.Add(youTubeItem);
                    }
                }

                return(youtubeItems);
            }
            catch (Exception ex)
            {
                var ms = ex;
                return(new List <YouTubeItem>());
            }
        }
        async Task <ObservableCollection <YouTubeItem> > GetVideoDetailsAsync(List <string> videoIds)
        {
            try
            {
                var videoIdString = string.Join(",", videoIds);
                var youtubeItems  = new ObservableCollection <YouTubeItem>();

                using (var httpClient = new HttpClient())
                {
                    string url  = string.Format(detailsUrl, videoIdString);
                    var    json = await httpClient.GetStringAsync(url);

                    var response = JsonConvert.DeserializeObject <YouTubeApiDetailsRoot>(json);

                    foreach (var item in response.items)
                    {
                        var youTubeItem = new YouTubeItem()
                        {
                            Title                = item.snippet.title,
                            Description          = item.snippet.description,
                            ChannelTitle         = item.snippet.channelTitle,
                            PublishedAt          = item.snippet.publishedAt,
                            VideoId              = item.id,
                            DefaultThumbnailUrl  = item.snippet?.thumbnails?.@default?.url,
                            MediumThumbnailUrl   = item.snippet?.thumbnails?.medium?.url,
                            HighThumbnailUrl     = item.snippet?.thumbnails?.high?.url,
                            StandardThumbnailUrl = item.snippet?.thumbnails?.standard?.url,
                            MaxResThumbnailUrl   = item.snippet?.thumbnails?.maxres?.url,
                            ViewCount            = item.statistics?.viewCount,
                            LikeCount            = item.statistics?.likeCount,
                            DislikeCount         = item.statistics?.dislikeCount,
                            FavoriteCount        = item.statistics?.favoriteCount,
                            CommentCount         = item.statistics?.commentCount,
                            Tags = item.snippet?.tags
                        };


                        youtubeItems.Add(youTubeItem);
                    }
                }
                var res = youtubeItems.ToList().OrderBy(n => n.PublishedAt);
                return(new ObservableCollection <YouTubeItem>(res));
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
                return(new ObservableCollection <YouTubeItem>());
            }
        }
        async Task GetPlayListVideos()
        {
            try
            {
                using (var httpClient = new HttpClient())
                {
                    Items = new ObservableCollection <YouTubeItem>();
                    var youtubeItems = new ObservableCollection <YouTubeItem>();
                    var videoIds     = new List <string>();
                    var json         = await httpClient.GetStringAsync(channelUrl);

                    // Deserialize our data, this is in a simple List format
                    var response = JsonConvert.DeserializeObject <YouTubeApiDetailsRoot>(json);

                    foreach (var item in response.items)
                    {
                        var youTubeItem = new YouTubeItem()
                        {
                            Title                = item.snippet.title,
                            Description          = item.snippet.description,
                            ChannelTitle         = item.snippet.channelTitle,
                            PublishedAt          = item.snippet.publishedAt,
                            DefaultThumbnailUrl  = item.snippet?.thumbnails?.@default?.url,
                            MediumThumbnailUrl   = item.snippet?.thumbnails?.medium?.url,
                            HighThumbnailUrl     = item.snippet?.thumbnails?.high?.url,
                            StandardThumbnailUrl = item.snippet?.thumbnails?.standard?.url,
                            MaxResThumbnailUrl   = item.snippet?.thumbnails?.maxres?.url,
                            ViewCount            = item.statistics?.viewCount,
                            LikeCount            = item.statistics?.likeCount,
                            DislikeCount         = item.statistics?.dislikeCount,
                            FavoriteCount        = item.statistics?.favoriteCount,
                            CommentCount         = item.statistics?.commentCount,
                            Tags    = item.snippet?.tags,
                            videoId = item.snippet?.resourceId?.videoId
                        };


                        youtubeItems.Add(youTubeItem);
                    }
                    var res = youtubeItems.ToList().OrderBy(n => n.PublishedAt);
                    Items = new ObservableCollection <YouTubeItem>(res);
                }
            }
            catch (Exception ex)
            {
                var ms = ex;
            }
        }
Beispiel #5
0
        public static IVideoItem CreateVideoItem(VideoItemPOCO poco,
                                                 SiteType site,
                                                 bool isJoinName  = false,
                                                 SyncState sstate = SyncState.Notset)
        {
            IVideoItem vi;

            switch (site)
            {
            case SiteType.YouTube:
                vi = new YouTubeItem
                {
                    ID             = poco.ID,
                    Title          = poco.Title,
                    ParentID       = poco.ParentID,
                    Description    = poco.Description,  // .WordWrap(80);
                    ViewCount      = poco.ViewCount,
                    Duration       = poco.Duration,
                    Comments       = poco.Comments,
                    Thumbnail      = poco.Thumbnail,
                    Timestamp      = poco.Timestamp,
                    LikeCount      = poco.LikeCount,
                    DislikeCount   = poco.DislikeCount,
                    ViewDiff       = poco.ViewDiff,
                    SyncState      = sstate == SyncState.Notset ? (SyncState)poco.SyncState : sstate,
                    WatchState     = (WatchState)poco.WatchState,
                    DurationString = StringExtensions.IntTostrTime(poco.Duration),
                    DateTimeAgo    = StringExtensions.TimeAgo(poco.Timestamp),
                    Subtitles      = new ObservableCollection <ISubtitle>(),
                    ParentTitle    = isJoinName ? poco.ParentName : string.Empty
                };
                break;

            case SiteType.Tapochek:
                vi = new TapochekItem();
                break;

            case SiteType.RuTracker:
                vi = new RuTrackerItem();
                break;

            default:
                vi = null;
                break;
            }
            return(vi);
        }
Beispiel #6
0
        private async Task GetVideoDetailsAsync(List <string> videoIds)
        {
            var videoIdString = string.Join(",", videoIds);

            using (var httpClient = new HttpClient())
            {
                var json = await httpClient.GetStringAsync(string.Format(AppConstants.detailsUrl, videoIdString));

                var response = JsonConvert.DeserializeObject <YoutubeRoot>(json);



                foreach (var item in response.items)
                {
                    var youTubeItem = new YouTubeItem()
                    {
                        Title                = item.snippet.title,
                        Description          = item.snippet.description,
                        ChannelTitle         = item.snippet.channelTitle,
                        PublishedAt          = item.snippet.publishedAt.ToString(),
                        VideoId              = item.id,
                        DefaultThumbnailUrl  = item.snippet?.thumbnails?.@default?.url,
                        MediumThumbnailUrl   = item.snippet?.thumbnails?.medium?.url,
                        HighThumbnailUrl     = item.snippet?.thumbnails?.high?.url,
                        StandardThumbnailUrl = item.snippet?.thumbnails?.standard?.url,
                        MaxResThumbnailUrl   = item.snippet?.thumbnails?.maxres?.url,
                        ViewCount            = item.statistics?.viewCount,
                        LikeCount            = item.statistics?.likeCount,
                        DislikeCount         = item.statistics?.dislikeCount,
                        FavoriteCount        = item.statistics?.favoriteCount,
                        CommentCount         = item.statistics?.commentCount,
                        VDLink               = "https://www.youtube.com/embed/" + item.id + @"\"
                                               //Tags = item.snippet?.tags
                    };

                    VideosList.Add(youTubeItem);
                }
            }
        }