diff options
| author | LukePulverenti <luke.pulverenti@gmail.com> | 2013-02-22 01:28:57 -0500 |
|---|---|---|
| committer | LukePulverenti <luke.pulverenti@gmail.com> | 2013-02-22 01:28:57 -0500 |
| commit | 746c5d2fa7cd14f648c72a87ce52e5096c1f03f1 (patch) | |
| tree | c2e9dbac2110c8c881ff82af01572b796c931c6f /MediaBrowser.Plugins.Trailers | |
| parent | 868a7ce9c8b50bd64c8b5ae33fec77abfd25ef7c (diff) | |
moved Plugins to separate repo
Diffstat (limited to 'MediaBrowser.Plugins.Trailers')
12 files changed, 0 insertions, 1353 deletions
diff --git a/MediaBrowser.Plugins.Trailers/AppleTrailerListingDownloader.cs b/MediaBrowser.Plugins.Trailers/AppleTrailerListingDownloader.cs deleted file mode 100644 index 76d7569b9f..0000000000 --- a/MediaBrowser.Plugins.Trailers/AppleTrailerListingDownloader.cs +++ /dev/null @@ -1,314 +0,0 @@ -using MediaBrowser.Common.Extensions; -using MediaBrowser.Controller; -using MediaBrowser.Controller.Entities; -using MediaBrowser.Controller.Extensions; -using MediaBrowser.Model.Entities; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Threading; -using System.Threading.Tasks; -using System.Xml; - -namespace MediaBrowser.Plugins.Trailers -{ - /// <summary> - /// Fetches Apple's list of current movie trailers - /// </summary> - public static class AppleTrailerListingDownloader - { - /// <summary> - /// The trailer feed URL - /// </summary> - private const string TrailerFeedUrl = "http://trailers.apple.com/trailers/home/xml/current_720p.xml"; - - /// <summary> - /// Downloads a list of trailer info's from the apple url - /// </summary> - /// <returns>Task{List{TrailerInfo}}.</returns> - public static async Task<List<TrailerInfo>> GetTrailerList(CancellationToken cancellationToken) - { - var stream = await Kernel.Instance.HttpManager.Get(TrailerFeedUrl, Kernel.Instance.ResourcePools.AppleTrailerVideos, cancellationToken).ConfigureAwait(false); - - var list = new List<TrailerInfo>(); - - using (var reader = XmlReader.Create(stream, new XmlReaderSettings { Async = true })) - { - await reader.MoveToContentAsync().ConfigureAwait(false); - - while (await reader.ReadAsync().ConfigureAwait(false)) - { - cancellationToken.ThrowIfCancellationRequested(); - - if (reader.NodeType == XmlNodeType.Element) - { - switch (reader.Name) - { - case "movieinfo": - var trailer = FetchTrailerInfo(reader.ReadSubtree()); - list.Add(trailer); - break; - } - } - } - } - - return list; - } - - /// <summary> - /// Fetches trailer info from an xml node - /// </summary> - /// <param name="reader">The reader.</param> - /// <returns>TrailerInfo.</returns> - private static TrailerInfo FetchTrailerInfo(XmlReader reader) - { - var trailerInfo = new TrailerInfo { }; - - reader.MoveToContent(); - - while (reader.Read()) - { - if (reader.NodeType == XmlNodeType.Element) - { - switch (reader.Name) - { - case "info": - FetchInfo(reader.ReadSubtree(), trailerInfo); - break; - case "cast": - FetchCast(reader.ReadSubtree(), trailerInfo); - break; - case "genre": - FetchGenres(reader.ReadSubtree(), trailerInfo); - break; - case "poster": - FetchPosterUrl(reader.ReadSubtree(), trailerInfo); - break; - case "preview": - FetchTrailerUrl(reader.ReadSubtree(), trailerInfo); - break; - default: - reader.Skip(); - break; - } - } - } - - return trailerInfo; - } - - private static readonly CultureInfo USCulture = new CultureInfo("en-US"); - - /// <summary> - /// Fetches from the info node - /// </summary> - /// <param name="reader">The reader.</param> - /// <param name="info">The info.</param> - private static void FetchInfo(XmlReader reader, TrailerInfo info) - { - reader.MoveToContent(); - reader.Read(); - - while (reader.NodeType == XmlNodeType.Element) - { - switch (reader.Name) - { - case "title": - info.Video.Name = reader.ReadStringSafe(); - break; - case "runtime": - { - var runtime = reader.ReadStringSafe(); - - if (!string.IsNullOrWhiteSpace(runtime)) - { - if (runtime.StartsWith(":", StringComparison.OrdinalIgnoreCase)) - { - runtime = "0" + runtime; - } - - TimeSpan runtimeTimeSpan; - - if (TimeSpan.TryParse(runtime, USCulture, out runtimeTimeSpan)) - { - info.Video.RunTimeTicks = runtimeTimeSpan.Ticks; - } - } - break; - } - case "rating": - info.Video.OfficialRating = reader.ReadStringSafe(); - break; - case "studio": - { - var studio = reader.ReadStringSafe(); - if (!string.IsNullOrWhiteSpace(studio)) - { - info.Video.AddStudio(studio); - } - break; - } - case "postdate": - { - DateTime date; - - if (DateTime.TryParse(reader.ReadStringSafe(), USCulture, DateTimeStyles.None, out date)) - { - info.PostDate = date; - } - break; - } - case "releasedate": - { - var val = reader.ReadStringSafe(); - - if (!string.IsNullOrWhiteSpace(val)) - { - DateTime date; - - if (DateTime.TryParse(val, USCulture, DateTimeStyles.None, out date)) - { - info.Video.PremiereDate = date; - info.Video.ProductionYear = date.Year; - } - } - - break; - } - case "director": - { - var directors = reader.ReadStringSafe() ?? string.Empty; - - foreach (var director in directors.Split(',', StringSplitOptions.RemoveEmptyEntries)) - { - var name = director.Trim(); - - if (!string.IsNullOrWhiteSpace(name)) - { - info.Video.AddPerson(new PersonInfo { Name = name, Type = PersonType.Director }); - } - } - break; - } - case "description": - info.Video.Overview = reader.ReadStringSafe(); - break; - default: - reader.Skip(); - break; - } - } - } - - /// <summary> - /// Fetches from the genre node - /// </summary> - /// <param name="reader">The reader.</param> - /// <param name="info">The info.</param> - private static void FetchGenres(XmlReader reader, TrailerInfo info) - { - reader.MoveToContent(); - reader.Read(); - - while (reader.IsStartElement()) - { - if (reader.NodeType == XmlNodeType.Element) - { - switch (reader.Name) - { - case "name": - info.Video.AddGenre(reader.ReadStringSafe()); - break; - default: - reader.Skip(); - break; - } - } - } - - } - - /// <summary> - /// Fetches from the cast node - /// </summary> - /// <param name="reader">The reader.</param> - /// <param name="info">The info.</param> - private static void FetchCast(XmlReader reader, TrailerInfo info) - { - reader.MoveToContent(); - reader.Read(); - - while (reader.IsStartElement()) - { - if (reader.NodeType == XmlNodeType.Element) - { - switch (reader.Name) - { - case "name": - info.Video.AddPerson(new PersonInfo { Name = reader.ReadStringSafe(), Type = PersonType.Actor }); - break; - default: - reader.Skip(); - break; - } - } - } - - } - - /// <summary> - /// Fetches from the preview node - /// </summary> - /// <param name="reader">The reader.</param> - /// <param name="info">The info.</param> - private static void FetchTrailerUrl(XmlReader reader, TrailerInfo info) - { - reader.MoveToContent(); - reader.Read(); - - while (reader.NodeType == XmlNodeType.Element) - { - switch (reader.Name) - { - case "large": - info.TrailerUrl = reader.ReadStringSafe(); - break; - default: - reader.Skip(); - break; - } - } - - } - - /// <summary> - /// Fetches from the poster node - /// </summary> - /// <param name="reader">The reader.</param> - /// <param name="info">The info.</param> - private static void FetchPosterUrl(XmlReader reader, TrailerInfo info) - { - reader.MoveToContent(); - reader.Read(); - - while (reader.NodeType == XmlNodeType.Element) - { - switch (reader.Name) - { - case "location": - info.ImageUrl = reader.ReadStringSafe(); - break; - case "xlarge": - info.HdImageUrl = reader.ReadStringSafe(); - break; - default: - reader.Skip(); - break; - } - } - - } - - } -} diff --git a/MediaBrowser.Plugins.Trailers/Configuration/PluginConfiguration.cs b/MediaBrowser.Plugins.Trailers/Configuration/PluginConfiguration.cs deleted file mode 100644 index d54f017971..0000000000 --- a/MediaBrowser.Plugins.Trailers/Configuration/PluginConfiguration.cs +++ /dev/null @@ -1,46 +0,0 @@ -using MediaBrowser.Model.Plugins; - -namespace MediaBrowser.Plugins.Trailers.Configuration -{ - /// <summary> - /// Class PluginConfiguration - /// </summary> - public class PluginConfiguration : BasePluginConfiguration - { - /// <summary> - /// Gets or sets the name of the folder. - /// </summary> - /// <value>The name of the folder.</value> - public string FolderName { get; set; } - - /// <summary> - /// Trailers older than this will not be downloaded and deleted if already downloaded. - /// </summary> - /// <value>The max trailer age.</value> - public int? MaxTrailerAge { get; set; } - - /// <summary> - /// Gets the path to where trailers should be downloaded. - /// If not supplied then programdata/cache/trailers will be used. - /// </summary> - /// <value>The download path.</value> - public string DownloadPath { get; set; } - - /// <summary> - /// Gets or sets a value indicating whether [delete old trailers]. - /// </summary> - /// <value><c>true</c> if [delete old trailers]; otherwise, <c>false</c>.</value> - public bool DeleteOldTrailers { get; set; } - - /// <summary> - /// Initializes a new instance of the <see cref="PluginConfiguration" /> class. - /// </summary> - public PluginConfiguration() - : base() - { - FolderName = "Trailers"; - - MaxTrailerAge = 60; - } - } -} diff --git a/MediaBrowser.Plugins.Trailers/Configuration/TrailerConfigurationPage.cs b/MediaBrowser.Plugins.Trailers/Configuration/TrailerConfigurationPage.cs deleted file mode 100644 index 93ce49dc26..0000000000 --- a/MediaBrowser.Plugins.Trailers/Configuration/TrailerConfigurationPage.cs +++ /dev/null @@ -1,50 +0,0 @@ -using MediaBrowser.Common.Plugins; -using MediaBrowser.Controller.Plugins; -using System.ComponentModel.Composition; -using System.IO; - -namespace MediaBrowser.Plugins.Trailers.Configuration -{ - /// <summary> - /// Class TrailerConfigurationPage - /// </summary> - [Export(typeof(BaseConfigurationPage))] - class TrailerConfigurationPage : BaseConfigurationPage - { - /// <summary> - /// Gets the name. - /// </summary> - /// <value>The name.</value> - public override string Name - { - get { return "Trailers"; } - } - - /// <summary> - /// Gets the HTML stream. - /// </summary> - /// <returns>Stream.</returns> - public override Stream GetHtmlStream() - { - return GetHtmlStreamFromManifestResource("MediaBrowser.Plugins.Trailers.Configuration.configPage.html"); - } - - /// <summary> - /// Gets the owner plugin. - /// </summary> - /// <returns>BasePlugin.</returns> - public override IPlugin GetOwnerPlugin() - { - return Plugin.Instance; - } - - /// <summary> - /// Gets the type of the configuration page. - /// </summary> - /// <value>The type of the configuration page.</value> - public override ConfigurationPageType ConfigurationPageType - { - get { return ConfigurationPageType.PluginConfiguration; } - } - } -} diff --git a/MediaBrowser.Plugins.Trailers/Configuration/configPage.html b/MediaBrowser.Plugins.Trailers/Configuration/configPage.html deleted file mode 100644 index 9467f3f98e..0000000000 --- a/MediaBrowser.Plugins.Trailers/Configuration/configPage.html +++ /dev/null @@ -1,119 +0,0 @@ -<!DOCTYPE html> -<html> -<head> - <title>Trailers</title> -</head> -<body> - <div id="trailersConfigurationPage" data-role="page" class="page type-interior pluginConfigurationPage"> - - <div data-role="content"> - <div class="content-primary"> - <form id="trailersConfigurationForm"> - - <ul class="ulForm" data-role="listview"> - <li> - <label for="txtFolderName"> - Trailer collection name: - </label> - <input id="txtFolderName" name="txtFolderName" /> - </li> - <li> - <label for="txtMaxTrailerAge"> - Max trailer age (days): - </label> - <input type="number" id="txtMaxTrailerAge" name="txtMaxTrailerAge" pattern="[0-9]*" min="1" /> - <div class="fieldDescription"> - If specified, trailers older than this will not be downloaded - </div> - </li> - <li> - <input type="checkbox" id="chkDeleteOldTrailers" name="chkDeleteOldTrailers" /> - <label for="chkDeleteOldTrailers">Delete trailers older than the max age</label> - </li> - <li> - <label for="txtDownloadPath"> - Download path: - </label> - <div style="display: inline-block; width:92%;"> - <input id="txtDownloadPath" name="txtDownloadPath" data-inline="true" /> - </div> - <button type="button" data-icon="folder-close" data-iconpos="notext" data-inline="true" onclick="TrailersConfigurationPage.selectDirectory();">Select Directory</button> - <div class="fieldDescription"> - By default, trailers are downloaded to an internal data directory. Using a different location may make it easier to share over your network. - </div> - </li> - <li> - <button type="submit" data-theme="b">Save</button> - <button type="button" onclick="history.back();">Cancel</button> - </li> - </ul> - - </form> - </div> - </div> - - <script type="text/javascript"> - - var TrailersConfigurationPage = { - pluginUniqueId: "986a7283-205a-4436-862d-23135c067f8a", - - selectDirectory: function () { - - Dashboard.selectDirectory({ - callback: function (path) { - - if (path) { - $('#txtDownloadPath', $.mobile.activePage).val(path); - } - $('#popupDirectoryPicker', $.mobile.activePage).popup("close"); - }, - - header: "Select Trailer Path" - }); - - } - }; - - $('#trailersConfigurationPage').on('pageshow', function (event) { - - Dashboard.showLoadingMsg(); - - var page = this; - - ApiClient.getPluginConfiguration(TrailersConfigurationPage.pluginUniqueId).done(function (config) { - - $('#txtDownloadPath', page).val(config.DownloadPath); - $('#txtFolderName', page).val(config.FolderName); - $('#txtMaxTrailerAge', page).val(config.MaxTrailerAge || ""); - $('#chkDeleteOldTrailers', page).checked(config.DeleteOldTrailers).checkboxradio("refresh"); - - Dashboard.hideLoadingMsg(); - }); - }); - - $('#trailersConfigurationForm').on('submit', function (e) { - - Dashboard.showLoadingMsg(); - - var form = this; - - ApiClient.getPluginConfiguration(TrailersConfigurationPage.pluginUniqueId).done(function (config) { - - config.DownloadPath = $('#txtDownloadPath', form).val(); - config.FolderName = $('#txtFolderName', form).val(); - var maxTrailerAge = $('#txtMaxTrailerAge', form).val(); - - config.MaxTrailerAge = maxTrailerAge ? maxTrailerAge : null; - - config.DeleteOldTrailers = $('#chkDeleteOldTrailers', form).checked(); - - ApiClient.updatePluginConfiguration(TrailersConfigurationPage.pluginUniqueId, config).done(Dashboard.processPluginConfigurationUpdateResult); - }); - - // Disable default form submission - return false; - }); - </script> - </div> -</body> -</html> diff --git a/MediaBrowser.Plugins.Trailers/Entities/TrailerCollectionFolder.cs b/MediaBrowser.Plugins.Trailers/Entities/TrailerCollectionFolder.cs deleted file mode 100644 index 95ba07967f..0000000000 --- a/MediaBrowser.Plugins.Trailers/Entities/TrailerCollectionFolder.cs +++ /dev/null @@ -1,33 +0,0 @@ -using MediaBrowser.Controller.Entities; -using System.ComponentModel.Composition; - -namespace MediaBrowser.Plugins.Trailers.Entities -{ - /// <summary> - /// Class TrailerCollectionFolder - /// </summary> - [Export(typeof(BasePluginFolder))] - class TrailerCollectionFolder : BasePluginFolder - { - /// <summary> - /// Gets the name. - /// </summary> - /// <value>The name.</value> - public override string Name - { - get - { - return Plugin.Instance.Configuration.FolderName; - } - } - - /// <summary> - /// Gets the path. - /// </summary> - /// <value>The path.</value> - public override string Path - { - get { return Plugin.Instance.DownloadPath; } - } - } -} diff --git a/MediaBrowser.Plugins.Trailers/MediaBrowser.Plugins.Trailers.csproj b/MediaBrowser.Plugins.Trailers/MediaBrowser.Plugins.Trailers.csproj deleted file mode 100644 index 6cf2aef78f..0000000000 --- a/MediaBrowser.Plugins.Trailers/MediaBrowser.Plugins.Trailers.csproj +++ /dev/null @@ -1,88 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> - <PropertyGroup> - <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> - <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> - <ProjectGuid>{2F4C01E2-7C9F-4F08-922E-27AC4A1D53FF}</ProjectGuid> - <OutputType>Library</OutputType> - <AppDesignerFolder>Properties</AppDesignerFolder> - <RootNamespace>MediaBrowser.Plugins.Trailers</RootNamespace> - <AssemblyName>MediaBrowser.Plugins.Trailers</AssemblyName> - <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> - <FileAlignment>512</FileAlignment> - <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir> - <RestorePackages>true</RestorePackages> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> - <DebugSymbols>true</DebugSymbols> - <DebugType>full</DebugType> - <Optimize>false</Optimize> - <OutputPath>bin\Debug\</OutputPath> - <DefineConstants>DEBUG;TRACE</DefineConstants> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> - <DebugType>pdbonly</DebugType> - <Optimize>true</Optimize> - <OutputPath>bin\Release\</OutputPath> - <DefineConstants>TRACE</DefineConstants> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - </PropertyGroup> - <PropertyGroup> - <RunPostBuildEvent>Always</RunPostBuildEvent> - </PropertyGroup> - <ItemGroup> - <Reference Include="System" /> - <Reference Include="System.ComponentModel.Composition" /> - <Reference Include="System.Core" /> - <Reference Include="System.Xml.Linq" /> - <Reference Include="System.Data.DataSetExtensions" /> - <Reference Include="Microsoft.CSharp" /> - <Reference Include="System.Data" /> - <Reference Include="System.Xml" /> - </ItemGroup> - <ItemGroup> - <Compile Include="AppleTrailerListingDownloader.cs" /> - <Compile Include="Configuration\PluginConfiguration.cs" /> - <Compile Include="Configuration\TrailerConfigurationPage.cs" /> - <Compile Include="Providers\TrailerFromJsonProvider.cs" /> - <Compile Include="Resolvers\TrailerResolver.cs" /> - <Compile Include="ScheduledTasks\CurrentTrailerDownloadTask.cs" /> - <Compile Include="Plugin.cs" /> - <Compile Include="Properties\AssemblyInfo.cs" /> - <Compile Include="Entities\TrailerCollectionFolder.cs" /> - <Compile Include="TrailerInfo.cs" /> - </ItemGroup> - <ItemGroup> - <ProjectReference Include="..\MediaBrowser.Common\MediaBrowser.Common.csproj"> - <Project>{9142eefa-7570-41e1-bfcc-468bb571af2f}</Project> - <Name>MediaBrowser.Common</Name> - </ProjectReference> - <ProjectReference Include="..\MediaBrowser.Controller\MediaBrowser.Controller.csproj"> - <Project>{17e1f4e6-8abd-4fe5-9ecf-43d4b6087ba2}</Project> - <Name>MediaBrowser.Controller</Name> - </ProjectReference> - <ProjectReference Include="..\MediaBrowser.Model\MediaBrowser.Model.csproj"> - <Project>{7eeeb4bb-f3e8-48fc-b4c5-70f0fff8329b}</Project> - <Name>MediaBrowser.Model</Name> - </ProjectReference> - </ItemGroup> - <ItemGroup> - <EmbeddedResource Include="Configuration\configPage.html" /> - </ItemGroup> - <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> - <PropertyGroup> - <PostBuildEvent>xcopy "$(TargetPath)" "$(SolutionDir)\ProgramData-Server\Plugins\" /y</PostBuildEvent> - </PropertyGroup> - <Import Project="$(SolutionDir)\.nuget\nuget.targets" /> - <!-- To modify your build process, add your task inside one of the targets below and uncomment it. - Other similar extension points exist, see Microsoft.Common.targets. - <Target Name="BeforeBuild"> - </Target> - <Target Name="AfterBuild"> - </Target> - --> -</Project>
\ No newline at end of file diff --git a/MediaBrowser.Plugins.Trailers/Plugin.cs b/MediaBrowser.Plugins.Trailers/Plugin.cs deleted file mode 100644 index 2fc2773d38..0000000000 --- a/MediaBrowser.Plugins.Trailers/Plugin.cs +++ /dev/null @@ -1,119 +0,0 @@ -using MediaBrowser.Common.Plugins; -using MediaBrowser.Controller.ScheduledTasks; -using MediaBrowser.Model.Plugins; -using MediaBrowser.Plugins.Trailers.Configuration; -using MediaBrowser.Plugins.Trailers.ScheduledTasks; -using System; -using System.ComponentModel.Composition; -using System.IO; - -namespace MediaBrowser.Plugins.Trailers -{ - /// <summary> - /// Class Plugin - /// </summary> - [Export(typeof(IPlugin))] - public class Plugin : BasePlugin<PluginConfiguration> - { - /// <summary> - /// Gets the name of the plugin - /// </summary> - /// <value>The name.</value> - public override string Name - { - get { return "Trailers"; } - } - - /// <summary> - /// Gets the description. - /// </summary> - /// <value>The description.</value> - public override string Description - { - get - { - return "Movie trailers for your collection."; - } - } - - /// <summary> - /// Gets the instance. - /// </summary> - /// <value>The instance.</value> - public static Plugin Instance { get; private set; } - - /// <summary> - /// Initializes a new instance of the <see cref="Plugin" /> class. - /// </summary> - public Plugin() - : base() - { - Instance = this; - } - - /// <summary> - /// The _download path - /// </summary> - private string _downloadPath; - /// <summary> - /// Gets the path to the trailer download directory - /// </summary> - /// <value>The download path.</value> - public string DownloadPath - { - get - { - if (_downloadPath == null) - { - // Use - _downloadPath = Configuration.DownloadPath; - - if (string.IsNullOrWhiteSpace(_downloadPath)) - { - _downloadPath = Path.Combine(Controller.Kernel.Instance.ApplicationPaths.DataPath, Name); - } - - if (!Directory.Exists(_downloadPath)) - { - Directory.CreateDirectory(_downloadPath); - } - } - return _downloadPath; - } - } - - /// <summary> - /// Starts the plugin on the server - /// </summary> - /// <param name="isFirstRun">if set to <c>true</c> [is first run].</param> - protected override void InitializeOnServer(bool isFirstRun) - { - base.InitializeOnServer(isFirstRun); - - if (isFirstRun) - { - Kernel.TaskManager.QueueScheduledTask<CurrentTrailerDownloadTask>(); - } - } - - /// <summary> - /// Completely overwrites the current configuration with a new copy - /// Returns true or false indicating success or failure - /// </summary> - /// <param name="configuration">The configuration.</param> - public override void UpdateConfiguration(BasePluginConfiguration configuration) - { - var config = (PluginConfiguration) configuration; - - var pathChanged = !string.Equals(Configuration.DownloadPath, config.DownloadPath, StringComparison.OrdinalIgnoreCase); - - base.UpdateConfiguration(configuration); - - if (pathChanged) - { - _downloadPath = null; - Kernel.TaskManager.QueueScheduledTask<RefreshMediaLibraryTask>(); - } - } - } -} diff --git a/MediaBrowser.Plugins.Trailers/Properties/AssemblyInfo.cs b/MediaBrowser.Plugins.Trailers/Properties/AssemblyInfo.cs deleted file mode 100644 index 32dd174d5f..0000000000 --- a/MediaBrowser.Plugins.Trailers/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("MediaBrowser.Plugins.Trailers")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("MediaBrowser.Plugins.Trailers")] -[assembly: AssemblyCopyright("Copyright © 2012")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("986a7283-205a-4436-862d-23135c067f8a")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// 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.*")] diff --git a/MediaBrowser.Plugins.Trailers/Providers/TrailerFromJsonProvider.cs b/MediaBrowser.Plugins.Trailers/Providers/TrailerFromJsonProvider.cs deleted file mode 100644 index 3f126dcdd4..0000000000 --- a/MediaBrowser.Plugins.Trailers/Providers/TrailerFromJsonProvider.cs +++ /dev/null @@ -1,143 +0,0 @@ -using MediaBrowser.Common.Serialization; -using MediaBrowser.Controller.Entities; -using MediaBrowser.Controller.Providers; -using MediaBrowser.Plugins.Trailers.Entities; -using System; -using System.ComponentModel.Composition; -using System.IO; -using System.Threading; -using System.Threading.Tasks; - -namespace MediaBrowser.Plugins.Trailers.Providers -{ - /// <summary> - /// Class TrailerFromJsonProvider - /// </summary> - [Export(typeof(BaseMetadataProvider))] - class TrailerFromJsonProvider : BaseMetadataProvider - { - /// <summary> - /// Supportses the specified item. - /// </summary> - /// <param name="item">The item.</param> - /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns> - public override bool Supports(BaseItem item) - { - var trailer = item as Trailer; - - return trailer != null && trailer.Parent is TrailerCollectionFolder; - } - - /// <summary> - /// Override this to return the date that should be compared to the last refresh date - /// to determine if this provider should be re-fetched. - /// </summary> - /// <param name="item">The item.</param> - /// <returns>DateTime.</returns> - protected override DateTime CompareDate(BaseItem item) - { - var entry = item.ResolveArgs.GetMetaFileByPath(Path.Combine(item.MetaLocation, "trailer.json")); - return entry != null ? entry.Value.LastWriteTimeUtc : DateTime.MinValue; - } - - /// <summary> - /// Fetches metadata and returns true or false indicating if any work that requires persistence was done - /// </summary> - /// <param name="item">The item.</param> - /// <param name="force">if set to <c>true</c> [force].</param> - /// <returns>Task{System.Boolean}.</returns> - protected override Task<bool> FetchAsyncInternal(BaseItem item, bool force, CancellationToken cancellationToken) - { - return Task.Run(() => Fetch((Trailer)item)); - } - - /// <summary> - /// Fetches the specified item. - /// </summary> - /// <param name="item">The item.</param> - /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns> - private bool Fetch(Trailer item) - { - var metadataFile = item.ResolveArgs.GetMetaFileByPath(Path.Combine(item.MetaLocation, "trailer.json")); - - if (metadataFile.HasValue) - { - var tempTrailer = JsonSerializer.DeserializeFromFile<Trailer>(metadataFile.Value.Path); - - ImportMetdata(tempTrailer, item); - - SetLastRefreshed(item, DateTime.UtcNow); - return true; - } - return false; - } - - /// <summary> - /// Gets the priority. - /// </summary> - /// <value>The priority.</value> - public override MetadataProviderPriority Priority - { - get { return MetadataProviderPriority.First; } - } - - /// <summary> - /// Imports the metdata. - /// </summary> - /// <param name="source">The source.</param> - /// <param name="target">The target.</param> - private void ImportMetdata(Trailer source, Trailer target) - { - if (!string.IsNullOrWhiteSpace(source.Name)) - { - target.Name = source.Name; - } - - if (source.RunTimeTicks.HasValue) - { - target.RunTimeTicks = source.RunTimeTicks; - } - - if (source.Genres != null) - { - foreach (var entry in source.Genres) - { - target.AddGenre(entry); - } - } - - if (!string.IsNullOrWhiteSpace(source.OfficialRating)) - { - target.OfficialRating = source.OfficialRating; - } - - if (!string.IsNullOrWhiteSpace(source.Overview)) - { - target.Overview = source.Overview; - } - - if (source.People != null) - { - target.AddPeople(source.People); - } - - if (source.PremiereDate.HasValue) - { - target.PremiereDate = source.PremiereDate; - } - - if (source.ProductionYear.HasValue) - { - target.ProductionYear = source.ProductionYear; - } - - if (source.Studios != null) - { - foreach (var entry in source.Studios) - { - target.AddStudio(entry); - } - } - } - } -} diff --git a/MediaBrowser.Plugins.Trailers/Resolvers/TrailerResolver.cs b/MediaBrowser.Plugins.Trailers/Resolvers/TrailerResolver.cs deleted file mode 100644 index b1e4968df3..0000000000 --- a/MediaBrowser.Plugins.Trailers/Resolvers/TrailerResolver.cs +++ /dev/null @@ -1,51 +0,0 @@ -using MediaBrowser.Controller.Entities; -using MediaBrowser.Controller.Library; -using MediaBrowser.Controller.Resolvers; -using System; -using System.ComponentModel.Composition; -using System.Linq; - -namespace MediaBrowser.Plugins.Trailers.Resolvers -{ - /// <summary> - /// Class TrailerResolver - /// </summary> - [Export(typeof(IBaseItemResolver))] - public class TrailerResolver : BaseVideoResolver<Trailer> - { - /// <summary> - /// Resolves the specified args. - /// </summary> - /// <param name="args">The args.</param> - /// <returns>Trailer.</returns> - protected override Trailer Resolve(ItemResolveArgs args) - { - // Must be a directory and under the trailer download folder - if (args.IsDirectory && args.Path.StartsWith(Plugin.Instance.DownloadPath, StringComparison.OrdinalIgnoreCase)) - { - // The trailer must be a video file - return FindTrailer(args); - } - - return null; - } - - /// <summary> - /// Finds a movie based on a child file system entries - /// </summary> - /// <param name="args">The args.</param> - /// <returns>Trailer.</returns> - private Trailer FindTrailer(ItemResolveArgs args) - { - // Loop through each child file/folder and see if we find a video - return args.FileSystemChildren - .Where(c => !c.IsDirectory) - .Select(child => base.Resolve(new ItemResolveArgs - { - FileInfo = child, - Path = child.Path - })) - .FirstOrDefault(i => i != null); - } - } -} diff --git a/MediaBrowser.Plugins.Trailers/ScheduledTasks/CurrentTrailerDownloadTask.cs b/MediaBrowser.Plugins.Trailers/ScheduledTasks/CurrentTrailerDownloadTask.cs deleted file mode 100644 index 47206fca03..0000000000 --- a/MediaBrowser.Plugins.Trailers/ScheduledTasks/CurrentTrailerDownloadTask.cs +++ /dev/null @@ -1,311 +0,0 @@ -using MediaBrowser.Common.IO; -using MediaBrowser.Common.ScheduledTasks; -using MediaBrowser.Common.Serialization; -using MediaBrowser.Controller; -using MediaBrowser.Controller.Entities; -using MediaBrowser.Model.Net; -using MediaBrowser.Model.Tasks; -using MediaBrowser.Plugins.Trailers.Entities; -using System; -using System.Collections.Generic; -using System.ComponentModel.Composition; -using System.IO; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; - -namespace MediaBrowser.Plugins.Trailers.ScheduledTasks -{ - /// <summary> - /// Downloads trailers from the web at scheduled times - /// </summary> - [Export(typeof(IScheduledTask))] - public class CurrentTrailerDownloadTask : BaseScheduledTask<Kernel> - { - /// <summary> - /// Creates the triggers that define when the task will run - /// </summary> - /// <returns>IEnumerable{BaseTaskTrigger}.</returns> - protected override IEnumerable<BaseTaskTrigger> GetDefaultTriggers() - { - var trigger = new DailyTrigger { TimeOfDay = TimeSpan.FromHours(2) }; //2am - - return new[] { trigger }; - } - - /// <summary> - /// Returns the task to be executed - /// </summary> - /// <param name="cancellationToken">The cancellation token.</param> - /// <param name="progress">The progress.</param> - /// <returns>Task.</returns> - protected override async Task ExecuteInternal(CancellationToken cancellationToken, IProgress<double> progress) - { - // Get the list of trailers - var trailers = await AppleTrailerListingDownloader.GetTrailerList(cancellationToken).ConfigureAwait(false); - - progress.Report(1); - - var trailersToDownload = trailers.Where(t => !IsOldTrailer(t.Video)).ToList(); - - cancellationToken.ThrowIfCancellationRequested(); - - var numComplete = 0; - - // Fetch them all in parallel - var tasks = trailersToDownload.Select(t => Task.Run(async () => - { - cancellationToken.ThrowIfCancellationRequested(); - - try - { - await DownloadTrailer(t, cancellationToken).ConfigureAwait(false); - } - catch (Exception ex) - { - Logger.ErrorException("Error downloading {0}", ex, t.TrailerUrl); - } - - // Update progress - lock (progress) - { - numComplete++; - double percent = numComplete; - percent /= trailersToDownload.Count; - - // Leave 1% for DeleteOldTrailers - progress.Report((99 * percent) + 1); - } - })); - - cancellationToken.ThrowIfCancellationRequested(); - - await Task.WhenAll(tasks).ConfigureAwait(false); - - cancellationToken.ThrowIfCancellationRequested(); - - if (Plugin.Instance.Configuration.DeleteOldTrailers) - { - // Enforce MaxTrailerAge - DeleteOldTrailers(); - } - - progress.Report(100); - } - - /// <summary> - /// Downloads a single trailer into the trailers directory - /// </summary> - /// <param name="trailer">The trailer.</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task.</returns> - private async Task DownloadTrailer(TrailerInfo trailer, CancellationToken cancellationToken) - { - // Construct the trailer foldername - var folderName = FileSystem.GetValidFilename(trailer.Video.Name); - - if (trailer.Video.ProductionYear.HasValue) - { - folderName += string.Format(" ({0})", trailer.Video.ProductionYear); - } - - var folderPath = Path.Combine(Plugin.Instance.DownloadPath, folderName); - - // Figure out which image we're going to download - var imageUrl = trailer.HdImageUrl ?? trailer.ImageUrl; - - // Construct the video filename (to match the folder name) - var videoFileName = Path.ChangeExtension(folderName, Path.GetExtension(trailer.TrailerUrl)); - - // Construct the image filename (folder + original extension) - var imageFileName = Path.ChangeExtension("folder", Path.GetExtension(imageUrl)); - - // Construct full paths - var videoFilePath = Path.Combine(folderPath, videoFileName); - var imageFilePath = Path.Combine(folderPath, imageFileName); - - // Create tasks to download each of them, if we don't already have them - Task<string> videoTask = null; - Task<MemoryStream> imageTask = null; - - var tasks = new List<Task>(); - - if (!File.Exists(videoFilePath)) - { - Logger.Info("Downloading trailer: " + trailer.TrailerUrl); - - // Fetch the video to a temp file because it's too big to put into a MemoryStream - videoTask = Kernel.HttpManager.FetchToTempFile(trailer.TrailerUrl, Kernel.ResourcePools.AppleTrailerVideos, cancellationToken, new Progress<double> { }, "QuickTime/7.6.2"); - tasks.Add(videoTask); - } - - if (!string.IsNullOrWhiteSpace(imageUrl) && !File.Exists(imageFilePath)) - { - // Fetch the image to a memory stream - Logger.Info("Downloading trailer image: " + imageUrl); - imageTask = Kernel.HttpManager.FetchToMemoryStream(imageUrl, Kernel.ResourcePools.AppleTrailerImages, cancellationToken); - tasks.Add(imageTask); - } - - try - { - // Wait for both downloads to finish - await Task.WhenAll(tasks).ConfigureAwait(false); - } - catch (HttpException ex) - { - Logger.ErrorException("Error downloading trailer file or image", ex); - } - - var videoFailed = false; - var directoryEnsured = false; - - // Proces the video file task result - if (videoTask != null) - { - if (videoTask.Status == TaskStatus.RanToCompletion) - { - EnsureDirectory(folderPath); - - directoryEnsured = true; - - // Move the temp file to the final destination - try - { - File.Move(videoTask.Result, videoFilePath); - } - catch (IOException ex) - { - Logger.ErrorException("Error moving temp file", ex); - File.Delete(videoTask.Result); - videoFailed = true; - } - } - else - { - Logger.Info("Trailer download failed: " + trailer.TrailerUrl); - - // Don't bother with the image if the video download failed - videoFailed = true; - } - } - - // Process the image file task result - if (imageTask != null && !videoFailed && imageTask.Status == TaskStatus.RanToCompletion) - { - if (!directoryEnsured) - { - EnsureDirectory(folderPath); - } - - try - { - // Save the image to the file system - using (var fs = new FileStream(imageFilePath, FileMode.Create, FileAccess.Write, FileShare.Read, StreamDefaults.DefaultFileStreamBufferSize, FileOptions.Asynchronous)) - { - using (var sourceStream = imageTask.Result) - { - await sourceStream.CopyToAsync(fs).ConfigureAwait(false); - } - } - } - catch (IOException ex) - { - Logger.ErrorException("Error saving image to file system", ex); - } - } - - // Save metadata only if the video was downloaded - if (!videoFailed && videoTask != null) - { - JsonSerializer.SerializeToFile(trailer.Video, Path.Combine(folderPath, "trailer.json")); - } - } - - /// <summary> - /// Determines whether [is old trailer] [the specified trailer]. - /// </summary> - /// <param name="trailer">The trailer.</param> - /// <returns><c>true</c> if [is old trailer] [the specified trailer]; otherwise, <c>false</c>.</returns> - private bool IsOldTrailer(Trailer trailer) - { - if (!Plugin.Instance.Configuration.MaxTrailerAge.HasValue) - { - return false; - } - - if (!trailer.PremiereDate.HasValue) - { - return false; - } - - var now = DateTime.UtcNow; - - // Not old if it still hasn't premiered. - if (now < trailer.PremiereDate.Value) - { - return false; - } - - return (DateTime.UtcNow - trailer.PremiereDate.Value).TotalDays > - Plugin.Instance.Configuration.MaxTrailerAge.Value; - } - - /// <summary> - /// Deletes trailers that are older than the supplied date - /// </summary> - private void DeleteOldTrailers() - { - var collectionFolder = (Folder)Kernel.RootFolder.Children.First(c => c.GetType().Name.Equals(typeof(TrailerCollectionFolder).Name)); - - foreach (var trailer in collectionFolder.RecursiveChildren.OfType<Trailer>().Where(IsOldTrailer)) - { - Logger.Info("Deleting old trailer: " + trailer.Name); - - Directory.Delete(Path.GetDirectoryName(trailer.Path), true); - } - } - - /// <summary> - /// Ensures the directory. - /// </summary> - /// <param name="path">The path.</param> - private void EnsureDirectory(string path) - { - if (!Directory.Exists(path)) - { - Directory.CreateDirectory(path); - } - } - - /// <summary> - /// Gets the name of the task - /// </summary> - /// <value>The name.</value> - public override string Name - { - get { return "Find current trailers"; } - } - - /// <summary> - /// Gets the category. - /// </summary> - /// <value>The category.</value> - public override string Category - { - get - { - return "Trailers"; - } - } - - /// <summary> - /// Gets the description. - /// </summary> - /// <value>The description.</value> - public override string Description - { - get { return "Searches the web for upcoming movie trailers, and downloads them based on your Trailer plugin settings."; } - } - } -} diff --git a/MediaBrowser.Plugins.Trailers/TrailerInfo.cs b/MediaBrowser.Plugins.Trailers/TrailerInfo.cs deleted file mode 100644 index e3c661b67f..0000000000 --- a/MediaBrowser.Plugins.Trailers/TrailerInfo.cs +++ /dev/null @@ -1,45 +0,0 @@ -using MediaBrowser.Controller.Entities; -using System; - -namespace MediaBrowser.Plugins.Trailers -{ - /// <summary> - /// This is a stub class used to hold information about a trailer - /// </summary> - public class TrailerInfo - { - /// <summary> - /// Gets or sets the video. - /// </summary> - /// <value>The video.</value> - public Trailer Video { get; set; } - /// <summary> - /// Gets or sets the image URL. - /// </summary> - /// <value>The image URL.</value> - public string ImageUrl { get; set; } - /// <summary> - /// Gets or sets the hd image URL. - /// </summary> - /// <value>The hd image URL.</value> - public string HdImageUrl { get; set; } - /// <summary> - /// Gets or sets the trailer URL. - /// </summary> - /// <value>The trailer URL.</value> - public string TrailerUrl { get; set; } - /// <summary> - /// Gets or sets the post date. - /// </summary> - /// <value>The post date.</value> - public DateTime PostDate { get; set; } - - /// <summary> - /// Initializes a new instance of the <see cref="TrailerInfo" /> class. - /// </summary> - public TrailerInfo() - { - Video = new Trailer(); - } - } -} |
