Ejemplo n.º 1
0
        public object Get(GetMetadataEditorInfo request)
        {
            var item = _libraryManager.GetItemById(request.ItemId);

            var info = new MetadataEditorInfo
            {
                ParentalRatingOptions = _localizationManager.GetParentalRatings(),
                ExternalIdInfos       = _providerManager.GetExternalIdInfos(item).ToArray(),
                Countries             = _localizationManager.GetCountries(),
                Cultures = _localizationManager.GetCultures()
            };

            if (!item.IsVirtualItem && !(item is ICollectionFolder) && !(item is UserView) && !(item is AggregateFolder) && !(item is LiveTvChannel) && !(item is IItemByName) &&
                item.SourceType == SourceType.Library)
            {
                var inheritedContentType  = _libraryManager.GetInheritedContentType(item);
                var configuredContentType = _libraryManager.GetConfiguredContentType(item);

                if (string.IsNullOrWhiteSpace(inheritedContentType) || !string.IsNullOrWhiteSpace(configuredContentType))
                {
                    info.ContentTypeOptions = GetContentTypeOptions(true).ToArray();
                    info.ContentType        = configuredContentType;

                    if (string.IsNullOrWhiteSpace(inheritedContentType) || string.Equals(inheritedContentType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase))
                    {
                        info.ContentTypeOptions = info.ContentTypeOptions
                                                  .Where(i => string.IsNullOrWhiteSpace(i.Value) || string.Equals(i.Value, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase))
                                                  .ToArray();
                    }
                }
            }

            return(ToOptimizedResult(info));
        }
Ejemplo n.º 2
0
        private async Task <RootObject> FetchMainResult(string id, string language, CancellationToken cancellationToken)
        {
            var url = string.Format(GetCollectionInfo3, id, MovieDbProvider.ApiKey);

            var imageLanguages = _localization.GetCultures()
                                 .Select(i => i.TwoLetterISOLanguageName)
                                 .Distinct(StringComparer.OrdinalIgnoreCase)
                                 .ToList();

            imageLanguages.Add("null");

            if (!string.IsNullOrEmpty(language))
            {
                // If preferred language isn't english, get those images too
                if (!imageLanguages.Contains(language, StringComparer.OrdinalIgnoreCase))
                {
                    imageLanguages.Add(language);
                }

                url += string.Format("&language={0}", language);
            }

            // Get images in english and with no language
            url += "&include_image_language=" + string.Join(",", imageLanguages.ToArray());

            cancellationToken.ThrowIfCancellationRequested();

            RootObject mainResult = null;

            using (var json = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions
            {
                Url = url,
                CancellationToken = cancellationToken,
                AcceptHeader = MovieDbSearch.AcceptHeader
            }).ConfigureAwait(false))
            {
                mainResult = _json.DeserializeFromStream <RootObject>(json);
            }

            cancellationToken.ThrowIfCancellationRequested();

            if (mainResult != null && string.IsNullOrEmpty(mainResult.overview))
            {
                if (!string.IsNullOrEmpty(language) && !string.Equals(language, "en", StringComparison.OrdinalIgnoreCase))
                {
                    url = string.Format(GetCollectionInfo3, id, MovieDbSearch.ApiKey) + "&include_image_language=en,null&language=en";

                    using (var json = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions
                    {
                        Url = url,
                        CancellationToken = cancellationToken,
                        AcceptHeader = MovieDbSearch.AcceptHeader
                    }).ConfigureAwait(false))
                    {
                        mainResult = _json.DeserializeFromStream <RootObject>(json);
                    }
                }
            }
            return(mainResult);
        }
Ejemplo n.º 3
0
        public static string GetImageLanguagesParam(ILocalizationManager localization, string preferredLanguage)
        {
            var languages = new List <string>();

            if (!string.IsNullOrEmpty(preferredLanguage))
            {
                languages.Add(preferredLanguage);
            }
            languages.Add("null");
            if (!string.Equals(preferredLanguage, "en", StringComparison.OrdinalIgnoreCase))
            {
                languages.Add("en");
            }

            var firstLetter = string.IsNullOrWhiteSpace(preferredLanguage)
                ? string.Empty
                : preferredLanguage.Substring(0, 1);

            var allLanguages = localization.GetCultures()
                               .Select(i => i.TwoLetterISOLanguageName)
                               .Distinct(StringComparer.OrdinalIgnoreCase)
                               .Where(i => !languages.Contains(i, StringComparer.OrdinalIgnoreCase) && i.StartsWith(firstLetter, StringComparison.OrdinalIgnoreCase))
                               .ToList();

            //languages.AddRange(allLanguages);

            return(string.Join(",", languages.ToArray()));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Adds the external subtitles.
        /// </summary>
        /// <param name="video">The video.</param>
        /// <param name="currentStreams">The current streams.</param>
        private void AddExternalSubtitles(Video video, List <MediaStream> currentStreams, IDirectoryService directoryService)
        {
            var files = GetSubtitleFiles(video, directoryService);

            var startIndex = currentStreams.Count;
            var streams    = new List <MediaStream>();

            var videoFileNameWithoutExtension = Path.GetFileNameWithoutExtension(video.Path);

            foreach (var file in files)
            {
                var fullName = file.FullName;

                var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fullName);

                // If the subtitle file matches the video file name
                if (string.Equals(videoFileNameWithoutExtension, fileNameWithoutExtension, StringComparison.OrdinalIgnoreCase))
                {
                    streams.Add(new MediaStream
                    {
                        Index      = startIndex++,
                        Type       = MediaStreamType.Subtitle,
                        IsExternal = true,
                        Path       = fullName,
                        Codec      = Path.GetExtension(fullName).ToLower().TrimStart('.')
                    });
                }
                else if (fileNameWithoutExtension.StartsWith(videoFileNameWithoutExtension + ".", StringComparison.OrdinalIgnoreCase))
                {
                    // Support xbmc naming conventions - 300.spanish.srt
                    var language = fileNameWithoutExtension.Split('.').LastOrDefault();

                    // Try to translate to three character code
                    // Be flexible and check against both the full and three character versions
                    var culture = _localization.GetCultures()
                                  .FirstOrDefault(i => string.Equals(i.DisplayName, language, StringComparison.OrdinalIgnoreCase) || string.Equals(i.Name, language, StringComparison.OrdinalIgnoreCase) || string.Equals(i.ThreeLetterISOLanguageName, language, StringComparison.OrdinalIgnoreCase) || string.Equals(i.TwoLetterISOLanguageName, language, StringComparison.OrdinalIgnoreCase));

                    if (culture != null)
                    {
                        language = culture.ThreeLetterISOLanguageName;
                    }

                    streams.Add(new MediaStream
                    {
                        Index      = startIndex++,
                        Type       = MediaStreamType.Subtitle,
                        IsExternal = true,
                        Path       = fullName,
                        Codec      = Path.GetExtension(fullName).ToLower().TrimStart('.'),
                        Language   = language
                    });
                }
            }

            video.SubtitleFiles = streams.Select(i => i.Path).OrderBy(i => i).ToList();

            currentStreams.AddRange(streams);
        }
Ejemplo n.º 5
0
        public ActionResult <MetadataEditorInfo> GetMetadataEditorInfo([FromRoute, Required] Guid itemId)
        {
            var item = _libraryManager.GetItemById(itemId);

            var info = new MetadataEditorInfo
            {
                ParentalRatingOptions = _localizationManager.GetParentalRatings().ToArray(),
                ExternalIdInfos       = _providerManager.GetExternalIdInfos(item).ToArray(),
                Countries             = _localizationManager.GetCountries().ToArray(),
                Cultures = _localizationManager.GetCultures().ToArray()
            };

            if (!item.IsVirtualItem &&
                item is not ICollectionFolder &&
                item is not UserView &&
                item is not AggregateFolder &&
                item is not LiveTvChannel &&
                item is not IItemByName &&
                item.SourceType == SourceType.Library)
            {
                var inheritedContentType  = _libraryManager.GetInheritedContentType(item);
                var configuredContentType = _libraryManager.GetConfiguredContentType(item);

                if (string.IsNullOrWhiteSpace(inheritedContentType) ||
                    !string.IsNullOrWhiteSpace(configuredContentType))
                {
                    info.ContentTypeOptions = GetContentTypeOptions(true).ToArray();
                    info.ContentType        = configuredContentType;

                    if (string.IsNullOrWhiteSpace(inheritedContentType) ||
                        string.Equals(inheritedContentType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase))
                    {
                        info.ContentTypeOptions = info.ContentTypeOptions
                                                  .Where(i => string.IsNullOrWhiteSpace(i.Value) ||
                                                         string.Equals(i.Value, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase))
                                                  .ToArray();
                    }
                }
            }

            return(info);
        }
        internal async Task <RootObject> FetchMainResult(string id, int seasonNumber, int episodeNumber, string language, CancellationToken cancellationToken)
        {
            var url = string.Format(GetTvInfo3, id, seasonNumber.ToString(CultureInfo.InvariantCulture), episodeNumber, MovieDbProvider.ApiKey);

            var imageLanguages = _localization.GetCultures()
                                 .Select(i => i.TwoLetterISOLanguageName)
                                 .Distinct(StringComparer.OrdinalIgnoreCase)
                                 .ToList();

            imageLanguages.Add("null");

            if (!string.IsNullOrEmpty(language))
            {
                // If preferred language isn't english, get those images too
                if (imageLanguages.Contains(language, StringComparer.OrdinalIgnoreCase))
                {
                    imageLanguages.Add(language);
                }

                url += string.Format("&language={0}", language);
            }

            // Get images in english and with no language
            url += "&include_image_language=" + string.Join(",", imageLanguages.ToArray());

            cancellationToken.ThrowIfCancellationRequested();

            using (var json = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions
            {
                Url = url,
                CancellationToken = cancellationToken,
                AcceptHeader = MovieDbProvider.AcceptHeader
            }).ConfigureAwait(false))
            {
                return(_jsonSerializer.DeserializeFromStream <RootObject>(json));
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>System.Object.</returns>
        public object Get(GetCultures request)
        {
            var result = _localization.GetCultures().ToList();

            return(ToOptimizedResult(result));
        }
Ejemplo n.º 8
0
 public ActionResult <IEnumerable <CultureDto> > GetCultures()
 {
     return(Ok(_localization.GetCultures()));
 }
        /// <summary>
        /// Adds the external subtitles.
        /// </summary>
        /// <param name="video">The video.</param>
        private void AddExternalSubtitles(Video video)
        {
            var useParent = !video.ResolveArgs.IsDirectory;

            if (useParent && video.Parent == null)
            {
                return;
            }

            var fileSystemChildren = useParent
                                         ? video.Parent.ResolveArgs.FileSystemChildren
                                         : video.ResolveArgs.FileSystemChildren;

            var startIndex = video.MediaStreams == null ? 0 : video.MediaStreams.Count;
            var streams    = new List <MediaStream>();

            var videoFileNameWithoutExtension = Path.GetFileNameWithoutExtension(video.Path);

            foreach (var file in fileSystemChildren
                     .Where(f => !f.Attributes.HasFlag(FileAttributes.Directory) && string.Equals(Path.GetExtension(f.FullName), ".srt", StringComparison.OrdinalIgnoreCase)))
            {
                var fullName = file.FullName;

                var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fullName);

                // If the subtitle file matches the video file name
                if (string.Equals(videoFileNameWithoutExtension, fileNameWithoutExtension, StringComparison.OrdinalIgnoreCase))
                {
                    streams.Add(new MediaStream
                    {
                        Index      = startIndex++,
                        Type       = MediaStreamType.Subtitle,
                        IsExternal = true,
                        Path       = fullName,
                        Codec      = "srt"
                    });
                }
                else if (fileNameWithoutExtension.StartsWith(videoFileNameWithoutExtension + ".", StringComparison.OrdinalIgnoreCase))
                {
                    // Support xbmc naming conventions - 300.spanish.srt
                    var language = fileNameWithoutExtension.Split('.').LastOrDefault();

                    // Try to translate to three character code
                    // Be flexible and check against both the full and three character versions
                    var culture = _localization.GetCultures()
                                  .FirstOrDefault(i => string.Equals(i.DisplayName, language, StringComparison.OrdinalIgnoreCase) || string.Equals(i.Name, language, StringComparison.OrdinalIgnoreCase) || string.Equals(i.ThreeLetterISOLanguageName, language, StringComparison.OrdinalIgnoreCase) || string.Equals(i.TwoLetterISOLanguageName, language, StringComparison.OrdinalIgnoreCase));

                    if (culture != null)
                    {
                        language = culture.ThreeLetterISOLanguageName;
                    }

                    streams.Add(new MediaStream
                    {
                        Index      = startIndex++,
                        Type       = MediaStreamType.Subtitle,
                        IsExternal = true,
                        Path       = fullName,
                        Codec      = "srt",
                        Language   = language
                    });
                }
            }

            if (video.MediaStreams == null)
            {
                video.MediaStreams = new List <MediaStream>();
            }
            video.MediaStreams.AddRange(streams);
        }
Ejemplo n.º 10
0
        private void GetExternalSubtitleStreams(List <MediaStream> streams, string folder,
                                                string videoPath,
                                                int startIndex,
                                                IDirectoryService directoryService,
                                                bool clearCache)
        {
            var videoFileNameWithoutExtension = _fileSystem.GetFileNameWithoutExtension(videoPath);

            videoFileNameWithoutExtension = NormalizeFilenameForSubtitleComparison(videoFileNameWithoutExtension);

            var files = directoryService.GetFilePaths(folder, clearCache).OrderBy(i => i).ToArray();

            foreach (var fullName in files)
            {
                var extension = Path.GetExtension(fullName);

                if (!SubtitleExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase))
                {
                    continue;
                }

                var fileNameWithoutExtension = _fileSystem.GetFileNameWithoutExtension(fullName);
                fileNameWithoutExtension = NormalizeFilenameForSubtitleComparison(fileNameWithoutExtension);

                if (!string.Equals(videoFileNameWithoutExtension, fileNameWithoutExtension, StringComparison.OrdinalIgnoreCase) &&
                    !fileNameWithoutExtension.StartsWith(videoFileNameWithoutExtension + ".", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                var codec = Path.GetExtension(fullName).ToLower().TrimStart('.');

                if (string.Equals(codec, "txt", StringComparison.OrdinalIgnoreCase))
                {
                    codec = "srt";
                }

                // If the subtitle file matches the video file name
                if (string.Equals(videoFileNameWithoutExtension, fileNameWithoutExtension, StringComparison.OrdinalIgnoreCase))
                {
                    streams.Add(new MediaStream
                    {
                        Index      = startIndex++,
                        Type       = MediaStreamType.Subtitle,
                        IsExternal = true,
                        Path       = fullName,
                        Codec      = codec
                    });
                }
                else if (fileNameWithoutExtension.StartsWith(videoFileNameWithoutExtension + ".", StringComparison.OrdinalIgnoreCase))
                {
                    var isForced = fullName.IndexOf(".forced.", StringComparison.OrdinalIgnoreCase) != -1 ||
                                   fullName.IndexOf(".foreign.", StringComparison.OrdinalIgnoreCase) != -1;

                    var isDefault = fullName.IndexOf(".default.", StringComparison.OrdinalIgnoreCase) != -1;

                    // Support xbmc naming conventions - 300.spanish.srt
                    var language = fileNameWithoutExtension
                                   .Replace(".forced", string.Empty, StringComparison.OrdinalIgnoreCase)
                                   .Replace(".foreign", string.Empty, StringComparison.OrdinalIgnoreCase)
                                   .Replace(".default", string.Empty, StringComparison.OrdinalIgnoreCase)
                                   .Split('.')
                                   .LastOrDefault();

                    // Try to translate to three character code
                    // Be flexible and check against both the full and three character versions
                    var culture = _localization.GetCultures()
                                  .FirstOrDefault(i => string.Equals(i.DisplayName, language, StringComparison.OrdinalIgnoreCase) ||
                                                  string.Equals(i.Name, language, StringComparison.OrdinalIgnoreCase) ||
                                                  string.Equals(i.ThreeLetterISOLanguageName, language, StringComparison.OrdinalIgnoreCase) ||
                                                  string.Equals(i.TwoLetterISOLanguageName, language, StringComparison.OrdinalIgnoreCase));

                    if (culture != null)
                    {
                        language = culture.ThreeLetterISOLanguageName;
                    }

                    streams.Add(new MediaStream
                    {
                        Index      = startIndex++,
                        Type       = MediaStreamType.Subtitle,
                        IsExternal = true,
                        Path       = fullName,
                        Codec      = codec,
                        Language   = language,
                        IsForced   = isForced,
                        IsDefault  = isDefault
                    });
                }
            }
        }
Ejemplo n.º 11
0
        public IEnumerable <MediaStream> GetExternalSubtitleStreams(Video video,
                                                                    int startIndex,
                                                                    IDirectoryService directoryService,
                                                                    bool clearCache)
        {
            var files = GetSubtitleFiles(video, directoryService, _fileSystem, clearCache);

            var streams = new List <MediaStream>();

            var videoFileNameWithoutExtension = _fileSystem.GetFileNameWithoutExtension(video.Path);

            foreach (var file in files)
            {
                var fullName = file.FullName;

                var fileNameWithoutExtension = _fileSystem.GetFileNameWithoutExtension(file);

                var codec = Path.GetExtension(fullName).ToLower().TrimStart('.');

                // If the subtitle file matches the video file name
                if (string.Equals(videoFileNameWithoutExtension, fileNameWithoutExtension, StringComparison.OrdinalIgnoreCase))
                {
                    streams.Add(new MediaStream
                    {
                        Index      = startIndex++,
                        Type       = MediaStreamType.Subtitle,
                        IsExternal = true,
                        Path       = fullName,
                        Codec      = codec
                    });
                }
                else if (fileNameWithoutExtension.StartsWith(videoFileNameWithoutExtension + ".", StringComparison.OrdinalIgnoreCase))
                {
                    var isForced = fullName.IndexOf(".forced.", StringComparison.OrdinalIgnoreCase) != -1 ||
                                   fullName.IndexOf(".foreign.", StringComparison.OrdinalIgnoreCase) != -1;

                    // Support xbmc naming conventions - 300.spanish.srt
                    var language = fileNameWithoutExtension
                                   .Replace(".forced", string.Empty, StringComparison.OrdinalIgnoreCase)
                                   .Replace(".foreign", string.Empty, StringComparison.OrdinalIgnoreCase)
                                   .Split('.')
                                   .LastOrDefault();

                    // Try to translate to three character code
                    // Be flexible and check against both the full and three character versions
                    var culture = _localization.GetCultures()
                                  .FirstOrDefault(i => string.Equals(i.DisplayName, language, StringComparison.OrdinalIgnoreCase) || string.Equals(i.Name, language, StringComparison.OrdinalIgnoreCase) || string.Equals(i.ThreeLetterISOLanguageName, language, StringComparison.OrdinalIgnoreCase) || string.Equals(i.TwoLetterISOLanguageName, language, StringComparison.OrdinalIgnoreCase));

                    if (culture != null)
                    {
                        language = culture.ThreeLetterISOLanguageName;
                    }

                    streams.Add(new MediaStream
                    {
                        Index      = startIndex++,
                        Type       = MediaStreamType.Subtitle,
                        IsExternal = true,
                        Path       = fullName,
                        Codec      = codec,
                        Language   = language,
                        IsForced   = isForced
                    });
                }
            }

            return(streams);
        }
        /// <summary>
        /// Fetches the main result.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="language">The language.</param>
        /// <param name="cancellationToken">The cancellation token</param>
        /// <returns>Task{CompleteMovieData}.</returns>
        internal async Task <CompleteMovieData> FetchMainResult(string id, string language, CancellationToken cancellationToken)
        {
            var url = string.Format(GetMovieInfo3, id, ApiKey);

            var imageLanguages = _localization.GetCultures()
                                 .Select(i => i.TwoLetterISOLanguageName)
                                 .Distinct(StringComparer.OrdinalIgnoreCase)
                                 .ToList();

            imageLanguages.Add("null");

            if (!string.IsNullOrEmpty(language))
            {
                // If preferred language isn't english, get those images too
                if (!imageLanguages.Contains(language, StringComparer.OrdinalIgnoreCase))
                {
                    imageLanguages.Add(language);
                }

                url += string.Format("&language={0}", language);
            }

            var includeImageLanguageParam = string.Join(",", imageLanguages.ToArray());

            // Get images in english and with no language
            url += "&include_image_language=" + includeImageLanguageParam;

            CompleteMovieData mainResult;

            cancellationToken.ThrowIfCancellationRequested();

            using (var json = await GetMovieDbResponse(new HttpRequestOptions
            {
                Url = url,
                CancellationToken = cancellationToken,
                AcceptHeader = AcceptHeader
            }).ConfigureAwait(false))
            {
                mainResult = _jsonSerializer.DeserializeFromStream <CompleteMovieData>(json);
            }

            cancellationToken.ThrowIfCancellationRequested();

            if (mainResult != null && string.IsNullOrEmpty(mainResult.overview))
            {
                if (!string.IsNullOrEmpty(language) && !string.Equals(language, "en", StringComparison.OrdinalIgnoreCase))
                {
                    _logger.Info("MovieDbProvider couldn't find meta for language " + language + ". Trying English...");

                    url = string.Format(GetMovieInfo3, id, ApiKey) + "&include_image_language=" + includeImageLanguageParam + "&language=en";

                    using (var json = await GetMovieDbResponse(new HttpRequestOptions
                    {
                        Url = url,
                        CancellationToken = cancellationToken,
                        AcceptHeader = AcceptHeader
                    }).ConfigureAwait(false))
                    {
                        mainResult = _jsonSerializer.DeserializeFromStream <CompleteMovieData>(json);
                    }
                }
            }

            return(mainResult);
        }
Ejemplo n.º 13
0
        public async Task <RemoteSubtitleInfo[]> SearchSubtitles(SubtitleSearchRequest request, CancellationToken cancellationToken)
        {
            var cultures = _localization.GetCultures();

            foreach (var culture in cultures)
            {
                if (string.Equals(culture.ThreeLetterISOLanguageName, request.Language, StringComparison.OrdinalIgnoreCase))
                {
                    request.TwoLetterISOLanguageName = culture.TwoLetterISOLanguageName;
                    break;
                }
            }

            var contentType = request.ContentType;
            var providers   = _subtitleProviders
                              .Where(i => i.SupportedMediaTypes.Contains(contentType))
                              .ToArray();

            // If not searching all, search one at a time until something is found
            if (!request.SearchAllProviders)
            {
                foreach (var provider in providers)
                {
                    try
                    {
                        var searchResults = await provider.Search(request, cancellationToken).ConfigureAwait(false);

                        var list = searchResults.ToArray();

                        if (list.Length > 0)
                        {
                            Normalize(list);
                            return(list);
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.ErrorException("Error downloading subtitles from {0}", ex, provider.Name);
                    }
                }
                return(new RemoteSubtitleInfo[] { });
            }

            var tasks = providers.Select(async i =>
            {
                try
                {
                    var searchResults = await i.Search(request, cancellationToken).ConfigureAwait(false);

                    var list = searchResults.ToArray();
                    Normalize(list);
                    return(list);
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("Error downloading subtitles from {0}", ex, i.Name);
                    return(new RemoteSubtitleInfo[] { });
                }
            });

            var results = await Task.WhenAll(tasks).ConfigureAwait(false);

            return(results.SelectMany(i => i).ToArray());
        }