public VideoVariant(long bitRate, string contentType, string url, VideoContentType recognizedContentType) { BitRate = bitRate; ContentType = contentType; Url = url; RecognizedContentType = recognizedContentType; }
public async Task <IEnumerable <RemoteSubtitleInfo> > Search(string title, int?year, string lang, VideoContentType contentType, string movieId, int season, int episode, CancellationToken cancellationToken) { _logger?.Info( $"Subf2m= Request subtitle for '{title}', language={lang}, year={year}, movie Id={movieId}, Season={season}, Episode={episode}"); List <RemoteSubtitleInfo> subtitles = null; try { switch (contentType) { case VideoContentType.Movie: var movie = new Movie(_httpClient, _logger, _jsonSerializer, _appHost, _localizationManager); subtitles = await movie.Search(title, year, lang, movieId, cancellationToken); break; case VideoContentType.Episode: var series = new Series(_httpClient, _logger, _jsonSerializer, _appHost, _localizationManager); subtitles = await series.Search(lang, movieId, season, episode, cancellationToken); break; default: throw new ApplicationException($"His plugins not support {contentType}"); } } catch (Exception e) { _logger?.Error(e.Message, e); } if (subtitles == null || !subtitles.Any()) { return(new List <RemoteSubtitleInfo>()); } subtitles.RemoveAll(l => string.IsNullOrWhiteSpace(l.Name)); return(subtitles.OrderBy(s => s.Name)); }
public async Task <IEnumerable <RemoteSubtitleInfo> > Search(string title, int?year, string lang, VideoContentType contentType, string movieId, int season, int episode) { _logger?.Info( $"Subscene= Request subtitle for '{title}', language={lang}, year={year}, movie Id={movieId}, Season={season}, Episode={episode}"); var res = new List <RemoteSubtitleInfo>(); try { res = contentType == VideoContentType.Movie ? await SearchMovie(title, year, lang, movieId) : await SearchTV(title, year, lang, movieId, season, episode); if (!res.Any()) { return(res); } } catch (Exception e) { _logger?.Error(e.Message, e); } res.RemoveAll(l => string.IsNullOrWhiteSpace(l.Name)); res = res.GroupBy(s => s.Id) .Select(s => new RemoteSubtitleInfo() { Id = s.First().Id, Name = $"{s.First().ProviderName} ({s.First().Author})", Author = s.First().Author, ProviderName = "Subscene", Comment = string.Join("<br/>", s.Select(n => n.Name)), Format = "srt" }).ToList(); return(res.OrderBy(s => s.Name)); }
private async Task<bool> DownloadSubtitles(Video video, List<MediaStream> mediaStreams, bool skipIfEmbeddedSubtitlesPresent, bool skipIfAudioTrackMatches, bool requirePerfectMatch, string language, VideoContentType mediaType, CancellationToken cancellationToken) { // There's already subtitles for this language if (mediaStreams.Any(i => i.Type == MediaStreamType.Subtitle && i.IsTextSubtitleStream && string.Equals(i.Language, language, StringComparison.OrdinalIgnoreCase))) { return false; } var audioStreams = mediaStreams.Where(i => i.Type == MediaStreamType.Audio).ToList(); var defaultAudioStreams = audioStreams.Where(i => i.IsDefault).ToList(); // If none are marked as default, just take a guess if (defaultAudioStreams.Count == 0) { defaultAudioStreams = audioStreams.Take(1).ToList(); } // There's already a default audio stream for this language if (skipIfAudioTrackMatches && defaultAudioStreams.Any(i => string.Equals(i.Language, language, StringComparison.OrdinalIgnoreCase))) { return false; } // There's an internal subtitle stream for this language if (skipIfEmbeddedSubtitlesPresent && mediaStreams.Any(i => i.Type == MediaStreamType.Subtitle && !i.IsExternal && string.Equals(i.Language, language, StringComparison.OrdinalIgnoreCase))) { return false; } var request = new SubtitleSearchRequest { ContentType = mediaType, IndexNumber = video.IndexNumber, Language = language, MediaPath = video.Path, Name = video.Name, ParentIndexNumber = video.ParentIndexNumber, ProductionYear = video.ProductionYear, ProviderIds = video.ProviderIds, // Stop as soon as we find something SearchAllProviders = false, IsPerfectMatch = requirePerfectMatch }; var episode = video as Episode; if (episode != null) { request.IndexNumberEnd = episode.IndexNumberEnd; request.SeriesName = episode.SeriesName; } try { var searchResults = await _subtitleManager.SearchSubtitles(request, cancellationToken).ConfigureAwait(false); var result = searchResults.FirstOrDefault(); if (result != null) { await _subtitleManager.DownloadSubtitles(video, result.Id, cancellationToken) .ConfigureAwait(false); return true; } } catch (Exception ex) { _logger.ErrorException("Error downloading subtitles", ex); } return false; }
private async Task <bool> DownloadSubtitles(Video video, List <MediaStream> mediaStreams, bool skipIfEmbeddedSubtitlesPresent, bool skipIfAudioTrackMatches, bool requirePerfectMatch, string language, VideoContentType mediaType, CancellationToken cancellationToken) { // There's already subtitles for this language if (mediaStreams.Any(i => i.Type == MediaStreamType.Subtitle && i.IsTextSubtitleStream && string.Equals(i.Language, language, StringComparison.OrdinalIgnoreCase))) { return(false); } var audioStreams = mediaStreams.Where(i => i.Type == MediaStreamType.Audio).ToList(); var defaultAudioStreams = audioStreams.Where(i => i.IsDefault).ToList(); // If none are marked as default, just take a guess if (defaultAudioStreams.Count == 0) { defaultAudioStreams = audioStreams.Take(1).ToList(); } // There's already a default audio stream for this language if (skipIfAudioTrackMatches && defaultAudioStreams.Any(i => string.Equals(i.Language, language, StringComparison.OrdinalIgnoreCase))) { return(false); } // There's an internal subtitle stream for this language if (skipIfEmbeddedSubtitlesPresent && mediaStreams.Any(i => i.Type == MediaStreamType.Subtitle && !i.IsExternal && string.Equals(i.Language, language, StringComparison.OrdinalIgnoreCase))) { return(false); } var request = new SubtitleSearchRequest { ContentType = mediaType, IndexNumber = video.IndexNumber, Language = language, MediaPath = video.Path, Name = video.Name, ParentIndexNumber = video.ParentIndexNumber, ProductionYear = video.ProductionYear, ProviderIds = video.ProviderIds, // Stop as soon as we find something SearchAllProviders = false, IsPerfectMatch = requirePerfectMatch }; var episode = video as Episode; if (episode != null) { request.IndexNumberEnd = episode.IndexNumberEnd; request.SeriesName = episode.SeriesName; } try { var searchResults = await _subtitleManager.SearchSubtitles(request, cancellationToken).ConfigureAwait(false); var result = searchResults.FirstOrDefault(); if (result != null) { await _subtitleManager.DownloadSubtitles(video, result.Id, cancellationToken) .ConfigureAwait(false); return(true); } } catch (RateLimitExceededException) { } catch (Exception ex) { _logger.ErrorException("Error downloading subtitles", ex); } return(false); }
public static RTCVideoContentType ToPlatformNative(this VideoContentType nativePort) => (RTCVideoContentType)nativePort;