update live tv setup

This commit is contained in:
Luke Pulverenti
2015-07-23 01:25:55 -04:00
parent cf27ac47a8
commit 7300a475d1
11 changed files with 923 additions and 109 deletions

View File

@@ -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)