tvdb offline changes, doesn't work.

This commit is contained in:
Keivan Beigi 2013-01-30 16:36:26 -08:00 committed by kay.one
parent 8a5a326480
commit 022ed5ba5c
11 changed files with 2837 additions and 192 deletions

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
</configuration>

Binary file not shown.

View File

@ -0,0 +1,153 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>
<!-- Enable the restore command to run before builds -->
<RestorePackages Condition=" '$(RestorePackages)' == '' ">false</RestorePackages>
<!-- Property that enables building a package from a project -->
<BuildPackage Condition=" '$(BuildPackage)' == '' ">false</BuildPackage>
<!-- Determines if package restore consent is required to restore packages -->
<RequireRestoreConsent Condition=" '$(RequireRestoreConsent)' != 'false' ">true</RequireRestoreConsent>
<!-- Download NuGet.exe if it does not already exist -->
<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">false</DownloadNuGetExe>
</PropertyGroup>
<ItemGroup Condition=" '$(PackageSources)' == '' ">
<!-- Package sources used to restore packages. By default, registered sources under %APPDATA%\NuGet\NuGet.Config will be used -->
<!-- The official NuGet package source (https://nuget.org/api/v2/) will be excluded if package sources are specified and it does not appear in the list -->
<!--
<PackageSource Include="https://nuget.org/api/v2/" />
<PackageSource Include="https://my-nuget-source/nuget/" />
-->
</ItemGroup>
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT'">
<!-- Windows specific commands -->
<NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>
<PackagesConfig>$([System.IO.Path]::Combine($(ProjectDir), "packages.config"))</PackagesConfig>
<PackagesDir>$([System.IO.Path]::Combine($(SolutionDir), "packages"))</PackagesDir>
</PropertyGroup>
<PropertyGroup Condition=" '$(OS)' != 'Windows_NT'">
<!-- We need to launch nuget.exe with the mono command if we're not on windows -->
<NuGetToolsPath>$(SolutionDir).nuget</NuGetToolsPath>
<PackagesConfig>packages.config</PackagesConfig>
<PackagesDir>$(SolutionDir)packages</PackagesDir>
</PropertyGroup>
<PropertyGroup>
<!-- NuGet command -->
<NuGetExePath Condition=" '$(NuGetExePath)' == '' ">$(NuGetToolsPath)\nuget.exe</NuGetExePath>
<PackageSources Condition=" $(PackageSources) == '' ">@(PackageSource)</PackageSources>
<NuGetCommand Condition=" '$(OS)' == 'Windows_NT'">"$(NuGetExePath)"</NuGetCommand>
<NuGetCommand Condition=" '$(OS)' != 'Windows_NT' ">mono --runtime=v4.0.30319 $(NuGetExePath)</NuGetCommand>
<PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir>
<RequireConsentSwitch Condition=" $(RequireRestoreConsent) == 'true' ">-RequireConsent</RequireConsentSwitch>
<!-- Commands -->
<RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(RequireConsentSwitch) -o "$(PackagesDir)"</RestoreCommand>
<BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -p Configuration=$(Configuration) -o "$(PackageOutputDir)" -symbols</BuildCommand>
<!-- We need to ensure packages are restored prior to assembly resolve -->
<ResolveReferencesDependsOn Condition="$(RestorePackages) == 'true'">
RestorePackages;
$(ResolveReferencesDependsOn);
</ResolveReferencesDependsOn>
<!-- Make the build depend on restore packages -->
<BuildDependsOn Condition="$(BuildPackage) == 'true'">
$(BuildDependsOn);
BuildPackage;
</BuildDependsOn>
</PropertyGroup>
<Target Name="CheckPrerequisites">
<!-- Raise an error if we're unable to locate nuget.exe -->
<Error Condition="'$(DownloadNuGetExe)' != 'true' AND !Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" />
<SetEnvironmentVariable EnvKey="VisualStudioVersion" EnvValue="$(VisualStudioVersion)" Condition=" '$(VisualStudioVersion)' != '' AND '$(OS)' == 'Windows_NT' " />
<!--
Take advantage of MsBuild's build dependency tracking to make sure that we only ever download nuget.exe once.
This effectively acts as a lock that makes sure that the download operation will only happen once and all
parallel builds will have to wait for it to complete.
-->
<MsBuild Targets="_DownloadNuGet" Projects="$(MSBuildThisFileFullPath)" Properties="Configuration=NOT_IMPORTANT" />
</Target>
<Target Name="_DownloadNuGet">
<DownloadNuGet OutputFilename="$(NuGetExePath)" Condition=" '$(DownloadNuGetExe)' == 'true' AND !Exists('$(NuGetExePath)')" />
</Target>
<Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
<Exec Command="$(RestoreCommand)"
Condition="'$(OS)' != 'Windows_NT' And Exists('$(PackagesConfig)')" />
<Exec Command="$(RestoreCommand)"
LogStandardErrorAsError="true"
Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" />
</Target>
<Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites">
<Exec Command="$(BuildCommand)"
Condition=" '$(OS)' != 'Windows_NT' " />
<Exec Command="$(BuildCommand)"
LogStandardErrorAsError="true"
Condition=" '$(OS)' == 'Windows_NT' " />
</Target>
<UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<OutputFilename ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Reference Include="System.Core" />
<Using Namespace="System" />
<Using Namespace="System.IO" />
<Using Namespace="System.Net" />
<Using Namespace="Microsoft.Build.Framework" />
<Using Namespace="Microsoft.Build.Utilities" />
<Code Type="Fragment" Language="cs">
<![CDATA[
try {
OutputFilename = Path.GetFullPath(OutputFilename);
Log.LogMessage("Downloading latest version of NuGet.exe...");
WebClient webClient = new WebClient();
webClient.DownloadFile("https://nuget.org/nuget.exe", OutputFilename);
return true;
}
catch (Exception ex) {
Log.LogErrorFromException(ex);
return false;
}
]]>
</Code>
</Task>
</UsingTask>
<UsingTask TaskName="SetEnvironmentVariable" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<EnvKey ParameterType="System.String" Required="true" />
<EnvValue ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Using Namespace="System" />
<Code Type="Fragment" Language="cs">
<![CDATA[
try {
Environment.SetEnvironmentVariable(EnvKey, EnvValue, System.EnvironmentVariableTarget.Process);
}
catch {
}
]]>
</Code>
</Task>
</UsingTask>
</Project>

View File

@ -1,8 +1,15 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NzbDrone.Tvdb.Offline", "NzbDrone.Tvdb.Offline\NzbDrone.Tvdb.Offline.csproj", "{9B00D86A-6A39-44D2-9D66-32D9D07882E8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{4F7C0C2A-56AB-4D92-9ACF-BB202A49C7C9}"
ProjectSection(SolutionItems) = preProject
.nuget\NuGet.Config = .nuget\NuGet.Config
.nuget\NuGet.exe = .nuget\NuGet.exe
.nuget\NuGet.targets = .nuget\NuGet.targets
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!--
See http://nlog-project.org/wiki/Configuration_file
for information on customizing logging rules and outputs.
-->
<targets>
<!-- add your targets here -->
<!--
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}" />
-->
</targets>
<rules>
<!-- add your logging rules here -->
<!--
<logger name="*" minlevel="Trace" writeTo="f" />
-->
</rules>
</nlog>

File diff suppressed because it is too large Load Diff

View File

@ -14,6 +14,8 @@
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget>
@ -39,23 +41,20 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>.\Ionic.Zip.dll</HintPath>
</Reference>
<Reference Include="NLog">
<HintPath>..\..\NzbDrone.Core\Libraries\NLog.dll</HintPath>
<Reference Include="MongoDB.Bson">
<HintPath>..\packages\mongocsharpdriver.1.7\lib\net35\MongoDB.Bson.dll</HintPath>
</Reference>
<Reference Include="NLog.Extended">
<HintPath>..\..\NzbDrone.Core\Libraries\NLog.Extended.dll</HintPath>
<Reference Include="MongoDB.Driver">
<HintPath>..\packages\mongocsharpdriver.1.7\lib\net35\MongoDB.Driver.dll</HintPath>
</Reference>
<Reference Include="NLog">
<HintPath>..\packages\NLog.2.0.0.2000\lib\net40\NLog.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" />
@ -72,11 +71,19 @@
<None Include="log.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<Content Include="NLog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Include="NLog.xsd">
<SubType>Designer</SubType>
</None>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="Ionic.Zip.dll" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<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">

View File

@ -1,23 +1,39 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Net;
using System.Xml.Linq;
using Ionic.Zip;
using Ionic.Zlib;
using NLog;
using NLog.Config;
using SubSonic.DataProviders;
using SubSonic.Repository;
namespace NzbDrone.Tvdb.Offline
{
class Program
public class TVDbService
{
static Logger _logger = LogManager.GetLogger("Main");
public List<string> GetSeriesId()
{
var startYear = 1900;
var xml = new WebClient().DownloadString("http://www.thetvdb.com/api/Updates.php?type=all&time=" + startYear);
var Ids = XElement.Load("http://www.thetvdb.com/api/Updates.php?type=all&time=1990")
.Descendants("Items").Select(i=>i.Elements(""))
}
}
public class Program
{
static readonly Logger _logger = LogManager.GetLogger("Main");
private static DirectoryInfo _target;
private static DirectoryInfo _temp;
private static bool _cleanDb;
@ -27,21 +43,10 @@ namespace NzbDrone.Tvdb.Offline
{
SetupLogger();
_logger.Info("Starting TVDB Offline...");
ProcessArguments(args);
if (_cleanDb)
{
CleanUpDb();
}
else
{
CreateNewDb();
}
if (!String.IsNullOrWhiteSpace(dbPath))
{
using (ZipFile zip = new ZipFile())
using (var zip = new ZipFile())
{
_logger.Info("Compressing database file");
zip.CompressionLevel = CompressionLevel.BestCompression;
@ -142,150 +147,11 @@ namespace NzbDrone.Tvdb.Offline
}
private static IRepository InitSubsonic(bool purge, string name = "")
{
dbPath = Path.Combine(_temp.FullName, "series_data" + name + ".db");
_logger.Info("Loading Database file at {0}", dbPath);
if (purge && File.Exists(dbPath))
{
File.Delete(dbPath);
}
string logConnectionString = String.Format("Data Source={0};Version=3;", dbPath);
var provider = ProviderFactory.GetProvider(logConnectionString, "System.Data.SQLite");
return new SimpleRepository(provider, SimpleRepositoryOptions.RunMigrations);
}
private static void ProcessArguments(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);
}
if (args.Count() > 1 && !string.IsNullOrWhiteSpace(args[1]) && args[1].Trim().ToLower() == "/clean")
{
_cleanDb = true;
}
_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());
}
}
private static void CleanUpDb()
{
_logger.Info("Cleaning up database");
var repo = InitSubsonic(false);
var series = repo.All<Series>().ToList();
var cleanSeries = new List<Series>();
decimal progress = 0;
foreach (var item in series)
{
Console.Write("\r{0:0.0}%", progress * 100 / series.Count());
var clean = CleanSeries(item);
if (clean != null)
{
cleanSeries.Add(clean);
}
progress++;
}
repo = InitSubsonic(true, "_cleanTitle");
_logger.Info("Writing clean list to database");
repo.AddMany(cleanSeries);
}
private static Series CleanSeries(Series series)
{
if (String.IsNullOrWhiteSpace(series.Title))
{
return null;
}
if (String.IsNullOrWhiteSpace(series.AirsDayOfWeek))
{
series.AirsDayOfWeek = null;
}
else
{
//if (series.AirsDayOfWeek.ToLower() == "daily")
//{
// series.WeekDay = 8;
//}
//else
//{
// DayOfWeek weekdayEnum;
// if (Enum.TryParse(series.AirsDayOfWeek, true, out weekdayEnum))
// {
// series.WeekDay = (int)weekdayEnum;
// }
// else
// {
// _logger.Warn("Can't parse weekday enum " + series.AirsDayOfWeek);
// }
//}
if (String.IsNullOrWhiteSpace(series.AirsDayOfWeek))
{
series.AirsDayOfWeek = null;
}
}
if (String.IsNullOrWhiteSpace(series.Status))
{
series.Active = null;
}
else if (series.Status == "Ended")
{
series.Active = false;
}
else if (series.Status == "Continuing")
{
series.Active = true;
}
else
{
_logger.Warn("Can't parse status " + series.Status);
}
series.Status = null;
series.Overview = null;
series.CleanTitle = null;
return series;
LogManager.Configuration = new XmlLoggingConfiguration("nlog.config", false);
}
}
}

View File

@ -1,27 +1,21 @@
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; }
[SubSonicNullString]
public string CleanTitle { get; set; }
[SubSonicNullString]
public string Status { get; set; }
public Boolean? Active { get; set; }
[SubSonicNullString]
public string Overview { get; set; }
[SubSonicNullString]
public string AirsDayOfWeek { get; set; }
public int? WeekDay { get; set; }
@ -32,12 +26,6 @@ namespace NzbDrone.Tvdb.Offline
public decimal? Rating { get; set; }
[SubSonicIgnore]
public String Path { get; set; }
public override string ToString()
{
return string.Format("[{0}:{1} {2}]", SeriesId, Title, Path);
}
}
}

View File

@ -1,12 +1,14 @@
<?xml version="1.0"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
<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>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Ionic.Zip" publicKeyToken="edbe51ad942a3f5c" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.9.1.5" newVersion="1.9.1.5" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="mongocsharpdriver" version="1.7" targetFramework="net40" />
<package id="NLog" version="2.0.0.2000" targetFramework="net40" />
<package id="NLog.Config" version="2.0.0.2000" targetFramework="net40" />
</packages>