Added TvDb offline project. still need to clean the data
This commit is contained in:
parent
af705cbf9a
commit
bee99cbd5b
|
@ -8,7 +8,7 @@ using NzbDrone.Core.Repository.Quality;
|
|||
|
||||
namespace NzbDrone.Core
|
||||
{
|
||||
internal static class Parser
|
||||
public static class Parser
|
||||
{
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
|
@ -239,7 +239,7 @@ namespace NzbDrone.Core
|
|||
/// </summary>
|
||||
/// <param name = "title">title</param>
|
||||
/// <returns></returns>
|
||||
internal static string NormalizeTitle(string title)
|
||||
public static string NormalizeTitle(string title)
|
||||
{
|
||||
return NormalizeRegex.Replace(title, String.Empty).ToLower();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Visual Studio 2010
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.Tvdb.Offline", "NzbDrone.Tvdb.Offline\NzbDrone.Tvdb.Offline.csproj", "{9B00D86A-6A39-44D2-9D66-32D9D07882E8}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{9B00D86A-6A39-44D2-9D66-32D9D07882E8}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{9B00D86A-6A39-44D2-9D66-32D9D07882E8}.Debug|x86.Build.0 = Debug|x86
|
||||
{9B00D86A-6A39-44D2-9D66-32D9D07882E8}.Release|x86.ActiveCfg = Release|x86
|
||||
{9B00D86A-6A39-44D2-9D66-32D9D07882E8}.Release|x86.Build.0 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
Binary file not shown.
|
@ -0,0 +1,87 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
||||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{9B00D86A-6A39-44D2-9D66-32D9D07882E8}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>NzbDrone.Tvdb.Offline</RootNamespace>
|
||||
<AssemblyName>NzbDrone.Tvdb.Offline</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile>
|
||||
</TargetFrameworkProfile>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<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|x86' ">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Ionic.Zip, Version=1.9.1.5, Culture=neutral, PublicKeyToken=edbe51ad942a3f5c, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>.\Ionic.Zip.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NLog">
|
||||
<HintPath>..\..\NzbDrone.Core\Libraries\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NLog.Extended">
|
||||
<HintPath>..\..\NzbDrone.Core\Libraries\NLog.Extended.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NzbDrone.Core">
|
||||
<HintPath>..\..\NzbDrone.Core\bin\Debug\NzbDrone.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SubSonic.Core">
|
||||
<HintPath>..\..\NzbDrone.Core\Libraries\SubSonic.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Data.SQLite">
|
||||
<HintPath>..\..\NzbDrone.Core\Libraries\System.Data.SQLite.dll</HintPath>
|
||||
</Reference>
|
||||
<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="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Series.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
<None Include="log.config">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Ionic.Zip.dll" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.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>
|
|
@ -0,0 +1,181 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
using Ionic.Zip;
|
||||
using NLog;
|
||||
using NLog.Config;
|
||||
using SubSonic.DataProviders;
|
||||
using SubSonic.Repository;
|
||||
|
||||
namespace NzbDrone.Tvdb.Offline
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static Logger _logger = LogManager.GetLogger("Main");
|
||||
private static DirectoryInfo _target;
|
||||
private static DirectoryInfo _temp;
|
||||
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
SetupLogger();
|
||||
_logger.Info("Starting TVDB Offline...");
|
||||
GetPath(args);
|
||||
|
||||
Start();
|
||||
|
||||
|
||||
Console.WriteLine("Press any key to exit...");
|
||||
Console.ReadLine();
|
||||
}
|
||||
|
||||
|
||||
private static void Start()
|
||||
{
|
||||
_logger.Info("Starting to generate offline DB...");
|
||||
var files = _target.GetFiles("*.zip");
|
||||
_logger.Info("Total number of files found {0}", files.Count());
|
||||
|
||||
var list = new Dictionary<int, Series>();
|
||||
|
||||
var repo = InitSubsonic();
|
||||
decimal progress = 0;
|
||||
foreach (var fileInfo in files)
|
||||
{
|
||||
Console.Write("\r{0:0.0}%", progress * 100 / files.Count());
|
||||
var series = ProcessFile(fileInfo, repo);
|
||||
if (series != null)
|
||||
{
|
||||
if (!list.ContainsKey(series.SeriesId))
|
||||
{
|
||||
list.Add(series.SeriesId, series);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine();
|
||||
_logger.Warn("Conflict {0} <=> {1}", list[series.SeriesId], series);
|
||||
}
|
||||
}
|
||||
progress++;
|
||||
}
|
||||
|
||||
_logger.Info("Writing series to DB");
|
||||
repo.AddMany(list.Values);
|
||||
_logger.Info("DB is fully created");
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static Series ProcessFile(FileInfo fileInfo, IRepository repo)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
_logger.Debug("Processing " + fileInfo.Name);
|
||||
using (ZipFile zip = ZipFile.Read(fileInfo.FullName))
|
||||
{
|
||||
|
||||
ZipEntry e = zip["en.xml"];
|
||||
if (e == null)
|
||||
{
|
||||
_logger.Warn("File {0} didn't contain an en.xml file", fileInfo.Name);
|
||||
return null;
|
||||
}
|
||||
|
||||
var stream = e.OpenReader();
|
||||
var seriesElement = XDocument.Load(stream).Descendants("Series").First();
|
||||
|
||||
var series = new Series();
|
||||
series.SeriesId = (int)seriesElement.Element("id");
|
||||
|
||||
series.AirsDayOfWeek = seriesElement.Element("Airs_DayOfWeek").Value;
|
||||
series.AirTimes = seriesElement.Element("Airs_Time").Value;
|
||||
series.Overview = seriesElement.Element("Overview").Value;
|
||||
series.Status = seriesElement.Element("Status").Value;
|
||||
series.Title = seriesElement.Element("SeriesName").Value;
|
||||
|
||||
int ratingCount;
|
||||
Int32.TryParse(seriesElement.Element("RatingCount").Value, out ratingCount);
|
||||
series.RateCount = ratingCount;
|
||||
|
||||
decimal rating;
|
||||
Decimal.TryParse(seriesElement.Element("Rating").Value, out rating);
|
||||
series.RateCount = ratingCount;
|
||||
|
||||
series.CleanTitle = Core.Parser.NormalizeTitle(series.Title);
|
||||
series.Path = fileInfo.Name;
|
||||
|
||||
return series;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.Error("Unable to process file. {0}. {1}", fileInfo.Name, e.Message);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static IRepository InitSubsonic()
|
||||
{
|
||||
var path = Path.Combine(_temp.FullName, "series_data.db");
|
||||
_logger.Info("Creating Database file at {0}", path);
|
||||
|
||||
if (File.Exists(path))
|
||||
{
|
||||
File.Delete(path);
|
||||
}
|
||||
|
||||
string logConnectionString = String.Format("Data Source={0};Version=3;", path);
|
||||
var provider = ProviderFactory.GetProvider(logConnectionString, "System.Data.SQLite");
|
||||
|
||||
return new SimpleRepository(provider, SimpleRepositoryOptions.RunMigrations);
|
||||
}
|
||||
|
||||
private static void GetPath(string[] args)
|
||||
{
|
||||
if (args == null || args.Count() == 0 || string.IsNullOrWhiteSpace(args[0]))
|
||||
{
|
||||
_logger.Warn("Please provide a valid target path");
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
_target = new DirectoryInfo(args[0]);
|
||||
|
||||
if (!_target.Exists)
|
||||
{
|
||||
_logger.Warn("Directory '{0}' doesn't exist.", _target.FullName);
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
_logger.Info("Target Path '[{0}]'", _target.FullName);
|
||||
|
||||
_logger.Debug("Creating temporary folder");
|
||||
_temp = _target.CreateSubdirectory("temp");
|
||||
}
|
||||
|
||||
|
||||
private static void SetupLogger()
|
||||
{
|
||||
|
||||
LogManager.ThrowExceptions = true;
|
||||
|
||||
try
|
||||
{
|
||||
LogManager.Configuration = new XmlLoggingConfiguration("log.config", false);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
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("NzbDrone.Tvdb.Offline")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Microsoft")]
|
||||
[assembly: AssemblyProduct("NzbDrone.Tvdb.Offline")]
|
||||
[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
|
||||
[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("20805934-73f9-4a27-93c5-bb17f42435cd")]
|
||||
|
||||
// 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.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
@ -0,0 +1,35 @@
|
|||
using System;
|
||||
using SubSonic.SqlGeneration.Schema;
|
||||
|
||||
namespace NzbDrone.Tvdb.Offline
|
||||
{
|
||||
public class Series
|
||||
{
|
||||
[SubSonicPrimaryKey(false)]
|
||||
public virtual int SeriesId { get; set; }
|
||||
|
||||
public string Title { get; set; }
|
||||
|
||||
public string CleanTitle { get; set; }
|
||||
|
||||
public string Status { get; set; }
|
||||
|
||||
public string Overview { get; set; }
|
||||
|
||||
public string AirsDayOfWeek { get; set; }
|
||||
|
||||
public String AirTimes { get; set; }
|
||||
|
||||
public int RateCount { get; set; }
|
||||
|
||||
public decimal Rating { get; set; }
|
||||
|
||||
[SubSonicIgnore]
|
||||
public String Path { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("[{0}:{1} {2}]", SeriesId, Title, Path);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0"?>
|
||||
<configuration>
|
||||
<startup useLegacyV2RuntimeActivationPolicy="true">
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
|
||||
</startup>
|
||||
<system.data>
|
||||
<DbProviderFactories>
|
||||
<remove invariant="System.Data.SQLite" />
|
||||
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
|
||||
</DbProviderFactories>
|
||||
</system.data>
|
||||
</configuration>
|
|
@ -0,0 +1,18 @@
|
|||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" autoReload="true">
|
||||
<targets>
|
||||
<target name="consoleTarget" xsi:type="ColoredConsole" layout="${logger}: ${message}" />
|
||||
<target name="debugTarget" xsi:type="Debugger" layout="${logger}: ${message}" />
|
||||
<target name="udpTarget" xsi:type="Chainsaw" address="udp://127.0.0.1:20480"
|
||||
includeCallSite="true" includeSourceInfo="true" includeNLogData="true" includeNDC="true" includeMDC="true">
|
||||
<parameter name="exception" layout="${exception:format=ToString}" xsi:type="NLogViewerParameterInfo" />
|
||||
<parameter name="processname" layout="${processname}" xsi:type="NLogViewerParameterInfo" />
|
||||
<parameter name="stacktrace" layout="${stacktrace:topFrames=99}" xsi:type="NLogViewerParameterInfo" />
|
||||
<parameter name="ThreadName" layout="${threadname}" xsi:type="NLogViewerParameterInfo" />
|
||||
</target>
|
||||
</targets>
|
||||
<rules>
|
||||
<logger name="*" minlevel="Info" writeTo="consoleTarget"/>
|
||||
<logger name="*" minlevel="Trace" writeTo="debugTarget"/>
|
||||
<logger name="*" minlevel="Trace" writeTo="udpTarget"/>
|
||||
</rules>
|
||||
</nlog>
|
|
@ -0,0 +1,30 @@
|
|||
* [31maf705cb[m -[33m (HEAD, origin/master, origin/HEAD, master)[m cleaned up history/log grid UI [32m(20 seconds ago) [1;34m<kay.one>[m
|
||||
* [31me896af5[m -[33m[m ReSharper code cleanup [32m(17 minutes ago) [1;34m<kay.one>[m
|
||||
* [31m8cade43[m -[33m[m Application will automatically restart on db error. [32m(32 minutes ago) [1;34m<kay.one>[m
|
||||
* [31mfcf5197[m -[33m[m Removed IConfigProvider, ISeasonProvider, ISyncProvider [32m(86 minutes ago) [1;34m<kay.one>[m
|
||||
* [31m7efbfdb[m -[33m[m removed IEpisodeProvider, ILogProvider [32m(3 hours ago) [1;34m<kay.one>[m
|
||||
* [31m8fbc79c[m -[33m[m Merge branch 'mark-fork' [32m(4 hours ago) [1;34m<kay.one>[m
|
||||
[32m|[m[33m\[m
|
||||
[32m|[m * [31m0a7f7fc[m -[33m (mark/master, mark-fork)[m Added tests for RootDirProvider. [32m(5 hours ago) [1;34m<Mark McDowall>[m
|
||||
[32m|[m * [31mbfeb7b3[m -[33m[m Merge branch 'master' of git://github.com/kayone/NzbDrone [32m(7 hours ago) [1;34m<Mark McDowall>[m
|
||||
[32m|[m [34m|[m[35m\[m
|
||||
[32m|[m * [35m|[m [31m1a9948d[m -[33m[m Removed IDiskProvider. [32m(27 hours ago) [1;34m<Mark McDowall>[m
|
||||
[32m|[m * [35m|[m [31me5413d6[m -[33m[m Removed IRenameProvider. [32m(27 hours ago) [1;34m<Mark McDowall>[m
|
||||
[32m|[m * [35m|[m [31m29690d9[m -[33m[m Removed IRssSyncProvider & IBacklogProvider [32m(27 hours ago) [1;34m<Mark McDowall>[m
|
||||
[32m|[m * [35m|[m [31m0d95302[m -[33m[m Removed IHistoryProvider. [32m(27 hours ago) [1;34m<Mark McDowall>[m
|
||||
[32m|[m * [35m|[m [31mc25af59[m -[33m[m Removed ISeriesProvider [32m(27 hours ago) [1;34m<Mark McDowall>[m
|
||||
[32m|[m * [35m|[m [31mbd0a7a5[m -[33m[m Removed INotificationProvider [32m(27 hours ago) [1;34m<Mark McDowall>[m
|
||||
[32m|[m * [35m|[m [31m4426072[m -[33m[m Merge branch 'master' of git://github.com/kayone/NzbDrone [32m(34 hours ago) [1;34m<Mark McDowall>[m
|
||||
[32m|[m [36m|[m[1;31m\[m [35m\[m
|
||||
* [36m|[m [1;31m|[m [35m|[m [31m1cc44ed[m -[33m[m fixed some build issues/notification issues [32m(4 hours ago) [1;34m<kay.one>[m
|
||||
[35m|[m [36m|[m[35m_[m[1;31m|[m[35m/[m
|
||||
[35m|[m[35m/[m[36m|[m [1;31m|[m
|
||||
* [36m|[m [1;31m|[m [31mce11986[m -[33m[m Merge branch 'mark-fork' [32m(34 hours ago) [1;34m<Keivan>[m
|
||||
[1;31m|[m[36m\[m [36m\[m [1;31m\[m
|
||||
[1;31m|[m [36m|[m[36m/[m [1;31m/[m
|
||||
[1;31m|[m [36m|[m [1;31m/[m
|
||||
[1;31m|[m [36m|[m[1;31m/[m
|
||||
[1;31m|[m[1;31m/[m[36m|[m
|
||||
[1;31m|[m * [31mf52b399[m -[33m[m Removed IExternalNotificationProvider [32m(35 hours ago) [1;34m<Mark McDowall>[m
|
||||
[1;31m|[m * [31mc77a88d[m -[33m[m Removed IDownloadProvider [32m(35 hours ago) [1;34m<Mark McDowall>[m
|
||||
[1;31m|[m * [31m0ee4f8c[m -[33m[m Removed IPostProcessingProvider [32m(2 days ago) [1;34m<Mark McDowall>[m
|
Loading…
Reference in New Issue