Skip to content

Commit

Permalink
Merge pull request #377 from MarkSummerville/25
Browse files Browse the repository at this point in the history
Updates from latest round of bug fixing
  • Loading branch information
SirSparkles authored Apr 18, 2018
2 parents 907680b + c7e9e8b commit d4aeb93
Show file tree
Hide file tree
Showing 35 changed files with 798 additions and 551 deletions.
2 changes: 1 addition & 1 deletion TVRename#/App/AutoFolderMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void mScanDelayTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
mUI.Invoke(mUI.AFMDoAll);

if (TVSettings.Instance.MonitoredFoldersScanType == TVSettings.ScanType.Full)
mDoc.ExportMissingXML(); // Export Missing episodes to XML if we scanned all
mDoc.ExportMissingXML(TVSettings.Instance.MonitoredFoldersScanType); // Export Missing episodes to XML if we scanned all

}

Expand Down
2 changes: 1 addition & 1 deletion TVRename#/App/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private static void Main(string[] args)
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(GlobalExceptionHandler);
AppDomain.CurrentDomain.UnhandledException += GlobalExceptionHandler;

if (args.Contains("/?", StringComparer.OrdinalIgnoreCase))
{
Expand Down
2 changes: 1 addition & 1 deletion TVRename#/DownloadIdentifers/DownloadEpisodeJPG.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public override ItemList ProcessEpisode(ProcessedEpisode dbep, FileInfo filo, bo
{
string basefn = filo.RemoveExtension();

FileInfo imgjpg = FileHelper.FileInFolder(filo.Directory, basefn + ".jpg");
FileInfo imgjpg = FileHelper.FileInFolder(filo.Directory, basefn + defaultExtension);

if (forceRefresh || !imgjpg.Exists)
TheActionList.Add(new ActionDownloadImage(dbep.SI, dbep, imgjpg, ban, TVSettings.Instance.ShrinkLargeMede8erImages));
Expand Down
105 changes: 105 additions & 0 deletions TVRename#/Exporter/ActionListXML.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
using System;
using System.Xml;

namespace TVRename
{
abstract class ActionListXML : ActionListExporter
{
protected ActionListXML(ItemList theActionList) : base(theActionList)
{
}

public override void Run()
{
if (Active())
{
try
{

XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.NewLineOnAttributes = true;
using (XmlWriter writer = XmlWriter.Create(Location(), settings))
{
writer.WriteStartDocument();

writer.WriteStartElement("TVRename");
XMLHelper.WriteAttributeToXML(writer, "Version", "2.1");
writer.WriteStartElement(name());


foreach (Item action in TheActionList)
{
if (isOutput(action))
{
ActionCopyMoveRename acmr = (ActionCopyMoveRename)action;
writer.WriteStartElement("Item");

XMLHelper.WriteAttributeToXML(writer, "Operation", acmr.Name);
XMLHelper.WriteAttributeToXML(writer, "FromFolder", acmr.From.DirectoryName);
XMLHelper.WriteAttributeToXML(writer, "FromName", acmr.From.Name);
XMLHelper.WriteAttributeToXML(writer, "ToFolder", acmr.To.DirectoryName);
XMLHelper.WriteAttributeToXML(writer, "ToName", acmr.To.Name);
XMLHelper.WriteAttributeToXML(writer, "ShowName", acmr.Episode.TheSeries.Name);
XMLHelper.WriteAttributeToXML(writer, "Season", acmr.Episode.AppropriateSeasonNumber);
XMLHelper.WriteAttributeToXML(writer, "Episode", acmr.Episode.NumsAsString());

writer.WriteEndElement(); //Item
}

}

writer.WriteEndElement(); // Name
writer.WriteEndElement(); // tvrename
writer.WriteEndDocument();
}
}
catch (Exception e)
{
Logger.Error(e);
}
}
}

protected abstract bool isOutput(Item a);
protected abstract string name();

}

class RenamingXML : ActionListXML
{
public RenamingXML(ItemList theActionList) : base(theActionList)
{
}

protected override bool isOutput(Item a)
{
return (a is ActionCopyMoveRename cmr) && ((cmr.Operation == ActionCopyMoveRename.Op.Rename));
}
public override bool ApplicableFor(TVSettings.ScanType st) => true;

public override bool Active() => TVSettings.Instance.ExportRenamingXML;
protected override string Location() => TVSettings.Instance.ExportRenamingXMLTo;
protected override string name() => "Renaming";

}

class CopyMoveXML : ActionListXML
{
public CopyMoveXML(ItemList theActionList) : base(theActionList)
{
}

public override bool ApplicableFor(TVSettings.ScanType st) => true;

protected override bool isOutput(Item a)
{
return (a is ActionCopyMoveRename cmr) && ((cmr.Operation != ActionCopyMoveRename.Op.Rename));
}

public override bool Active() => TVSettings.Instance.ExportFOXML;
protected override string Location() => TVSettings.Instance.ExportFOXMLTo;
protected override string name() => "FindingAndOrganising";

}
}
41 changes: 28 additions & 13 deletions TVRename#/Exporter/Exporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,48 @@

namespace TVRename
{
abstract class Exporter
internal abstract class Exporter
{
public abstract bool Active();
public abstract void Run();
protected abstract string Location();
protected static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();

}

abstract class ShowsExporter : Exporter
internal abstract class ShowsExporter : Exporter
{
public abstract void Run(List<ShowItem> shows);
protected readonly List<ShowItem> Shows;


protected ShowsExporter(List<ShowItem> shows)
{
this.Shows = shows;
}
}


abstract class MissingExporter : Exporter
internal abstract class ActionListExporter : Exporter
{
public abstract void Run(ItemList theActionList);
protected readonly ItemList TheActionList;


protected ActionListExporter(ItemList theActionList)
{
this.TheActionList = theActionList;
}

public abstract bool ApplicableFor(TVSettings.ScanType st);
}

abstract class UpcomingExporter : Exporter
internal abstract class UpcomingExporter : Exporter
{
protected readonly TVDoc mDoc;
protected readonly TVDoc Doc;


public UpcomingExporter(TVDoc doc)
protected UpcomingExporter(TVDoc doc)
{
this.mDoc = doc;
this.Doc = doc;
}

private string Produce()
Expand All @@ -44,10 +59,10 @@ private string Produce()

using (MemoryStream ms = new MemoryStream())
{
List<ProcessedEpisode> lpe = mDoc.NextNShows(TVSettings.Instance.ExportRSSMaxShows,
List<ProcessedEpisode> lpe = this.Doc.NextNShows(TVSettings.Instance.ExportRSSMaxShows,
TVSettings.Instance.ExportRSSDaysPast, TVSettings.Instance.ExportRSSMaxDays);
if (lpe != null)
if (this.Generate(ms, lpe))
if (Generate(ms, lpe))
{
return System.Text.Encoding.ASCII.GetString(ms.ToArray());
}
Expand All @@ -61,7 +76,7 @@ private string Produce()
return "";
}

public void Run()
public override void Run()
{
if (Active())
{
Expand Down
50 changes: 50 additions & 0 deletions TVRename#/Exporter/MissingCSV.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;

namespace TVRename
{
// ReSharper disable once InconsistentNaming
internal class MissingCSV : ActionListExporter
{
public MissingCSV(ItemList theActionList) : base(theActionList)
{
}

public override bool Active() => TVSettings.Instance.ExportMissingCSV;
protected override string Location() => TVSettings.Instance.ExportMissingCSVTo;

public override bool ApplicableFor(TVSettings.ScanType st)
{
return (st==TVSettings.ScanType.Full );
}

public override void Run()
{
if (!Active()) return;

try
{

using (System.IO.StreamWriter file = new System.IO.StreamWriter(Location()))
{
file.WriteLine("Show Name,Season,Episode,Episode Name,Air Date,Folder,Nice Name,thetvdb.com Code");

foreach (Item action in this.TheActionList)
{
if (action is ItemMissing im)
{
ProcessedEpisode pe = im.Episode;
DateTime? dt = pe.GetAirDateDT(true);
file.WriteLine($"\"{pe.TheSeries.Name}\",{pe.AppropriateSeasonNumber},{pe.NumsAsString()},\"{pe.Name}\",{dt:G},\"{action.TargetFolder}\",\"{im.Filename }\",{pe.SeriesID}");
}

}

}
}
catch (Exception e)
{
Logger.Error(e);
}
}
}
}
77 changes: 48 additions & 29 deletions TVRename#/Exporter/MissingXML.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
using System;
using System.Text;
using System.Xml;

namespace TVRename
{
class MissingXML : MissingExporter
// ReSharper disable once InconsistentNaming
internal class MissingXML : ActionListExporter
{
public MissingXML(ItemList theActionList) : base(theActionList)
{
}

public override bool Active() =>TVSettings.Instance.ExportMissingXML;
protected override string Location() =>TVSettings.Instance.ExportMissingXMLTo;
public override void Run(ItemList TheActionList)

public override bool ApplicableFor(TVSettings.ScanType st)
{
if (TVSettings.Instance.ExportMissingXML)
return (st == TVSettings.ScanType.Full);
}
public override void Run()
{
if (!Active()) return;

try
{
XmlWriterSettings settings = new XmlWriterSettings();
//XmlWriterSettings settings = gcnew XmlWriterSettings();
settings.Indent = true;
settings.NewLineOnAttributes = true;
XmlWriterSettings settings = new XmlWriterSettings
{
Indent = true,
NewLineOnAttributes = true,
Encoding = Encoding.ASCII
};


using (XmlWriter writer = XmlWriter.Create(Location(), settings))
{
writer.WriteStartDocument();
Expand All @@ -24,34 +40,37 @@ public override void Run(ItemList TheActionList)
XMLHelper.WriteAttributeToXML(writer,"Version","2.1");
writer.WriteStartElement("MissingItems");

foreach (Item Action in TheActionList)
foreach (Item action in this.TheActionList)
{
if (Action is ItemMissing)
{
ItemMissing Missing = (ItemMissing)(Action);
writer.WriteStartElement("MissingItem");

XMLHelper.WriteElementToXML(writer,"id",Missing.Episode.SI.TVDBCode);
XMLHelper.WriteElementToXML(writer, "title",Missing.Episode.TheSeries.Name);
XMLHelper.WriteElementToXML(writer, "season", Helpers.pad(Missing.Episode.AppropriateSeasonNumber));
XMLHelper.WriteElementToXML(writer, "episode", Helpers.pad(Missing.Episode.AppropriateEpNum));
XMLHelper.WriteElementToXML(writer, "episodeName",Missing.Episode.Name);
XMLHelper.WriteElementToXML(writer, "description",Missing.Episode.Overview);

writer.WriteStartElement("pubDate");
DateTime? dt = Missing.Episode.GetAirDateDT(true);
if (dt != null)
writer.WriteValue(dt.Value.ToString("F"));
writer.WriteEndElement();

writer.WriteEndElement(); // MissingItem
if (!(action is ItemMissing)) continue;

ItemMissing missing = (ItemMissing)(action);
writer.WriteStartElement("MissingItem");

XMLHelper.WriteElementToXML(writer,"id",missing.Episode.SI.TVDBCode);
XMLHelper.WriteElementToXML(writer, "title",missing.Episode.TheSeries.Name);
XMLHelper.WriteElementToXML(writer, "season", Helpers.pad(missing.Episode.AppropriateSeasonNumber));
XMLHelper.WriteElementToXML(writer, "episode", Helpers.pad(missing.Episode.AppropriateEpNum));
XMLHelper.WriteElementToXML(writer, "episodeName",missing.Episode.Name);
XMLHelper.WriteElementToXML(writer, "description",missing.Episode.Overview);

}
writer.WriteStartElement("pubDate");
DateTime? dt = missing.Episode.GetAirDateDT(true);
if (dt != null)
writer.WriteValue(dt.Value.ToString("F"));
writer.WriteEndElement();

writer.WriteEndElement(); // MissingItem
}
writer.WriteEndElement(); // MissingItems
writer.WriteEndElement(); // tvrename
writer.WriteEndDocument();
}

}
catch (Exception e)
{
Logger.Error(e);
}
}
}
Expand Down
Loading

0 comments on commit d4aeb93

Please sign in to comment.