Skip to content

Commit

Permalink
fix directory not found error in episode organization
Browse files Browse the repository at this point in the history
  • Loading branch information
LukePulverenti committed Feb 25, 2014
1 parent 130672d commit b4777dc
Show file tree
Hide file tree
Showing 25 changed files with 150 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,17 +285,8 @@ private async Task<HttpResponseInfo> SendAsync(HttpRequestOptions options, strin
EnsureSuccessStatusCode(httpResponse);

options.CancellationToken.ThrowIfCancellationRequested();

return new HttpResponseInfo
{
Content = httpResponse.GetResponseStream(),

StatusCode = httpResponse.StatusCode,

ContentType = httpResponse.ContentType,

Headers = httpResponse.Headers
};
return GetResponseInfo(httpResponse, httpResponse.GetResponseStream(), GetContentLength(httpResponse));
}

using (var response = await httpWebRequest.GetResponseAsync().ConfigureAwait(false))
Expand All @@ -314,16 +305,7 @@ private async Task<HttpResponseInfo> SendAsync(HttpRequestOptions options, strin

memoryStream.Position = 0;

return new HttpResponseInfo
{
Content = memoryStream,

StatusCode = httpResponse.StatusCode,

ContentType = httpResponse.ContentType,

Headers = httpResponse.Headers
};
return GetResponseInfo(httpResponse, memoryStream, memoryStream.Length);
}
}
}
Expand Down Expand Up @@ -367,6 +349,38 @@ private async Task<HttpResponseInfo> SendAsync(HttpRequestOptions options, strin
}
}

private HttpResponseInfo GetResponseInfo(HttpWebResponse httpResponse, Stream content, long? contentLength)
{
return new HttpResponseInfo
{
Content = content,

StatusCode = httpResponse.StatusCode,

ContentType = httpResponse.ContentType,

Headers = httpResponse.Headers,

ContentLength = contentLength
};
}

private HttpResponseInfo GetResponseInfo(HttpWebResponse httpResponse, string tempFile, long? contentLength)
{
return new HttpResponseInfo
{
TempFilePath = tempFile,

StatusCode = httpResponse.StatusCode,

ContentType = httpResponse.ContentType,

Headers = httpResponse.Headers,

ContentLength = contentLength
};
}

public Task<HttpResponseInfo> Post(HttpRequestOptions options)
{
return SendAsync(options, "POST");
Expand Down Expand Up @@ -493,16 +507,7 @@ public async Task<HttpResponseInfo> GetTempFileResponse(HttpRequestOptions optio

options.Progress.Report(100);

return new HttpResponseInfo
{
TempFilePath = tempFile,

StatusCode = httpResponse.StatusCode,

ContentType = httpResponse.ContentType,

Headers = httpResponse.Headers
};
return GetResponseInfo(httpResponse, tempFile, contentLength);
}
}
catch (OperationCanceledException ex)
Expand Down
6 changes: 6 additions & 0 deletions MediaBrowser.Common/Net/HttpResponseInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public class HttpResponseInfo
/// <value>The temp file path.</value>
public string TempFilePath { get; set; }

/// <summary>
/// Gets or sets the length of the content.
/// </summary>
/// <value>The length of the content.</value>
public long? ContentLength { get; set; }

/// <summary>
/// Gets or sets the headers.
/// </summary>
Expand Down
6 changes: 4 additions & 2 deletions MediaBrowser.Controller/Entities/Folder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ private BaseItem GetLinkedChild(LinkedChild info)
// First get using the cached Id
if (info.ItemId != Guid.Empty)
{
item = LibraryManager.GetItemById(info.ItemId) as BaseItem;
item = LibraryManager.GetItemById(info.ItemId);
}

// If still null, search by path
Expand Down Expand Up @@ -1098,7 +1098,9 @@ public BaseItem FindByPath(string path)
return this;
}

return RecursiveChildren.FirstOrDefault(i => string.Equals(i.Path, path, StringComparison.OrdinalIgnoreCase) || i.PhysicalLocations.Contains(path, StringComparer.OrdinalIgnoreCase));
return RecursiveChildren.FirstOrDefault(i => string.Equals(i.Path, path, StringComparison.OrdinalIgnoreCase) ||
(!i.IsFolder && !i.IsInMixedFolder && string.Equals(i.ContainingFolderPath, path, StringComparison.OrdinalIgnoreCase)) ||
i.PhysicalLocations.Contains(path, StringComparer.OrdinalIgnoreCase));
}

public override bool IsPlayed(User user)
Expand Down
11 changes: 10 additions & 1 deletion MediaBrowser.Controller/Entities/TV/Season.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,16 @@ public string SeriesName
/// <returns>SeasonInfo.</returns>
public SeasonInfo GetLookupInfo()
{
return GetItemLookupInfo<SeasonInfo>();
var id = GetItemLookupInfo<SeasonInfo>();

var series = Series;

if (series != null)
{
id.SeriesProviderIds = series.ProviderIds;
}

return id;
}

/// <summary>
Expand Down
16 changes: 16 additions & 0 deletions MediaBrowser.Controller/Providers/BaseItemXmlParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,22 @@ protected virtual void FetchDataFromXmlNode(XmlReader reader, T item)
}
break;
}
case "MusicbrainzId":
{
var mbz = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(mbz))
{
if (item is MusicAlbum)
{
item.SetProviderId(MetadataProviders.MusicBrainzAlbum, mbz);
}
else if (item is MusicArtist)
{
item.SetProviderId(MetadataProviders.MusicBrainzArtist, mbz);
}
}
break;
}
case "MusicBrainzAlbumId":
{
var mbz = reader.ReadElementContentAsString();
Expand Down
7 changes: 6 additions & 1 deletion MediaBrowser.Controller/Providers/ItemLookupInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ public class BookInfo : ItemLookupInfo

public class SeasonInfo : ItemLookupInfo
{

public Dictionary<string, string> SeriesProviderIds { get; set; }

public SeasonInfo()
{
SeriesProviderIds = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
}
}
}
2 changes: 1 addition & 1 deletion MediaBrowser.Providers/All/LocalImageProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ private void PopulatePrimaryImages(IHasImages item, List<LocalImageInfo> images,
AddImage(files, images, imagePrefix + "movie", ImageType.Primary);
}

if (string.IsNullOrEmpty(item.Path))
if (!string.IsNullOrEmpty(item.Path))
{
var name = Path.GetFileNameWithoutExtension(item.Path);

Expand Down
22 changes: 19 additions & 3 deletions MediaBrowser.Providers/Manager/ItemImageProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public async Task<RefreshResult> RefreshImages(IHasImages item, IEnumerable<IIma
var providerIds = new List<Guid>();

// In order to avoid duplicates, only download these if there are none already
var backdropLimit = item.HasImage(ImageType.Backdrop) ? 0 : savedOptions.GetLimit(ImageType.Backdrop);
var screenshotLimit = item.HasImage(ImageType.Screenshot) ? 0 : savedOptions.GetLimit(ImageType.Screenshot);
var backdropLimit = savedOptions.GetLimit(ImageType.Backdrop);
var screenshotLimit = savedOptions.GetLimit(ImageType.Screenshot);

foreach (var provider in providers)
{
Expand Down Expand Up @@ -362,9 +362,25 @@ private async Task DownloadBackdrops(IHasImages item, ImageType imageType, int l
{
var response = await provider.GetImageResponse(url, cancellationToken).ConfigureAwait(false);

// If there's already an image of the same size, skip it
if (response.ContentLength.HasValue)
{
try
{
if (item.GetImages(imageType).Any(i => new FileInfo(i.Path).Length == response.ContentLength.Value))
{
response.Content.Dispose();
continue;
}
}
catch (IOException ex)
{
_logger.ErrorException("Error examining images", ex);
}
}

await _providerManager.SaveImage(item, response.Content, response.ContentType, imageType, null, cancellationToken).ConfigureAwait(false);
result.UpdateType = result.UpdateType | ItemUpdateType.ImageUpdate;
break;
}
catch (HttpException ex)
{
Expand Down
3 changes: 3 additions & 0 deletions MediaBrowser.Providers/MediaBrowser.Providers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="..\SharedVersion.cs">
<Link>Properties\SharedVersion.cs</Link>
</Compile>
<Compile Include="AdultVideos\AdultVideoMetadataService.cs" />
<Compile Include="AdultVideos\AdultVideoXmlProvider.cs" />
<Compile Include="All\InternalMetadataFolderImageProvider.cs" />
Expand Down
4 changes: 2 additions & 2 deletions MediaBrowser.Providers/Movies/FanartMovieImageProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken can
{
CancellationToken = cancellationToken,
Url = url,
ResourcePool = FanartArtistProvider.FanArtResourcePool
ResourcePool = FanartArtistProvider.Current.FanArtResourcePool
});
}

Expand Down Expand Up @@ -410,7 +410,7 @@ internal async Task DownloadMovieXml(string tmdbId, CancellationToken cancellati
using (var response = await _httpClient.Get(new HttpRequestOptions
{
Url = url,
ResourcePool = FanartArtistProvider.FanArtResourcePool,
ResourcePool = FanartArtistProvider.Current.FanArtResourcePool,
CancellationToken = cancellationToken

}).ConfigureAwait(false))
Expand Down
2 changes: 1 addition & 1 deletion MediaBrowser.Providers/Music/FanArtAlbumProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken can
{
CancellationToken = cancellationToken,
Url = url,
ResourcePool = FanartArtistProvider.FanArtResourcePool
ResourcePool = FanartArtistProvider.Current.FanArtResourcePool
});
}

Expand Down
2 changes: 1 addition & 1 deletion MediaBrowser.Providers/Music/FanArtArtistProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace MediaBrowser.Providers.Music
{
public class FanartArtistProvider : IRemoteImageProvider, IHasChangeMonitor, IHasOrder
{
internal static readonly SemaphoreSlim FanArtResourcePool = new SemaphoreSlim(3, 3);
internal readonly SemaphoreSlim FanArtResourcePool = new SemaphoreSlim(3, 3);
internal const string ApiKey = "5c6b04c68e904cfed1e6cbc9a9e683d4";
private const string FanArtBaseUrl = "http://api.fanart.tv/webservice/artist/{0}/{1}/xml/all/1/1";

Expand Down
2 changes: 1 addition & 1 deletion MediaBrowser.Providers/Music/FanArtUpdatesPostScanTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private async Task<IEnumerable<string>> GetArtistIdsToUpdate(IEnumerable<string>
Url = string.Format(UpdatesUrl, FanartArtistProvider.ApiKey, lastUpdateTime),
CancellationToken = cancellationToken,
EnableHttpCompression = true,
ResourcePool = FanartArtistProvider.FanArtResourcePool
ResourcePool = FanartArtistProvider.Current.FanArtResourcePool

}).ConfigureAwait(false))
{
Expand Down
2 changes: 1 addition & 1 deletion MediaBrowser.Providers/Music/MusicExternalIds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public string UrlFormatString

public bool Supports(IHasProviderIds item)
{
return item is Audio || item is MusicAlbum;
return item is Audio;
}
}

Expand Down
2 changes: 1 addition & 1 deletion MediaBrowser.Providers/Omdb/OmdbProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace MediaBrowser.Providers.Omdb
{
public class OmdbProvider
{
internal readonly SemaphoreSlim ResourcePool = new SemaphoreSlim(1, 1);
private static readonly SemaphoreSlim ResourcePool = new SemaphoreSlim(1, 1);
private readonly IJsonSerializer _jsonSerializer;
private readonly IHttpClient _httpClient;
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
Expand Down
7 changes: 1 addition & 6 deletions MediaBrowser.Providers/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,4 @@
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
//
4 changes: 4 additions & 0 deletions MediaBrowser.Providers/Savers/XmlSaverHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public static class XmlSaverHelpers
"MusicBrainzAlbumArtistId",
"MusicBrainzAlbumId",
"MusicBrainzReleaseGroupId",

// Old - not used anymore
"MusicbrainzId",

"Overview",
"Persons",
"PlotKeywords",
Expand Down
2 changes: 1 addition & 1 deletion MediaBrowser.Providers/TV/FanArtSeasonProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken can
{
CancellationToken = cancellationToken,
Url = url,
ResourcePool = FanartArtistProvider.FanArtResourcePool
ResourcePool = FanartArtistProvider.Current.FanArtResourcePool
});
}

Expand Down
2 changes: 1 addition & 1 deletion MediaBrowser.Providers/TV/FanArtTvUpdatesPostScanTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private async Task<IEnumerable<string>> GetSeriesIdsToUpdate(IEnumerable<string>
Url = string.Format(UpdatesUrl, FanartArtistProvider.ApiKey, lastUpdateTime),
CancellationToken = cancellationToken,
EnableHttpCompression = true,
ResourcePool = FanartArtistProvider.FanArtResourcePool
ResourcePool = FanartArtistProvider.Current.FanArtResourcePool

}).ConfigureAwait(false))
{
Expand Down
4 changes: 2 additions & 2 deletions MediaBrowser.Providers/TV/FanartSeriesProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken can
{
CancellationToken = cancellationToken,
Url = url,
ResourcePool = FanartArtistProvider.FanArtResourcePool
ResourcePool = FanartArtistProvider.Current.FanArtResourcePool
});
}

Expand Down Expand Up @@ -414,7 +414,7 @@ internal async Task DownloadSeriesXml(string tvdbId, CancellationToken cancellat
using (var response = await _httpClient.Get(new HttpRequestOptions
{
Url = url,
ResourcePool = FanartArtistProvider.FanArtResourcePool,
ResourcePool = FanartArtistProvider.Current.FanArtResourcePool,
CancellationToken = cancellationToken

}).ConfigureAwait(false))
Expand Down
8 changes: 5 additions & 3 deletions MediaBrowser.Providers/TV/TvdbSeriesProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,23 +175,25 @@ internal Task EnsureSeriesInfo(string seriesId, string preferredMetadataLanguage
var download = false;
var automaticUpdatesEnabled = _config.Configuration.EnableTvDbUpdates;

const int cacheDays = 3;

var seriesFile = files.FirstOrDefault(i => string.Equals(seriesXmlFilename, i.Name, StringComparison.OrdinalIgnoreCase));
// No need to check age if automatic updates are enabled
if (seriesFile == null || !seriesFile.Exists || (!automaticUpdatesEnabled && (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(seriesFile)).TotalDays > 7))
if (seriesFile == null || !seriesFile.Exists || (!automaticUpdatesEnabled && (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(seriesFile)).TotalDays > cacheDays))
{
download = true;
}

var actorsXml = files.FirstOrDefault(i => string.Equals("actors.xml", i.Name, StringComparison.OrdinalIgnoreCase));
// No need to check age if automatic updates are enabled
if (actorsXml == null || !actorsXml.Exists || (!automaticUpdatesEnabled && (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(actorsXml)).TotalDays > 7))
if (actorsXml == null || !actorsXml.Exists || (!automaticUpdatesEnabled && (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(actorsXml)).TotalDays > cacheDays))
{
download = true;
}

var bannersXml = files.FirstOrDefault(i => string.Equals("banners.xml", i.Name, StringComparison.OrdinalIgnoreCase));
// No need to check age if automatic updates are enabled
if (bannersXml == null || !bannersXml.Exists || (!automaticUpdatesEnabled && (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(bannersXml)).TotalDays > 7))
if (bannersXml == null || !bannersXml.Exists || (!automaticUpdatesEnabled && (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(bannersXml)).TotalDays > cacheDays))
{
download = true;
}
Expand Down
Loading

0 comments on commit b4777dc

Please sign in to comment.