private async Task <YoutubeDTO> GetInfoFromYouTubeSearchAPI(string steemTitle, string steemDescription, double steemDuration, string steemAuthor)
        {
            var client = new RestClient("https://www.googleapis.com/youtube/v3/");

            var request = new RestRequest("search", Method.GET);

            request.AddQueryParameter("part", "snippet");
            request.AddQueryParameter("q", steemTitle);
            request.AddQueryParameter("type", "video");
            request.AddQueryParameter("maxResults", "1");
            request.AddQueryParameter("fields", "items(snippet(publishedAt,title,description,channelTitle,channelId),id(videoId))");
            request.AddQueryParameter("key", _configurationManager.YouTubeApiKey);

            IRestResponse response = await client.ExecuteTaskAsync(request);

            YouTubeRoot resp = JsonConvert.DeserializeObject <YouTubeRoot>(response.Content);

            if (resp == null || resp.Items.Length == 0)
            {
                return new YoutubeDTO {
                           ErrorMessage = "pas de réponse de YouTube"
                }
            }
            ;

            YouTubeSnippet video = resp.Items[0].Snippet;
            YouTubeId      id    = resp.Items[0].Id;

            // similitudes
            var    jw                  = new JaroWinkler();
            double distanceTitle       = FormatScore(jw.Similarity(steemTitle, video.Title));
            double distanceDescription = FormatScore(jw.Similarity(steemDescription, video.Description));
            double distanceAuthor      = FormatScore(jw.Similarity(steemAuthor, video.ChannelTitle));

            var dto = new YoutubeDTO
            {
                Success             = true,
                VideoId             = id.VideoId,
                VideoTitle          = video.Title,
                ChannelId           = video.ChannelId,
                ChannelTitle        = video.ChannelTitle,
                PublishedAt         = video.PublishedAt,
                DistanceTitle       = distanceTitle,
                DistanceDescription = distanceDescription,
                DistanceAuthor      = distanceAuthor
            };

            return(dto);
        }
Exemple #2
0
        protected async override Task LoadImage(DirectoryInfo albumCoverDirectory)
        {
            if (albumCoverDirectory.Exists)
            {
                var imageFile =
                    albumCoverDirectory.GetFiles("*.jpg")
                    .FirstOrDefault(item => item.Name.ToLower() == YouTubeId.ToLower());

                if (imageFile != null)
                {
                    Image = new BitmapImage(new Uri(imageFile.FullName));
                    return;
                }

                Image = MusicCoverManager.GetAlbumImage(this, albumCoverDirectory);
                if (Image != null)
                {
                    return;
                }
            }


            if (HurricaneSettings.Instance.Config.LoadAlbumCoverFromInternet)
            {
                try
                {
                    if (!string.IsNullOrEmpty(ThumbnailUrl))
                    {
                        Image = await YouTubeApi.LoadBitmapImage(this, albumCoverDirectory);

                        if (Image != null)
                        {
                            return;
                        }
                    }

                    Image = await MusicCoverManager.LoadCoverFromWeb(this, albumCoverDirectory, Uploader != Artist);
                }
                catch (WebException)
                {
                    //Happens, doesn't matter
                }
            }
        }
Exemple #3
0
 public YouTubeTrack(string id)
 {
     Id = new YouTubeId {
         VideoId = id
     };
 }