mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-03-17 23:56:44 +00:00
update live tv setup
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
using MediaBrowser.Common.IO;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Common.Progress;
|
||||
using MediaBrowser.Common.ScheduledTasks;
|
||||
using MediaBrowser.Common.Security;
|
||||
using MediaBrowser.Controller.Channels;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
@@ -29,22 +27,18 @@ namespace MediaBrowser.Server.Implementations.Channels
|
||||
private readonly IChannelManager _manager;
|
||||
private readonly IServerConfigurationManager _config;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IHttpClient _httpClient;
|
||||
private readonly IFileSystem _fileSystem;
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
private readonly IUserManager _userManager;
|
||||
private readonly ISecurityManager _security;
|
||||
|
||||
public ChannelDownloadScheduledTask(IChannelManager manager, IServerConfigurationManager config, ILogger logger, IHttpClient httpClient, IFileSystem fileSystem, ILibraryManager libraryManager, IUserManager userManager, ISecurityManager security)
|
||||
public ChannelDownloadScheduledTask(IChannelManager manager, IServerConfigurationManager config, ILogger logger, IFileSystem fileSystem, ILibraryManager libraryManager, IUserManager userManager)
|
||||
{
|
||||
_manager = manager;
|
||||
_config = config;
|
||||
_logger = logger;
|
||||
_httpClient = httpClient;
|
||||
_fileSystem = fileSystem;
|
||||
_libraryManager = libraryManager;
|
||||
_userManager = userManager;
|
||||
_security = security;
|
||||
}
|
||||
|
||||
public string Name
|
||||
|
||||
@@ -23,7 +23,6 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -255,7 +254,7 @@ namespace MediaBrowser.Server.Implementations.Channels
|
||||
sources.InsertRange(0, cachedVersions);
|
||||
}
|
||||
|
||||
return sources.Where(IsValidMediaSource);
|
||||
return sources;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<MediaSourceInfo>> GetDynamicMediaSources(IChannelMediaItem item, CancellationToken cancellationToken)
|
||||
@@ -279,7 +278,6 @@ namespace MediaBrowser.Server.Implementations.Channels
|
||||
|
||||
var list = SortMediaInfoResults(results)
|
||||
.Select(i => GetMediaSource(item, i))
|
||||
.Where(IsValidMediaSource)
|
||||
.ToList();
|
||||
|
||||
var cachedVersions = GetCachedChannelItemMediaSources(item);
|
||||
@@ -1424,18 +1422,8 @@ namespace MediaBrowser.Server.Implementations.Channels
|
||||
|
||||
foreach (var source in list)
|
||||
{
|
||||
try
|
||||
{
|
||||
await TryDownloadChannelItem(source, item, destination, progress, cancellationToken).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
catch (HttpException ex)
|
||||
{
|
||||
if (ex.StatusCode.HasValue && ex.StatusCode.Value == HttpStatusCode.NotFound)
|
||||
{
|
||||
MarkBadMediaSource(source);
|
||||
}
|
||||
}
|
||||
await TryDownloadChannelItem(source, item, destination, progress, cancellationToken).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1525,81 +1513,6 @@ namespace MediaBrowser.Server.Implementations.Channels
|
||||
}
|
||||
}
|
||||
|
||||
private readonly ReaderWriterLockSlim _mediaSourceHistoryLock = new ReaderWriterLockSlim();
|
||||
private bool IsValidMediaSource(MediaSourceInfo source)
|
||||
{
|
||||
if (source.Protocol == MediaProtocol.Http)
|
||||
{
|
||||
return !GetBadMediaSourceHistory().Contains(source.Path, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void MarkBadMediaSource(MediaSourceInfo source)
|
||||
{
|
||||
var list = GetBadMediaSourceHistory();
|
||||
list.Add(source.Path);
|
||||
|
||||
var path = GetMediaSourceHistoryPath();
|
||||
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
||||
|
||||
if (_mediaSourceHistoryLock.TryEnterWriteLock(TimeSpan.FromSeconds(5)))
|
||||
{
|
||||
try
|
||||
{
|
||||
File.WriteAllLines(path, list.ToArray(), Encoding.UTF8);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error saving file", ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_mediaSourceHistoryLock.ExitWriteLock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ConcurrentBag<string> _badMediaSources = null;
|
||||
private ConcurrentBag<string> GetBadMediaSourceHistory()
|
||||
{
|
||||
if (_badMediaSources == null)
|
||||
{
|
||||
var path = GetMediaSourceHistoryPath();
|
||||
|
||||
if (_mediaSourceHistoryLock.TryEnterReadLock(TimeSpan.FromSeconds(1)))
|
||||
{
|
||||
if (_badMediaSources == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
_badMediaSources = new ConcurrentBag<string>(File.ReadAllLines(path, Encoding.UTF8));
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
_badMediaSources = new ConcurrentBag<string>();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error reading file", ex);
|
||||
_badMediaSources = new ConcurrentBag<string>();
|
||||
}
|
||||
finally
|
||||
{
|
||||
_mediaSourceHistoryLock.ExitReadLock();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return _badMediaSources;
|
||||
}
|
||||
|
||||
private string GetMediaSourceHistoryPath()
|
||||
{
|
||||
return Path.Combine(_config.ApplicationPaths.DataPath, "channels", "failures.txt");
|
||||
}
|
||||
|
||||
private void IncrementDownloadCount(string key, int? limit)
|
||||
{
|
||||
if (!limit.HasValue)
|
||||
|
||||
Reference in New Issue
Block a user