public Task <MetadataResult <Movie> > GetMetadata(ItemInfo info, IDirectoryService directoryService, CancellationToken cancellationToken) { var result = new MetadataResult <Movie>(); if (Plugin.Instance.Configuration.DisableLocalMetadata) { _logger.LogInformation("Local Metadata Disabled"); result.HasMetadata = false; return(Task.FromResult(result)); } try { var item = new Movie(); var infoJson = GetInfoJson(info.Path); result.HasMetadata = true; result.Item = item; var jsonObj = ReadJsonData(result, infoJson.FullName, cancellationToken); result.Item.Name = jsonObj.title; result.Item.Overview = jsonObj.description; var date = DateTime.ParseExact(jsonObj.upload_date, "yyyyMMdd", null); result.Item.ProductionYear = date.Year; result.Item.PremiereDate = date; result.AddPerson(YoutubeMetadataProvider.CreatePerson(jsonObj.uploader, jsonObj.channel_id)); return(Task.FromResult(result)); } catch (FileNotFoundException) { _logger.LogInformation("Could not find {0}", info.Path); result.HasMetadata = false; return(Task.FromResult(result)); } }
public async Task <MetadataResult <MusicVideo> > GetMetadata(MusicVideoInfo info, CancellationToken cancellationToken) { var result = new MetadataResult <MusicVideo>(); var id = YoutubeMetadataProvider.Current.GetYTID(info.Name); _logger.LogInformation(id); if (!string.IsNullOrWhiteSpace(id)) { await YoutubeMetadataProvider.Current.EnsureInfo(id, cancellationToken).ConfigureAwait(false); var path = YoutubeMetadataProvider.GetVideoInfoPath(_config.ApplicationPaths, id); var video = _json.DeserializeFromFile <Google.Apis.YouTube.v3.Data.Video>(path); if (video != null) { result.Item = new MusicVideo(); result.HasMetadata = true; result.Item.OriginalTitle = info.Name; YoutubeMetadataProvider.Current.ProcessResult(result.Item, video); result.AddPerson(YoutubeMetadataProvider.CreatePerson(video.Snippet.ChannelTitle, video.Snippet.ChannelId)); } } else { _logger.LogInformation("Youtube ID not found in filename of title: " + info.Name); } return(result); }
public YoutubeMetadataProvider(IServerConfigurationManager config, IFileSystem fileSystem, IHttpClient httpClient, IJsonSerializer json, ILogger logger, ILibraryManager libmanager) { _config = config; _fileSystem = fileSystem; _httpClient = httpClient; _json = json; _logger = logger; _libmanager = libmanager; Current = this; }
internal Task EnsureInfo(string channelId, CancellationToken cancellationToken) { var ytPath = YoutubeMetadataProvider.GetVideoInfoPath(_config.ApplicationPaths, channelId); var fileInfo = _fileSystem.GetFileSystemInfo(ytPath); if (fileInfo.Exists) { if ((DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(fileInfo)).TotalDays <= 10) { return(Task.CompletedTask); } } return(DownloadInfo(channelId, cancellationToken)); }
/// <inheritdoc /> public async Task <IEnumerable <RemoteImageInfo> > GetImages(BaseItem item, CancellationToken cancellationToken) { var id = YoutubeMetadataProvider.Current.GetYTID(item.FileNameWithoutExtension); if (!string.IsNullOrWhiteSpace(id)) { await YoutubeMetadataProvider.Current.EnsureInfo(id, cancellationToken).ConfigureAwait(false); var path = YoutubeMetadataProvider.GetVideoInfoPath(_config.ApplicationPaths, id); var obj = _json.DeserializeFromFile <Google.Apis.YouTube.v3.Data.Video>(path); if (obj != null) { var tnurls = new List <string>(); if (obj.Snippet.Thumbnails.Maxres != null) { tnurls.Add(obj.Snippet.Thumbnails.Maxres.Url); } if (obj.Snippet.Thumbnails.Standard != null) { tnurls.Add(obj.Snippet.Thumbnails.Standard.Url); } if (obj.Snippet.Thumbnails.High != null) { tnurls.Add(obj.Snippet.Thumbnails.High.Url); } if (obj.Snippet.Thumbnails.Medium != null) { tnurls.Add(obj.Snippet.Thumbnails.Medium.Url); } if (obj.Snippet.Thumbnails.Default__.Url != null) { tnurls.Add(obj.Snippet.Thumbnails.Default__.Url); } return(GetImages(tnurls)); } else { _logger.LogInformation("Object is null!"); } } return(new List <RemoteImageInfo>()); }
public async Task <IEnumerable <RemoteImageInfo> > GetImages(BaseItem item, CancellationToken cancellationToken) { var infos = new List <RemoteImageInfo>(); var channelId = item.ProviderIds["youtubemetadata"]; cancellationToken.ThrowIfCancellationRequested(); if (!string.IsNullOrWhiteSpace(channelId)) { await EnsureInfo(channelId, cancellationToken).ConfigureAwait(false); var path = YoutubeMetadataProvider.GetVideoInfoPath(_config.ApplicationPaths, channelId); var channel = _json.DeserializeFromFile <Google.Apis.YouTube.v3.Data.Channel>(path); if (channel != null) { var rii = new RemoteImageInfo(); if (channel.Snippet.Thumbnails.Maxres != null) { rii.Url = channel.Snippet.Thumbnails.Maxres.Url; } else if (channel.Snippet.Thumbnails.Standard != null) { rii.Url = channel.Snippet.Thumbnails.Standard.Url; } else if (channel.Snippet.Thumbnails.High != null) { rii.Url = channel.Snippet.Thumbnails.High.Url; } else if (channel.Snippet.Thumbnails.Medium != null) { rii.Url = channel.Snippet.Thumbnails.Medium.Url; } else if (channel.Snippet.Thumbnails.Default__.Url != null) { rii.Url = channel.Snippet.Thumbnails.Default__.Url; } infos.Add(rii); } } //return Task.FromResult<IEnumerable<RemoteImageInfo>>(infos); return(infos); }
/// <summary> /// Downloads metadata from Youtube API asyncronously and stores it as a json to cache. /// </summary> /// <param name="youtubeId"></param> /// <param name="cancellationToken"></param> /// <returns></returns> internal async Task DownloadInfo(string channelId, CancellationToken cancellationToken) { await Task.Delay(10000).ConfigureAwait(false); cancellationToken.ThrowIfCancellationRequested(); var youtubeService = new YouTubeService(new BaseClientService.Initializer() { ApiKey = Plugin.Instance.Configuration.apikey, ApplicationName = this.GetType().ToString() }); var vreq = youtubeService.Channels.List("snippet"); vreq.Id = channelId; var response = await vreq.ExecuteAsync(); var path = YoutubeMetadataProvider.GetVideoInfoPath(_config.ApplicationPaths, channelId); Directory.CreateDirectory(Path.GetDirectoryName(path)); var foo = response.Items[0]; _json.SerializeToFile(foo, path); }