mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
pool tuners
This commit is contained in:
parent
615d1e2a53
commit
e5aea2b622
@ -21,17 +21,15 @@ namespace MediaBrowser.Controller.LiveTv
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the channels.
|
/// Gets the channels.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="info">The information.</param>
|
|
||||||
/// <param name="cancellationToken">The cancellation token.</param>
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
/// <returns>Task<IEnumerable<ChannelInfo>>.</returns>
|
/// <returns>Task<IEnumerable<ChannelInfo>>.</returns>
|
||||||
Task<IEnumerable<ChannelInfo>> GetChannels(TunerHostInfo info, CancellationToken cancellationToken);
|
Task<IEnumerable<ChannelInfo>> GetChannels(CancellationToken cancellationToken);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the tuner infos.
|
/// Gets the tuner infos.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="info">The information.</param>
|
|
||||||
/// <param name="cancellationToken">The cancellation token.</param>
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
/// <returns>Task<List<LiveTvTunerInfo>>.</returns>
|
/// <returns>Task<List<LiveTvTunerInfo>>.</returns>
|
||||||
Task<List<LiveTvTunerInfo>> GetTunerInfos(TunerHostInfo info, CancellationToken cancellationToken);
|
Task<List<LiveTvTunerInfo>> GetTunerInfos(CancellationToken cancellationToken);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the channel stream.
|
/// Gets the channel stream.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -185,18 +185,25 @@ namespace MediaBrowser.Providers.Movies
|
|||||||
//release date and certification are retrieved based on configured country and we fall back on US if not there and to minimun release date if still no match
|
//release date and certification are retrieved based on configured country and we fall back on US if not there and to minimun release date if still no match
|
||||||
if (movieData.releases != null && movieData.releases.countries != null)
|
if (movieData.releases != null && movieData.releases.countries != null)
|
||||||
{
|
{
|
||||||
var ourRelease = movieData.releases.countries.FirstOrDefault(c => c.iso_3166_1.Equals(preferredCountryCode, StringComparison.OrdinalIgnoreCase)) ?? new MovieDbProvider.Country();
|
var releases = movieData.releases.countries.Where(i => !string.IsNullOrWhiteSpace(i.certification)).ToList();
|
||||||
var usRelease = movieData.releases.countries.FirstOrDefault(c => c.iso_3166_1.Equals("US", StringComparison.OrdinalIgnoreCase)) ?? new MovieDbProvider.Country();
|
|
||||||
var minimunRelease = movieData.releases.countries.OrderBy(c => c.release_date).FirstOrDefault() ?? new MovieDbProvider.Country();
|
|
||||||
|
|
||||||
var ratingPrefix = string.Equals(preferredCountryCode, "us", StringComparison.OrdinalIgnoreCase) ? "" : preferredCountryCode + "-";
|
var ourRelease = releases.FirstOrDefault(c => c.iso_3166_1.Equals(preferredCountryCode, StringComparison.OrdinalIgnoreCase));
|
||||||
movie.OfficialRating = !string.IsNullOrEmpty(ourRelease.certification)
|
var usRelease = releases.FirstOrDefault(c => c.iso_3166_1.Equals("US", StringComparison.OrdinalIgnoreCase));
|
||||||
? ratingPrefix + ourRelease.certification
|
var minimunRelease = releases.OrderBy(c => c.release_date).FirstOrDefault();
|
||||||
: !string.IsNullOrEmpty(usRelease.certification)
|
|
||||||
? usRelease.certification
|
if (ourRelease != null)
|
||||||
: !string.IsNullOrEmpty(minimunRelease.certification)
|
{
|
||||||
? minimunRelease.iso_3166_1 + "-" + minimunRelease.certification
|
var ratingPrefix = string.Equals(preferredCountryCode, "us", StringComparison.OrdinalIgnoreCase) ? "" : preferredCountryCode + "-";
|
||||||
: null;
|
movie.OfficialRating = ratingPrefix + ourRelease.certification;
|
||||||
|
}
|
||||||
|
else if (usRelease != null)
|
||||||
|
{
|
||||||
|
movie.OfficialRating = usRelease.certification;
|
||||||
|
}
|
||||||
|
else if (minimunRelease != null)
|
||||||
|
{
|
||||||
|
movie.OfficialRating = minimunRelease.iso_3166_1 + "-" + minimunRelease.certification;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(movieData.release_date))
|
if (!string.IsNullOrWhiteSpace(movieData.release_date))
|
||||||
@ -232,7 +239,7 @@ namespace MediaBrowser.Providers.Movies
|
|||||||
}
|
}
|
||||||
|
|
||||||
resultItem.ResetPeople();
|
resultItem.ResetPeople();
|
||||||
|
|
||||||
//Actors, Directors, Writers - all in People
|
//Actors, Directors, Writers - all in People
|
||||||
//actors come from cast
|
//actors come from cast
|
||||||
if (movieData.casts != null && movieData.casts.cast != null)
|
if (movieData.casts != null && movieData.casts.cast != null)
|
||||||
|
@ -172,7 +172,7 @@ namespace MediaBrowser.Providers.Omdb
|
|||||||
result.Item.SetProviderId(MetadataProviders.Imdb, imdbId);
|
result.Item.SetProviderId(MetadataProviders.Imdb, imdbId);
|
||||||
result.HasMetadata = true;
|
result.HasMetadata = true;
|
||||||
|
|
||||||
await new OmdbProvider(_jsonSerializer, _httpClient).Fetch(result.Item, imdbId, info.MetadataLanguage, cancellationToken).ConfigureAwait(false);
|
await new OmdbProvider(_jsonSerializer, _httpClient).Fetch(result.Item, imdbId, info.MetadataLanguage, info.MetadataCountryCode, cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -211,7 +211,7 @@ namespace MediaBrowser.Providers.Omdb
|
|||||||
result.Item.SetProviderId(MetadataProviders.Imdb, imdbId);
|
result.Item.SetProviderId(MetadataProviders.Imdb, imdbId);
|
||||||
result.HasMetadata = true;
|
result.HasMetadata = true;
|
||||||
|
|
||||||
await new OmdbProvider(_jsonSerializer, _httpClient).Fetch(result.Item, imdbId, info.MetadataLanguage, cancellationToken).ConfigureAwait(false);
|
await new OmdbProvider(_jsonSerializer, _httpClient).Fetch(result.Item, imdbId, info.MetadataLanguage, info.MetadataCountryCode, cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -28,7 +28,7 @@ namespace MediaBrowser.Providers.Omdb
|
|||||||
Current = this;
|
Current = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Fetch(BaseItem item, string imdbId, string language, CancellationToken cancellationToken)
|
public async Task Fetch(BaseItem item, string imdbId, string language, string country, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(imdbId))
|
if (string.IsNullOrWhiteSpace(imdbId))
|
||||||
{
|
{
|
||||||
@ -55,7 +55,11 @@ namespace MediaBrowser.Providers.Omdb
|
|||||||
if (string.Equals(language, "en", StringComparison.OrdinalIgnoreCase))
|
if (string.Equals(language, "en", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
item.Name = result.Title;
|
item.Name = result.Title;
|
||||||
item.OfficialRating = result.Rated;
|
|
||||||
|
if (string.Equals(country, "us", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
item.OfficialRating = result.Rated;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int year;
|
int year;
|
||||||
|
@ -88,11 +88,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
|
|||||||
var status = new LiveTvServiceStatusInfo();
|
var status = new LiveTvServiceStatusInfo();
|
||||||
var list = new List<LiveTvTunerInfo>();
|
var list = new List<LiveTvTunerInfo>();
|
||||||
|
|
||||||
foreach (var hostInstance in GetTunerHosts())
|
foreach (var hostInstance in _liveTvManager.TunerHosts)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var tuners = await hostInstance.Item1.GetTunerInfos(hostInstance.Item2, cancellationToken).ConfigureAwait(false);
|
var tuners = await hostInstance.GetTunerInfos(cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
list.AddRange(tuners);
|
list.AddRange(tuners);
|
||||||
}
|
}
|
||||||
@ -120,11 +120,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
|
|||||||
|
|
||||||
var list = new List<ChannelInfo>();
|
var list = new List<ChannelInfo>();
|
||||||
|
|
||||||
foreach (var hostInstance in GetTunerHosts())
|
foreach (var hostInstance in _liveTvManager.TunerHosts)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var channels = await hostInstance.Item1.GetChannels(hostInstance.Item2, cancellationToken).ConfigureAwait(false);
|
var channels = await hostInstance.GetChannels(cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
list.AddRange(channels);
|
list.AddRange(channels);
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,46 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|||||||
|
|
||||||
private const string ChannelIdPrefix = "hdhr_";
|
private const string ChannelIdPrefix = "hdhr_";
|
||||||
|
|
||||||
public async Task<IEnumerable<ChannelInfo>> GetChannels(TunerHostInfo info, CancellationToken cancellationToken)
|
private List<TunerHostInfo> GetTunerHosts()
|
||||||
|
{
|
||||||
|
return GetConfiguration().TunerHosts
|
||||||
|
.Where(i => i.IsEnabled && string.Equals(i.Type, Type, StringComparison.OrdinalIgnoreCase))
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<ChannelInfo>> GetChannels(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var list = new List<ChannelInfo>();
|
||||||
|
|
||||||
|
var hosts = GetTunerHosts();
|
||||||
|
|
||||||
|
var ipAddresses = new List<string>();
|
||||||
|
|
||||||
|
foreach (var host in hosts)
|
||||||
|
{
|
||||||
|
var ip = GetApiUrl(host, false);
|
||||||
|
|
||||||
|
if (ipAddresses.Contains(ip, StringComparer.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
list.AddRange(await GetChannels(host, cancellationToken).ConfigureAwait(false));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.ErrorException("Error getting channel list", ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
ipAddresses.Add(ip);
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<IEnumerable<ChannelInfo>> GetChannels(TunerHostInfo info, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var options = new HttpRequestOptions
|
var options = new HttpRequestOptions
|
||||||
{
|
{
|
||||||
@ -146,6 +185,26 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.HdHomerun
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<List<LiveTvTunerInfo>> GetTunerInfos(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var list = new List<LiveTvTunerInfo>();
|
||||||
|
|
||||||
|
foreach (var host in GetConfiguration().TunerHosts
|
||||||
|
.Where(i => i.IsEnabled && string.Equals(i.Type, Type, StringComparison.OrdinalIgnoreCase)))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
list.AddRange(await GetTunerInfos(host, cancellationToken).ConfigureAwait(false));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.ErrorException("Error getting tuner info", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
private string GetApiUrl(TunerHostInfo info, bool isPlayback)
|
private string GetApiUrl(TunerHostInfo info, bool isPlayback)
|
||||||
{
|
{
|
||||||
var url = info.Url;
|
var url = info.Url;
|
||||||
|
@ -4,6 +4,7 @@ using MediaBrowser.Controller.LiveTv;
|
|||||||
using MediaBrowser.Model.Dto;
|
using MediaBrowser.Model.Dto;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
using MediaBrowser.Model.LiveTv;
|
using MediaBrowser.Model.LiveTv;
|
||||||
|
using MediaBrowser.Model.Logging;
|
||||||
using MediaBrowser.Model.MediaInfo;
|
using MediaBrowser.Model.MediaInfo;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -27,20 +28,52 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts
|
|||||||
}
|
}
|
||||||
|
|
||||||
private readonly IConfigurationManager _config;
|
private readonly IConfigurationManager _config;
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
public M3UTunerHost(IConfigurationManager config)
|
public M3UTunerHost(IConfigurationManager config, ILogger logger)
|
||||||
{
|
{
|
||||||
_config = config;
|
_config = config;
|
||||||
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<IEnumerable<ChannelInfo>> GetChannels(TunerHostInfo info, CancellationToken cancellationToken)
|
private List<TunerHostInfo> GetTunerHosts()
|
||||||
{
|
{
|
||||||
var urlHash = info.Url.GetMD5().ToString("N");
|
return GetConfiguration().TunerHosts
|
||||||
|
.Where(i => i.IsEnabled && string.Equals(i.Type, Type, StringComparison.OrdinalIgnoreCase))
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<ChannelInfo>> GetChannels(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var list = new List<ChannelInfo>();
|
||||||
|
|
||||||
|
var urls = GetTunerHosts().Select(i => i.Url)
|
||||||
|
.Where(i => !string.IsNullOrWhiteSpace(i))
|
||||||
|
.Distinct(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
foreach (var url in urls)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
list.AddRange(await GetChannels(url, cancellationToken).ConfigureAwait(false));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.ErrorException("Error getting channel list", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Task<IEnumerable<ChannelInfo>> GetChannels(string url, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var urlHash = url.GetMD5().ToString("N");
|
||||||
|
|
||||||
int position = 0;
|
int position = 0;
|
||||||
string line;
|
string line;
|
||||||
// Read the file and display it line by line.
|
// Read the file and display it line by line.
|
||||||
var file = new StreamReader(info.Url);
|
var file = new StreamReader(url);
|
||||||
var channels = new List<M3UChannel>();
|
var channels = new List<M3UChannel>();
|
||||||
while ((line = file.ReadLine()) != null)
|
while ((line = file.ReadLine()) != null)
|
||||||
{
|
{
|
||||||
@ -105,19 +138,20 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts
|
|||||||
return Task.FromResult((IEnumerable<ChannelInfo>)channels);
|
return Task.FromResult((IEnumerable<ChannelInfo>)channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<List<LiveTvTunerInfo>> GetTunerInfos(TunerHostInfo info, CancellationToken cancellationToken)
|
public Task<List<LiveTvTunerInfo>> GetTunerInfos(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var list = new List<LiveTvTunerInfo>();
|
var list = GetConfiguration().TunerHosts
|
||||||
|
.Where(i => i.IsEnabled && string.Equals(i.Type, Type, StringComparison.OrdinalIgnoreCase))
|
||||||
list.Add(new LiveTvTunerInfo()
|
.Select(i => new LiveTvTunerInfo()
|
||||||
{
|
{
|
||||||
Name = Name,
|
Name = Name,
|
||||||
SourceType = Type,
|
SourceType = Type,
|
||||||
Status = LiveTvTunerStatus.Available,
|
Status = LiveTvTunerStatus.Available,
|
||||||
Id = info.Url.GetMD5().ToString("N"),
|
Id = i.Url.GetMD5().ToString("N"),
|
||||||
Url = info.Url
|
Url = i.Url
|
||||||
});
|
})
|
||||||
|
.ToList();
|
||||||
|
|
||||||
return Task.FromResult(list);
|
return Task.FromResult(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,7 +170,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts
|
|||||||
|
|
||||||
channelId = channelId.Substring(urlHash.Length);
|
channelId = channelId.Substring(urlHash.Length);
|
||||||
|
|
||||||
var channels = await GetChannels(info, cancellationToken).ConfigureAwait(false);
|
var channels = await GetChannels(info.Url, cancellationToken).ConfigureAwait(false);
|
||||||
var m3uchannels = channels.Cast<M3UChannel>();
|
var m3uchannels = channels.Cast<M3UChannel>();
|
||||||
var channel = m3uchannels.FirstOrDefault(c => c.Id == channelId);
|
var channel = m3uchannels.FirstOrDefault(c => c.Id == channelId);
|
||||||
if (channel != null)
|
if (channel != null)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user