private async Task <IEnumerable <RemoteChapterResult> > SearchAsync(ChapterSearchRequest request,
                                                                            CancellationToken cancellationToken)
        {
            var duration = String.Empty;

            if (request.RuntimeTicks.HasValue)
            {
                duration = GetTimeString(request.RuntimeTicks.Value);
            }

            var url = BaseUrl + String.Format("search?title={0}&duration={1}", request.Name, duration);

            var options = GetHttpRequestOptions(cancellationToken, url);

            using (var stream = await _httpClient.Get(options).ConfigureAwait(false))
            {
                var result = _xmlSerializer.DeserializeFromStream(typeof(Results), stream) as Results;
                if (result == null)
                {
                    return(new List <RemoteChapterResult>());
                }

                var details = result.Detail;

                var runtime = request.RuntimeTicks;
                details = details
                          .OrderBy(i =>
                {
                    if (!runtime.HasValue)
                    {
                        return(0);
                    }

                    return(Math.Abs(runtime.Value - i.Source.Duration.Ticks));
                })
                          .ThenBy(i => i.Confirmations)
                          .ToList();

                return(details.Select(x =>
                {
                    var c = new RemoteChapterResult
                    {
                        Id = x.Ref.ChapterSetId,
                        Name = x.Title,
                        RunTimeTicks = x.Source.Duration.Ticks
                    };

                    _logger.Debug(string.Format("\"{0}\" results - {1}: {2} [{3}]", request.Name, c.Name, c.Id, GetTimeString(c.RunTimeTicks.Value)));

                    return c;
                }));
            }
        }
 public async Task <rss> GetStreamList(String queryUrl, int offset, CancellationToken cancellationToken)
 {
     using (var xml = await _httpClient.Get(queryUrl, CancellationToken.None).ConfigureAwait(false))
     {
         return(_xmlSerializer.DeserializeFromStream(typeof(rss), xml) as rss);
     }
 }
Exemple #3
0
        public static async Task ExtractSystemTemplates(ILogger logger, IDeviceProfileManager profileManager, IXmlSerializer xmlSerializer)
        {
            if (profileManager.Profiles.Count(p => p.ProfileType == DeviceProfileType.SystemTemplate) > 1)
            {
                // Don't load more than once.
                return;
            }

            // Load Resources into memory.
            const string NamespaceName = "Jellyfin.Plugin.Dlna.Profiles.Xml.";

            foreach (var name in _assembly.GetManifestResourceNames())
            {
                if (!name.StartsWith(NamespaceName, StringComparison.Ordinal))
                {
                    continue;
                }

                await using var stream = _assembly.GetManifestResourceStream(name);
                if (stream == null)
                {
                    logger.LogError("Unable to extract manifest resource for {Name}", name);
                    break;
                }

                var systemProfile = (DeviceProfile)xmlSerializer.DeserializeFromStream(typeof(DeviceProfile), stream);
                if (systemProfile != null)
                {
                    systemProfile.ProfileType = DeviceProfileType.SystemTemplate;
                    profileManager.AddProfile(systemProfile);
                }
            }
        }
        private async Task <IEnumerable <RemoteChapterResult> > FetchAsyncInternal(ChapterSearchRequest request,
                                                                                   CancellationToken cancellationToken)
        {
            string imdbIdText = request.GetProviderId(MetadataProviders.Imdb);
            long   imdbId     = 0;

            long.TryParse(imdbIdText.TrimStart('t'), NumberStyles.Any, _usCulture, out imdbId);

            var p = new SearchParameters
            {
                Type      = SearchType.Search,
                Title     = request.Name,
                Language  = request.Language,
                Show      = request.SeriesName,
                Season    = request.ParentIndexNumber,
                Episode   = request.IndexNumber,
                VideoKind = request.ContentType == VideoContentType.Movie ? "Movie" : "TVShow",
                ImdbId    = imdbId > 0 ? imdbId.ToString() : null,
                Token     = ApiKey,
                Locked    = true,
            };

            var url = BaseUrl + p.BuildQueryString();

            using (var stream = await _httpClient.Get(new HttpRequestOptions
            {
                Url = url,
                ResourcePool = _resourcePool,
                CancellationToken = cancellationToken
            }).ConfigureAwait(false))
            {
                var result = _xmlSerializer.DeserializeFromStream(typeof(SearchResults), stream) as SearchResults;
                if (result == null)
                {
                    return(new List <RemoteChapterResult>());
                }

                var first = result.Movies.FirstOrDefault();
                if (first != null)
                {
                    return(first.Chapters.Items.Select(x => new RemoteChapterResult
                    {
                        Id = x.Index.ToString(),
                        Name = x.Title,
                        RunTimeTicks = x.StartTime.Ticks
                    }));
                }
                else
                {
                    return(new List <RemoteChapterResult>());
                }
            }
        }
Exemple #5
0
 public object DeserializeXml(Type type, Stream stream)
 {
     return(_xmlSerializer.DeserializeFromStream(type, stream));
 }
Exemple #6
0
 public Task <object> DeserializeXml(Type type, Stream stream)
 {
     return(Task.FromResult(_xmlSerializer.DeserializeFromStream(type, stream)));
 }