Added TvDb offline project. still need to clean the data

pull/7/merge
kay.one 14 years ago
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

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

30
clo

@ -0,0 +1,30 @@
* af705cb - (HEAD, origin/master, origin/HEAD, master) cleaned up history/log grid UI (20 seconds ago) <kay.one>
* e896af5 - ReSharper code cleanup (17 minutes ago) <kay.one>
* 8cade43 - Application will automatically restart on db error. (32 minutes ago) <kay.one>
* fcf5197 - Removed IConfigProvider, ISeasonProvider, ISyncProvider (86 minutes ago) <kay.one>
* 7efbfdb - removed IEpisodeProvider, ILogProvider (3 hours ago) <kay.one>
* 8fbc79c - Merge branch 'mark-fork' (4 hours ago) <kay.one>
|\
| * 0a7f7fc - (mark/master, mark-fork) Added tests for RootDirProvider. (5 hours ago) <Mark McDowall>
| * bfeb7b3 - Merge branch 'master' of git://github.com/kayone/NzbDrone (7 hours ago) <Mark McDowall>
| |\
| * | 1a9948d - Removed IDiskProvider. (27 hours ago) <Mark McDowall>
| * | e5413d6 - Removed IRenameProvider. (27 hours ago) <Mark McDowall>
| * | 29690d9 - Removed IRssSyncProvider & IBacklogProvider (27 hours ago) <Mark McDowall>
| * | 0d95302 - Removed IHistoryProvider. (27 hours ago) <Mark McDowall>
| * | c25af59 - Removed ISeriesProvider (27 hours ago) <Mark McDowall>
| * | bd0a7a5 - Removed INotificationProvider (27 hours ago) <Mark McDowall>
| * | 4426072 - Merge branch 'master' of git://github.com/kayone/NzbDrone (34 hours ago) <Mark McDowall>
| |\ \
* | | | 1cc44ed - fixed some build issues/notification issues (4 hours ago) <kay.one>
| |_|/
|/| |
* | | ce11986 - Merge branch 'mark-fork' (34 hours ago) <Keivan>
|\ \ \
| |/ /
| | /
| |/
|/|
| * f52b399 - Removed IExternalNotificationProvider (35 hours ago) <Mark McDowall>
| * c77a88d - Removed IDownloadProvider (35 hours ago) <Mark McDowall>
| * 0ee4f8c - Removed IPostProcessingProvider (2 days ago) <Mark McDowall>
Loading…
Cancel
Save