public override ActionOutcome Go(TVRenameStats stats) { try { if (whereFile != null) { ProcessFile(whereFile, updateTime); } if (whereDirectory != null) { System.IO.Directory.SetLastWriteTimeUtc(whereDirectory.FullName, updateTime); } } catch (UnauthorizedAccessException uae) { return(new ActionOutcome(uae)); } catch (Exception e) { return(new ActionOutcome(e)); } return(ActionOutcome.Success()); }
}; // TODO: move into settings, and allow user to edit these #endregion Fields #region Constructors public TVDoc(FileInfo settingsFile, TheTVDB tvdb, CommandLineArgs args) { this.mTVDB = tvdb; this.Args = args; this.Ignore = new List<IgnoreItem>(); this.Workers = null; this.WorkerSemaphore = null; this.mStats = new TVRenameStats(); this.mDirty = false; this.TheActionList = new ItemList(); this.Settings = new TVSettings(); this.MonitorFolders = new List<String>(); this.IgnoreFolders = new List<String>(); this.SearchFolders = new List<String>(); ShowItems = new List<ShowItem>(); this.AddItems = new FolderMonitorEntryList(); this.DownloadDone = true; this.DownloadOK = true; this.ActionCancel = false; this.ScanProgDlg = null; this.LoadOK = ((settingsFile == null) || this.LoadXMLSettings(settingsFile)) && this.mTVDB.LoadOK; UpdateTVDBLanguage(); // StartServer(); }
public bool Go(TVSettings settings, ref bool pause, TVRenameStats stats) { System.Net.WebClient wc = new System.Net.WebClient(); try { byte[] r = wc.DownloadData(this.RSS.URL); if ((r == null) || (r.Length == 0)) { this.Error = true; this.ErrorText = "No data downloaded"; this.Done = true; return false; } string saveTemp = Path.GetTempPath() + System.IO.Path.DirectorySeparatorChar + settings.FilenameFriendly(this.RSS.Title); if (new FileInfo(saveTemp).Extension.ToLower() != "torrent") saveTemp += ".torrent"; File.WriteAllBytes(saveTemp, r); System.Diagnostics.Process.Start(settings.uTorrentPath, "/directory \"" + (new FileInfo(this.TheFileNoExt).Directory.FullName) + "\" \"" + saveTemp + "\""); this.Done = true; return true; } catch (Exception e) { this.ErrorText = e.Message; this.Error = true; this.Done = true; return false; } }
public bool Go(ref bool pause, TVRenameStats stats) { XmlWriterSettings settings = new XmlWriterSettings { Indent = true, NewLineOnAttributes = true }; // "try" and silently fail. eg. when file is use by other... XmlWriter writer; try { // XmlWriter writer = XmlWriter.Create(this.Where.FullName, settings); writer = XmlWriter.Create(this.Where.FullName, settings); if (writer == null) { return(false); } } catch (Exception) { this.Done = true; return(true); } writer.WriteStartElement("FolderTag"); XMLHelper.WriteElementToXML(writer, "ViewMode", "Movie"); writer.WriteEndElement(); writer.Close(); this.Done = true; return(true); }
public override bool Go(ref bool pause, TVRenameStats stats) { // read NTFS permissions (if any) FileSecurity security = null; try { security = From.GetAccessControl(); } catch { // ignored } DoCopyRename(stats); // set NTFS permissions try { if (security != null) { To.SetAccessControl(security); } } catch { // ignored } TidyUpIfNeeded(); return(!Error); }
public bool Go(ref bool pause, TVRenameStats stats) { System.Net.WebClient wc = new System.Net.WebClient(); try { byte[] r = wc.DownloadData(this.RSS.URL); if ((r == null) || (r.Length == 0)) { this.Error = true; this.ErrorText = "No data downloaded"; this.Done = true; return(false); } string saveTemp = Path.GetTempPath() + System.IO.Path.DirectorySeparatorChar + TVSettings.Instance.FilenameFriendly(this.RSS.Title); if (new FileInfo(saveTemp).Extension.ToLower() != "torrent") { saveTemp += ".torrent"; } File.WriteAllBytes(saveTemp, r); System.Diagnostics.Process.Start(TVSettings.Instance.uTorrentPath, "/directory \"" + (new FileInfo(this.TheFileNoExt).Directory.FullName) + "\" \"" + saveTemp + "\""); this.Done = true; return(true); } catch (Exception e) { this.ErrorText = e.Message; this.Error = true; this.Done = true; return(false); } }
public bool Go(TVSettings settings, ref bool pause, TVRenameStats stats) { byte[] theData = this.SI.TVDB.GetPage(this.BannerPath, false, typeMaskBits.tmBanner, false); if ((theData == null) || (theData.Length == 0)) { this.ErrorText = "Unable to download " + this.BannerPath; this.Error = true; this.Done = true; return(false); } try { FileStream fs = new FileStream(this.Destination.FullName, FileMode.Create); fs.Write(theData, 0, theData.Length); fs.Close(); } catch (Exception e) { this.ErrorText = e.Message; this.Error = true; this.Done = true; return(false); } this.Done = true; return(true); }
public override bool Go(TVRenameStats stats) { try { if (Episode != null) // specific episode { WriteEpisodeXml(); } else if (SelectedShow != null) // show overview (Series.xml) { WriteSeriesXml(); } Done = true; return(true); } catch (Exception e) { ErrorText = e.Message; LastError = e; Error = true; Done = true; return(false); } }
public override bool Go(ref bool pause, TVRenameStats stats) { byte[] theData = TheTVDB.Instance.GetTvdbDownload(path); if ((theData is null) || (theData.Length == 0)) { ErrorText = "Unable to download " + path; Error = true; Done = true; return(false); } if (shrinkLargeMede8ErImage) { // shrink images down to a maximum size of 156x232 Image im = new Bitmap(new System.IO.MemoryStream(theData)); if (Episode is null) { if ((im.Width > 156) || (im.Height > 232)) { im = MaxSize(im, 156, 232); using (System.IO.MemoryStream m = new System.IO.MemoryStream()) { im.Save(m, ImageFormat.Jpeg); theData = m.ToArray(); } } } else { if ((im.Width > 232) || (im.Height > 156)) { im = MaxSize(im, 232, 156); using (System.IO.MemoryStream m = new System.IO.MemoryStream()) { im.Save(m, ImageFormat.Jpeg); theData = m.ToArray(); } } } } try { System.IO.FileStream fs = new System.IO.FileStream(destination.FullName, System.IO.FileMode.Create); fs.Write(theData, 0, theData.Length); fs.Close(); } catch (Exception e) { ErrorText = e.Message; Error = true; Done = true; return(false); } Done = true; return(true); }
public override ActionOutcome Go(TVRenameStats stats) { //if the directory is the root download folder do not delete if (TVSettings.Instance.MonitorFolders && TVSettings.Instance.DownloadFolders.Contains(toRemove.FullName)) { return(new ActionOutcome($@"Not removing {toRemove.FullName} as it is a Search Folder")); } try { if (toRemove.Exists) { DeleteOrRecycleFolder(toRemove); if (Tidyup != null && Tidyup.DeleteEmpty) { LOGGER.Info($"Testing {toRemove.Parent.FullName } to see whether it should be tidied up"); DoTidyUp(toRemove.Parent); } } return(ActionOutcome.Success()); } catch (Exception e) { return(new ActionOutcome(e)); } }
public override bool Go(TVRenameStats stats) { try { if (whereFile != null) { ProcessFile(whereFile, updateTime); } if (whereDirectory != null) { System.IO.Directory.SetLastWriteTimeUtc(whereDirectory.FullName, updateTime); } } catch (Exception e) { ErrorText = e.Message; LastError = e; Error = true; Done = true; return(false); } Done = true; return(true); }
public override bool Go(TVRenameStats stats) { XmlWriterSettings settings = new XmlWriterSettings { Indent = true, NewLineOnAttributes = true }; try { using (XmlWriter writer = XmlWriter.Create(Where.FullName, settings)) { writer.WriteStartElement("FolderTag"); writer.WriteElement("ViewMode", "Movie"); writer.WriteElement("ViewType", "Video"); writer.WriteEndElement(); } } catch (Exception e) { Error = true; ErrorText = e.Message; LastError = e; Done = true; return(false); } Done = true; return(true); }
public bool Go(TVSettings settings, ref bool pause, TVRenameStats stats) { // read NTFS permissions (if any) System.Security.AccessControl.FileSecurity security = null; try { security = this.From.GetAccessControl(); } catch { } if (this.QuickOperation()) { this.OSMoveRename(stats); // ask the OS to do it for us, since it's easy and quick! } else { this.CopyItOurself(ref pause, stats); // do it ourself! } // set NTFS permissions try { if (security != null) { this.To.SetAccessControl(security); } } catch { } return(!this.Error); }
public bool Go(TVSettings settings, ref bool pause, TVRenameStats stats) { // read NTFS permissions (if any) System.Security.AccessControl.FileSecurity security = null; try { security = this.From.GetAccessControl(); } catch { } if (this.QuickOperation()) this.OSMoveRename(stats); // ask the OS to do it for us, since it's easy and quick! else this.CopyItOurself(ref pause, stats); // do it ourself! // set NTFS permissions try { if (security != null) this.To.SetAccessControl(security); } catch { } return !this.Error; }
public override bool Go(TVRenameStats stats) { byte[] theData = TheTVDB.Instance.GetTvdbDownload(path); if ((theData is null) || (theData.Length == 0)) { ErrorText = "Unable to download " + path; Error = true; Done = true; return(false); } if (shrinkLargeMede8ErImage) { theData = ConvertBytes(theData); } try { System.IO.FileStream fs = new System.IO.FileStream(destination.FullName, System.IO.FileMode.Create); fs.Write(theData, 0, theData.Length); fs.Close(); } catch (Exception e) { ErrorText = e.Message; LastError = e; Error = true; Done = true; return(false); } Done = true; return(true); }
public override bool Go(ref bool pause, TVRenameStats stats) { if (Where is null) { ErrorText = "No file location specified - Development Error"; Error = true; Done = true; return(false); } if (Episode != null) { return(WriteEpisodeMetaDataFile()); } if (SelectedShow != null) { return(WriteSeriesXml()); } ErrorText = "No details available to write - Development Error"; Error = true; Done = true; return(false); }
public bool Go(TVSettings settings, ref bool pause, TVRenameStats stats) { byte[] theData = this.SI.TVDB.GetPage(this.BannerPath, false, typeMaskBits.tmBanner, false); if ((theData == null) || (theData.Length == 0)) { this.ErrorText = "Unable to download " + this.BannerPath; this.Error = true; this.Done = true; return false; } try { FileStream fs = new FileStream(this.Destination.FullName, FileMode.Create); fs.Write(theData, 0, theData.Length); fs.Close(); } catch (Exception e) { this.ErrorText = e.Message; this.Error = true; this.Done = true; return false; } this.Done = true; return true; }
private static TVRenameStats LoadFrom(String filename) { if (!File.Exists(filename)) { return(null); } XmlReaderSettings settings = new XmlReaderSettings { IgnoreComments = true, IgnoreWhitespace = true }; TVRenameStats sc = null; try { using (XmlReader reader = XmlReader.Create(filename, settings)) { XmlSerializer xs = new XmlSerializer(typeof(TVRenameStats)); sc = (TVRenameStats)xs.Deserialize(reader); System.Diagnostics.Debug.Assert(sc != null); } } catch (Exception e) { logger.Fatal(e); return(new TVRenameStats()); } return(sc); }
public override ActionOutcome Go(TVRenameStats stats) { try { byte[]? theData = si.Provider == TVDoc.ProviderType.TheTVDB ? TheTVDB.LocalCache.Instance.GetTvdbDownload(path) : HttpHelper.Download(path, false); if (theData is null || theData.Length == 0) { return(new ActionOutcome("Unable to download " + path)); } if (shrinkLargeMede8ErImage) { theData = ConvertBytes(theData); } System.IO.FileStream fs = new System.IO.FileStream(destination.FullName, System.IO.FileMode.Create); fs.Write(theData, 0, theData.Length); fs.Close(); } catch (Exception e) { return(new ActionOutcome(e)); } return(ActionOutcome.Success()); }
public override bool Go(ref bool pause, TVRenameStats stats) { try { if (this.WhereFile != null) { bool priorFileReadonly = this.WhereFile.IsReadOnly; if (priorFileReadonly) { this.WhereFile.IsReadOnly = false; } System.IO.File.SetLastWriteTimeUtc(this.WhereFile.FullName, this.updateTime); if (priorFileReadonly) { this.WhereFile.IsReadOnly = true; } } if (this.WhereDirectory != null) { System.IO.Directory.SetLastWriteTimeUtc(this.WhereDirectory.FullName, this.updateTime); } } catch (Exception e) { this.ErrorText = e.Message; this.Error = true; this.Done = true; return(false); } this.Done = true; return(true); }
public override bool Go(TVRenameStats stats) { //if the directory is the root download folder do not delete if (TVSettings.Instance.MonitorFolders && TVSettings.Instance.DownloadFolders.Contains(toRemove.FullName)) { Error = true; ErrorText = $@"Not removing {toRemove.FullName} as it is a Search Folder"; return(false); } try { if (toRemove.Exists) { DeleteOrRecycleFolder(toRemove); if (Tidyup != null && Tidyup.DeleteEmpty) { LOGGER.Info($"Testing {toRemove.Parent.FullName } to see whether it should be tidied up"); DoTidyup(toRemove.Parent); } } } catch (Exception e) { Error = true; ErrorText = e.Message; LastError = e; } Done = true; return(!Error); }
public bool Go(ref bool pause, TVRenameStats stats) { XmlWriterSettings settings = new XmlWriterSettings { Indent = true, NewLineOnAttributes = true }; // "try" and silently fail. eg. when file is use by other... XmlWriter writer; try { // XmlWriter writer = XmlWriter.Create(this.Where.FullName, settings); writer = XmlWriter.Create(this.Where.FullName, settings); if (writer == null) return false; } catch (Exception) { this.Done = true; return true; } writer.WriteStartElement("FolderTag"); XMLHelper.WriteElementToXML(writer, "ViewMode", "Movie"); writer.WriteEndElement(); writer.Close(); this.Done = true; return true; }
public override ActionOutcome Go(TVRenameStats stats) { return(Episode != null?WriteEpisodeMetaDataFile() : SelectedShow != null?WriteSeriesXml() : ActionOutcome.Success()); //todo WDTV Movie support WriteMovieXml(); }
private void LoadStats() { try { CurrentStats = TVRenameStats.Load(); } catch (Exception) { // not worried if stats loading fails } }
public override bool Go(TVRenameStats stats) { try { if (!(TVSettings.Instance.CheckuTorrent || TVSettings.Instance.CheckqBitTorrent)) { Error = true; ErrorText = "No torrent clients enabled to download RSS"; Done = true; return(false); } if (!TVSettings.Instance.qBitTorrentDownloadFilesFirst && TVSettings.Instance.CheckqBitTorrent) { qBitTorrentFinder.StartTorrentDownload(url, null, false); Done = true; return(true); } byte[] r = HttpHelper.GetUrlBytes(url, true); if (r is null || r.Length == 0) { Error = true; ErrorText = "No data downloaded"; Done = true; return(false); } string saveTemp = SaveDownloadedData(r, SourceName); if (TVSettings.Instance.CheckuTorrent) { uTorrentFinder.StartTorrentDownload(saveTemp, theFileNoExt); } if (TVSettings.Instance.CheckqBitTorrent) { qBitTorrentFinder.StartTorrentDownload(url, saveTemp, TVSettings.Instance.qBitTorrentDownloadFilesFirst); } Done = true; return(true); } catch (Exception e) { ErrorText = e.Message; LastError = e; Error = true; Done = true; return(false); } }
public override bool Go(TVRenameStats stats) { XmlWriterSettings settings = new XmlWriterSettings { Indent = true, IndentChars = " ", Encoding = Encoding.UTF8, NewLineChars = "\r\n", NewLineOnAttributes = true, //Multipart NFO files are not actually valid XML as they have multiple episodeDetails elements ConformanceLevel = ConformanceLevel.Fragment }; try { // "try" and silently fail. eg. when file is use by other... using (XmlWriter writer = XmlWriter.Create(Where.FullName, settings)) { if (Episode != null) // specific episode { if (Episode.Type == ProcessedEpisode.ProcessedEpisodeType.merged) { foreach (Episode ep in Episode.SourceEpisodes) { ShowItem si = Episode.Show ?? SelectedShow; WriteEpisodeDetailsFor(ep, si, writer, true, si.DvdOrder); } } else { ShowItem si = Episode.Show ?? SelectedShow; WriteEpisodeDetailsFor(Episode, si, writer, false, si.DvdOrder); } } else if (SelectedShow != null) // show overview (tvshow.nfo) { WriteSeriesXmlFile(writer); } } } catch (Exception e) { ErrorText = e.Message; LastError = e; Error = true; Done = true; return(false); } Done = true; return(true); }
public override ActionOutcome Go(TVRenameStats stats) { try { client.RemoveCompletedDownload(name); return(ActionOutcome.Success()); } catch (Exception e) { return(new ActionOutcome(e)); } }
public override bool Go(ref bool pause, TVRenameStats stats) { byte[] theData = TheTVDB.Instance.GetTvdbDownload(path); if ((theData is null) || (theData.Length == 0)) { ErrorText = "Unable to download " + path; Error = true; Done = true; return(false); } if (shrinkLargeMede8ErImage) { using (Stream streamPhoto = new MemoryStream(theData)) { BitmapFrame bfPhoto = ReadBitmapFrame(streamPhoto); if (Episode is null) { if ((bfPhoto.Width > 156) || (bfPhoto.Height > 232)) { theData = Resize(bfPhoto, 156, 232); } } else { if ((bfPhoto.Width > 232) || (bfPhoto.Height > 156)) { theData = Resize(bfPhoto, 232, 156); } } } } try { FileStream fs = new FileStream(destination.FullName, FileMode.Create); fs.Write(theData, 0, theData.Length); fs.Close(); } catch (Exception e) { ErrorText = e.Message; Error = true; Done = true; return(false); } Done = true; return(true); }
public override bool Go(TVRenameStats stats) { try { // create folder if it does not exist. (Only really applies when .meta\ folder is being used.) if (!Where.Directory.Exists) { Directory.CreateDirectory(Where.Directory.FullName); } using ( System.IO.StreamWriter writer = new System.IO.StreamWriter(Where.FullName, false, System.Text.Encoding.GetEncoding(1252))) { // See: http://pytivo.sourceforge.net/wiki/index.php/Metadata writer.WriteLine($"title : {Episode.Show.ShowName}"); writer.WriteLine($"seriesTitle : {Episode.Show.ShowName}"); writer.WriteLine($"episodeTitle : {Episode.Name}"); writer.WriteLine( $"episodeNumber : {Episode.AppropriateSeasonNumber}{Episode.AppropriateEpNum:0#}"); writer.WriteLine("isEpisode : true"); writer.WriteLine($"description : {Episode.Overview}"); if (Episode.FirstAired != null) { writer.WriteLine($"originalAirDate : {Episode.FirstAired.Value:yyyy-MM-dd}T00:00:00Z"); } writer.WriteLine($"callsign : {Episode.Show.TheSeries()?.Network}"); WriteEntries(writer, "vDirector", Episode.EpisodeDirector); WriteEntries(writer, "vWriter", Episode.Writer); WriteEntries(writer, "vActor", string.Join("|", Episode.Show.GetActorNames())); WriteEntries(writer, "vGuestStar", Episode.EpisodeGuestStars); // not worrying about actors being repeated WriteEntries(writer, "vProgramGenre", string.Join("|", Episode.Show.Genres)); } Done = true; return(true); } catch (Exception e) { ErrorText = e.Message; LastError = e; Error = true; Done = true; return(false); } }
public bool Go(ref bool pause, TVRenameStats stats) { XmlWriterSettings settings = new XmlWriterSettings { Indent = true, NewLineOnAttributes = true }; // "try" and silently fail. eg. when file is use by other... XmlWriter writer; try { writer = XmlWriter.Create(this.Where.FullName, settings); if (writer == null) { return(false); } } catch (Exception) { this.Done = true; return(true); } writer.WriteStartElement("FolderTag"); // is it a show or season folder if (snum >= 0) { // if episode thumbnails are generated, use ViewMode Photo, otherwise use List if (TVSettings.Instance.EpJPGs) { XMLHelper.WriteElementToXML(writer, "ViewMode", "Photo"); } else { XMLHelper.WriteElementToXML(writer, "ViewMode", "List"); } XMLHelper.WriteElementToXML(writer, "ViewType", "Video"); } else { XMLHelper.WriteElementToXML(writer, "ViewMode", "Preview"); } writer.WriteEndElement(); writer.Close(); this.Done = true; return(true); }
private void DoCopyRename(TVRenameStats stats) { try { //we use a temp name just in case we are interrupted or some other problem occurs string tempName = TempFor(To); // If both full filenames are the same then we want to move it away and back //This deals with an issue on some systems (XP?) that case insensitive moves did not occur if (IsMoveRename() || FileHelper.Same(From, To)) { // This step could be slow, so report progress CopyMoveResult moveResult = File.Move(From.FullName, tempName, MoveOptions.CopyAllowed | MoveOptions.ReplaceExisting, CopyProgressCallback, null); if (moveResult.ErrorCode != 0) { throw new TheTVDB.TVDBException(moveResult.ErrorMessage); } } else { //we are copying Debug.Assert(Operation == Op.copy); // This step could be slow, so report progress CopyMoveResult copyResult = File.Copy(From.FullName, tempName, CopyOptions.None, true, CopyProgressCallback, null); if (copyResult.ErrorCode != 0) { throw new TheTVDB.TVDBException(copyResult.ErrorMessage); } } // Copying the temp file into the correct name is very quick, so no progress reporting File.Move(tempName, To.FullName, MoveOptions.ReplaceExisting); LOGGER.Info($"{Name} completed: {From.FullName} to {To.FullName } "); Done = true; UpdateStats(stats); } catch (Exception e) { LOGGER.Warn(e, $"Error occurred while {Name}: {From.FullName} to {To.FullName } "); Done = true; Error = true; ErrorText = e.Message; LastError = e; } }
public override ActionOutcome Go(TVRenameStats stats) { bool isDownloadable = url.IsWebLink(); try { try { if (TVSettings.Instance.CheckuTorrent && isDownloadable) { FileInfo downloadedFile = DownloadFile(); new uTorrent().StartTorrentDownload(downloadedFile); return(ActionOutcome.Success()); } if (TVSettings.Instance.CheckqBitTorrent) { if (isDownloadable && TVSettings.Instance.qBitTorrentDownloadFilesFirst) { FileInfo downloadedFile = DownloadFile(); new qBitTorrent().StartTorrentDownload(downloadedFile); return(ActionOutcome.Success()); } else { new qBitTorrent().StartUrlDownload(url); return(ActionOutcome.Success()); } } } catch (DownloadFailedException e) { //Don't worry about this error, we'll retry below } if (Helpers.OpenUrl(url)) { return(ActionOutcome.Success()); } return(new ActionOutcome("No torrent clients enabled to download RSS - Tried to use system open, but failed")); } catch (Exception e) { return(new ActionOutcome(e)); } }
public bool Go(TVSettings tvsettings, ref bool pause, TVRenameStats stats) { // "try" and silently fail. eg. when file is use by other... StreamWriter writer; try { // create folder if it does not exist. (Only really applies when .meta\ folder is being used.) if (!this.Where.Directory.Exists) { this.Where.Directory.Create(); } writer = new StreamWriter(this.Where.FullName); if (writer == null) { return(false); } } catch (Exception) { this.Done = true; return(true); } // See: http://pytivo.sourceforge.net/wiki/index.php/Metadata writer.WriteLine(string.Format("title : {0}", this.Episode.SI.ShowName)); writer.WriteLine(string.Format("seriesTitle : {0}", this.Episode.SI.ShowName)); writer.WriteLine(string.Format("episodeTitle : {0}", this.Episode.Name)); writer.WriteLine(string.Format("episodeNumber : {0}{1:0#}", this.Episode.SeasonNumber, this.Episode.EpNum)); writer.WriteLine("isEpisode : true"); writer.WriteLine(string.Format("description : {0}", this.Episode.Overview)); if (this.Episode.FirstAired != null) { writer.WriteLine(string.Format("originalAirDate : {0:yyyy-MM-dd}T00:00:00Z", this.Episode.FirstAired.Value)); } writer.WriteLine(string.Format("callsign : {0}", this.Episode.SI.TheSeries().GetItem("Network"))); WriteEntries(writer, "vDirector", this.Episode.EpisodeDirector); WriteEntries(writer, "vWriter", this.Episode.Writer); WriteEntries(writer, "vActor", this.Episode.SI.TheSeries().GetItem("Actors")); WriteEntries(writer, "vGuestStar", this.Episode.EpisodeGuestStars); // not worring about actors being repeated WriteEntries(writer, "vProgramGenre", this.Episode.SI.TheSeries().GetItem("Genre")); writer.Close(); this.Done = true; return(true); }
public override ActionOutcome Go(TVRenameStats stats) { try { ProcessFile(WhereFile, UpdateTime); } catch (UnauthorizedAccessException uae) { return(new ActionOutcome(uae)); } catch (Exception e) { return(new ActionOutcome(e)); } return(ActionOutcome.Success()); }
public override bool Go(TVRenameStats stats) { // read NTFS permissions (if any) FileSecurity security = null; try { security = From.GetAccessControl(); } catch { // ignored } DoCopyRename(stats); if (To.IsMovieFile()) { //File is correct name LOGGER.Debug($"Just copied {To.FullName} to the right place. Marking it as 'seen'."); //Record this episode as seen TVSettings.Instance.PreviouslySeenEpisodes.EnsureAdded(Episode); if (TVSettings.Instance.IgnorePreviouslySeen) { doc.SetDirty(); } } // set NTFS permissions try { if (security != null) { To.SetAccessControl(security); } } catch { // ignored } TidyUpIfNeeded(); return(!Error); }
public bool Go(TVSettings tvsettings, ref bool pause, TVRenameStats stats) { // "try" and silently fail. eg. when file is use by other... StreamWriter writer; try { // create folder if it does not exist. (Only really applies when .meta\ folder is being used.) if (!this.Where.Directory.Exists) this.Where.Directory.Create(); writer = new StreamWriter(this.Where.FullName); if (writer == null) return false; } catch (Exception) { this.Done = true; return true; } // See: http://pytivo.sourceforge.net/wiki/index.php/Metadata writer.WriteLine(string.Format("title : {0}", this.Episode.SI.ShowName)); writer.WriteLine(string.Format("seriesTitle : {0}", this.Episode.SI.ShowName)); writer.WriteLine(string.Format("episodeTitle : {0}", this.Episode.Name)); writer.WriteLine(string.Format("episodeNumber : {0}{1:0#}", this.Episode.SeasonNumber, this.Episode.EpNum)); writer.WriteLine("isEpisode : true"); writer.WriteLine(string.Format("description : {0}", this.Episode.Overview)); if (this.Episode.FirstAired != null) writer.WriteLine(string.Format("originalAirDate : {0:yyyy-MM-dd}T00:00:00Z",this.Episode.FirstAired.Value)); writer.WriteLine(string.Format("callsign : {0}", this.Episode.SI.TheSeries().GetItem("Network"))); WriteEntries(writer, "vDirector", this.Episode.EpisodeDirector); WriteEntries(writer, "vWriter", this.Episode.Writer); WriteEntries(writer, "vActor", this.Episode.SI.TheSeries().GetItem("Actors")); WriteEntries(writer, "vGuestStar", this.Episode.EpisodeGuestStars); // not worring about actors being repeated WriteEntries(writer, "vProgramGenre", this.Episode.SI.TheSeries().GetItem("Genre")); writer.Close(); this.Done = true; return true; }
}; // TODO: move into settings, and allow user to edit these public TVDoc(FileInfo settingsFile, CommandLineArgs args) { this.Args = args; this.Ignore = new List<IgnoreItem>(); this.Workers = null; this.WorkerSemaphore = null; this.mStats = new TVRenameStats(); this.mDirty = false; this.TheActionList = new ItemList(); this.MonitorFolders = new List<String>(); this.IgnoreFolders = new List<String>(); this.SearchFolders = new List<String>(); ShowItems = new List<ShowItem>(); this.AddItems = new FolderMonitorEntryList(); this.DownloadDone = true; this.DownloadOK = true; this.ActionCancel = false; this.ScanProgDlg = null; this.Finders = new List<Finder> (); this.Finders.Add(new FileFinder(this)); this.Finders.Add(new RSSFinder(this)); this.Finders.Add(new uTorrentFinder(this)); this.Finders.Add(new SABnzbdFinder(this)); this.LoadOK = ((settingsFile == null) || this.LoadXMLSettings(settingsFile)) && TheTVDB.Instance.LoadOK; this.DownloadIdentifiers = new DownloadIdentifiersController(); UpdateTVDBLanguage(); // StartServer(); }
public bool Go(ref bool pause, TVRenameStats stats) { XmlWriterSettings settings = new XmlWriterSettings { Indent = true, NewLineOnAttributes = true }; // "try" and silently fail. eg. when file is use by other... XmlWriter writer; try { // XmlWriter writer = XmlWriter.Create(this.Where.FullName, settings); writer = XmlWriter.Create(this.Where.FullName, settings); if (writer == null) return false; } catch (Exception) { this.Done = true; return true; } if (this.Episode != null) // specific episode { // See: http://xbmc.org/wiki/?title=Import_-_Export_Library#TV_Episodes writer.WriteStartElement("details"); writer.WriteStartElement("movie"); XMLHelper.WriteElementToXML(writer,"title",this.Episode.Name); XMLHelper.WriteElementToXML(writer,"season",this.Episode.SeasonNumber); XMLHelper.WriteElementToXML(writer,"episode",this.Episode.EpNum); writer.WriteStartElement("year"); if (this.Episode.FirstAired != null) writer.WriteValue(this.Episode.FirstAired.Value.ToString("yyyy")); writer.WriteEndElement(); writer.WriteStartElement("rating"); string rating = (this.Episode.EpisodeRating); if (!string.IsNullOrEmpty(rating)) { rating = rating.Trim('.'); rating = rating.Replace(".", ""); writer.WriteValue(rating); } writer.WriteEndElement(); // rating //Get the Series OverView string sov = this.Episode.SI.TheSeries().GetItem("Overview"); if (!string.IsNullOrEmpty(sov)) { XMLHelper.WriteElementToXML(writer,"plot",sov); } //Get the Episode overview XMLHelper.WriteElementToXML(writer,"episodeplot",this.Episode.Overview); if (this.Episode.SI != null) { WriteInfo(writer, this.Episode.SI, "ContentRating", "mpaa"); } //Runtime...taken from overall Series, not episode specific due to thetvdb string rt = this.Episode.SI.TheSeries().GetItem("Runtime"); if (!string.IsNullOrEmpty(rt)) { XMLHelper.WriteElementToXML(writer,"runtime",rt + " min"); } //Genres...taken from overall Series, not episode specific due to thetvdb writer.WriteStartElement("genres"); string genre = this.Episode.SI.TheSeries().GetItem("Genre"); if (!string.IsNullOrEmpty(genre)) { genre = genre.Trim('|'); genre = genre.Replace("|", " / "); XMLHelper.WriteElementToXML(writer,"genre",genre); } writer.WriteEndElement(); // genres //Director(s) if (!String.IsNullOrEmpty(this.Episode.EpisodeDirector)) { string EpDirector = this.Episode.EpisodeDirector; if (!string.IsNullOrEmpty(EpDirector)) { foreach (string Daa in EpDirector.Split('|')) { if (string.IsNullOrEmpty(Daa)) continue; XMLHelper.WriteElementToXML(writer,"director",Daa); } } } //Writers(s) if (!String.IsNullOrEmpty(this.Episode.Writer)) { string EpWriter = this.Episode.Writer; if (!string.IsNullOrEmpty(EpWriter)) { XMLHelper.WriteElementToXML(writer,"credits",EpWriter); } } writer.WriteStartElement("cast"); // actors... if (this.Episode.SI != null) { string actors = this.Episode.SI.TheSeries().GetItem("Actors"); if (!string.IsNullOrEmpty(actors)) { foreach (string aa in actors.Split('|')) { if (string.IsNullOrEmpty(aa)) continue; XMLHelper.WriteElementToXML(writer,"actor",aa); } } } writer.WriteEndElement(); // cast writer.WriteEndElement(); // movie writer.WriteEndElement(); // details } else if (this.SI != null) // show overview (Series.xml) { // http://www.xbmc.org/wiki/?title=Import_-_Export_Library#TV_Shows writer.WriteStartElement("details"); writer.WriteStartElement("movie"); XMLHelper.WriteElementToXML(writer,"title",this.SI.ShowName); writer.WriteStartElement("genres"); string genre = this.SI.TheSeries().GetItem("Genre"); if (!string.IsNullOrEmpty(genre)) { genre = genre.Trim('|'); genre = genre.Replace("|", " / "); XMLHelper.WriteElementToXML(writer,"genre",genre); } writer.WriteEndElement(); // genres WriteInfo(writer, this.SI, "FirstAired", "premiered"); WriteInfo(writer, this.SI, "Year", "year"); writer.WriteStartElement("rating"); string rating = this.SI.TheSeries().GetItem("Rating"); if (!string.IsNullOrEmpty(rating)) { rating = rating.Trim('.'); rating = rating.Replace(".", ""); writer.WriteValue(rating); } writer.WriteEndElement(); // rating WriteInfo(writer, this.SI, "Status", "status"); WriteInfo(writer, this.SI, "ContentRating", "mpaa"); WriteInfo(writer, this.SI, "IMDB_ID", "id", "moviedb", "imdb"); XMLHelper.WriteElementToXML(writer,"tvdbid",this.SI.TheSeries().TVDBCode); string rt = this.SI.TheSeries().GetItem("Runtime"); if (!string.IsNullOrEmpty(rt)) { XMLHelper.WriteElementToXML(writer,"runtime",rt + " min"); } WriteInfo(writer, this.SI, "Overview", "plot"); writer.WriteStartElement("cast"); // actors... string actors = this.SI.TheSeries().GetItem("Actors"); if (!string.IsNullOrEmpty(actors)) { foreach (string aa in actors.Split('|')) { if (string.IsNullOrEmpty(aa)) continue; XMLHelper.WriteElementToXML(writer,"actor",aa); } } writer.WriteEndElement(); // cast writer.WriteEndElement(); // movie writer.WriteEndElement(); // tvshow } writer.Close(); this.Done = true; return true; }
public bool Go(ref bool pause, TVRenameStats stats) { byte[] theData = TheTVDB.Instance.GetPage(this.BannerPath, false, typeMaskBits.tmBanner, false); if ((theData == null) || (theData.Length == 0)) { this.ErrorText = "Unable to download " + this.BannerPath; this.Error = true; this.Done = true; return false; } if (ShrinkLargeMede8erImage) { // shrink images down to a maximum size of 156x232 Image im = new Bitmap(new MemoryStream(theData)); if ((im.Width > 156) || (im.Height > 232)) { im = MaxSize(im, 156, 232); using (MemoryStream m = new MemoryStream()) { im.Save(m, ImageFormat.Jpeg); theData = m.ToArray(); } } } try { FileStream fs = new FileStream(this.Destination.FullName, FileMode.Create); fs.Write(theData, 0, theData.Length); fs.Close(); } catch (Exception e) { this.ErrorText = e.Message; this.Error = true; this.Done = true; return false; } this.Done = true; return true; }
public bool LoadXMLSettings(FileInfo from) { if (from == null) return true; try { XmlReaderSettings settings = new XmlReaderSettings { IgnoreComments = true, IgnoreWhitespace = true }; if (!from.Exists) { //LoadErr = from->Name + " : File does not exist"; //return false; return true; // that's ok } XmlReader reader = XmlReader.Create(from.FullName, settings); reader.Read(); if (reader.Name != "xml") { this.LoadErr = from.Name + " : Not a valid XML file"; return false; } reader.Read(); if (reader.Name != "TVRename") { this.LoadErr = from.Name + " : Not a TVRename settings file"; return false; } if (reader.GetAttribute("Version") != "2.1") { this.LoadErr = from.Name + " : Incompatible version"; return false; } reader.Read(); // move forward one while (!reader.EOF) { if (reader.Name == "TVRename" && !reader.IsStartElement()) break; // end of it all if (reader.Name == "Settings") { this.Settings = new TVSettings(reader.ReadSubtree()); reader.Read(); } else if (reader.Name == "MyShows") { XmlReader r2 = reader.ReadSubtree(); r2.Read(); r2.Read(); while (!r2.EOF) { if ((r2.Name == "MyShows") && (!r2.IsStartElement())) break; if (r2.Name == "ShowItem") { ShowItem si = new ShowItem(this.mTVDB, r2.ReadSubtree(), this.Settings); if (si.UseCustomShowName) // see if custom show name is actually the real show name { SeriesInfo ser = si.TheSeries(); if ((ser != null) && (si.CustomShowName == ser.Name)) { // then, turn it off si.CustomShowName = ""; si.UseCustomShowName = false; } } ShowItems.Add(si); r2.Read(); } else r2.ReadOuterXml(); } reader.Read(); } else if (reader.Name == "MonitorFolders") this.MonitorFolders = ReadStringsFromXml(reader, "MonitorFolders", "Folder"); else if (reader.Name == "IgnoreFolders") this.IgnoreFolders = ReadStringsFromXml(reader, "IgnoreFolders", "Folder"); else if (reader.Name == "FinderSearchFolders") this.SearchFolders = ReadStringsFromXml(reader, "FinderSearchFolders", "Folder"); else if (reader.Name == "IgnoreItems") { XmlReader r2 = reader.ReadSubtree(); r2.Read(); r2.Read(); while (r2.Name == "Ignore") this.Ignore.Add(new IgnoreItem(r2)); reader.Read(); } else reader.ReadOuterXml(); } reader.Close(); reader = null; } catch (Exception e) { this.LoadErr = from.Name + " : " + e.Message; return false; } try { mStats = TVRenameStats.Load(); } catch (Exception) { // not worried if stats loading fails } return true; }
public StatsWindow(TVRenameStats s) { this.Stats = s; this.InitializeComponent(); }
public bool Go(TVSettings tvsettings, ref bool pause, TVRenameStats stats) { XmlWriterSettings settings = new XmlWriterSettings { Indent = true, NewLineOnAttributes = true }; // "try" and silently fail. eg. when file is use by other... XmlWriter writer; try { // XmlWriter writer = XmlWriter.Create(this.Where.FullName, settings); writer = XmlWriter.Create(this.Where.FullName, settings); if (writer == null) return false; } catch (Exception) { this.Done = true; return true; } if (this.Episode != null) // specific episode { // See: http://xbmc.org/wiki/?title=Import_-_Export_Library#TV_Episodes writer.WriteStartElement("episodedetails"); writer.WriteStartElement("title"); writer.WriteValue(this.Episode.Name); writer.WriteEndElement(); writer.WriteStartElement("rating"); writer.WriteValue(this.Episode.EpisodeRating); writer.WriteEndElement(); writer.WriteStartElement("season"); writer.WriteValue(this.Episode.SeasonNumber); writer.WriteEndElement(); writer.WriteStartElement("episode"); writer.WriteValue(this.Episode.EpNum); writer.WriteEndElement(); writer.WriteStartElement("plot"); writer.WriteValue(this.Episode.Overview); writer.WriteEndElement(); writer.WriteStartElement("aired"); if (this.Episode.FirstAired != null) writer.WriteValue(this.Episode.FirstAired.Value.ToString("yyyy-MM-dd")); writer.WriteEndElement(); if (this.Episode.SI != null) { WriteInfo(writer, this.Episode.SI, "ContentRating", "mpaa"); } //Director(s) if (!String.IsNullOrEmpty(this.Episode.EpisodeDirector)) { string EpDirector = this.Episode.EpisodeDirector; if (!string.IsNullOrEmpty(EpDirector)) { foreach (string Daa in EpDirector.Split('|')) { if (string.IsNullOrEmpty(Daa)) continue; writer.WriteStartElement("director"); writer.WriteValue(Daa); writer.WriteEndElement(); } } } //Writers(s) if (!String.IsNullOrEmpty(this.Episode.Writer)) { string EpWriter = this.Episode.Writer; if (!string.IsNullOrEmpty(EpWriter)) { writer.WriteStartElement("credits"); writer.WriteValue(EpWriter); writer.WriteEndElement(); } } // Guest Stars... if (!String.IsNullOrEmpty(this.Episode.EpisodeGuestStars)) { string RecurringActors = ""; if (this.Episode.SI != null) { RecurringActors = this.Episode.SI.TheSeries().GetItem("Actors"); } string GuestActors = this.Episode.EpisodeGuestStars; if (!string.IsNullOrEmpty(GuestActors)) { foreach (string Gaa in GuestActors.Split('|')) { if (string.IsNullOrEmpty(Gaa)) continue; // Skip if the guest actor is also in the overal recurring list if (!string.IsNullOrEmpty(RecurringActors) && RecurringActors.Contains(Gaa)) { continue; } writer.WriteStartElement("actor"); writer.WriteStartElement("name"); writer.WriteValue(Gaa); writer.WriteEndElement(); // name writer.WriteEndElement(); // actor } } } // actors... if (this.Episode.SI != null) { string actors = this.Episode.SI.TheSeries().GetItem("Actors"); if (!string.IsNullOrEmpty(actors)) { foreach (string aa in actors.Split('|')) { if (string.IsNullOrEmpty(aa)) continue; writer.WriteStartElement("actor"); writer.WriteStartElement("name"); writer.WriteValue(aa); writer.WriteEndElement(); // name writer.WriteEndElement(); // actor } } } writer.WriteEndElement(); // episodedetails } else if (this.SI != null) // show overview (tvshow.nfo) { // http://www.xbmc.org/wiki/?title=Import_-_Export_Library#TV_Shows writer.WriteStartElement("tvshow"); writer.WriteStartElement("title"); writer.WriteValue(this.SI.ShowName); writer.WriteEndElement(); writer.WriteStartElement("episodeguideurl"); writer.WriteValue(TheTVDB.BuildURL(true, true, this.SI.TVDBCode, this.SI.TVDB.RequestLanguage)); writer.WriteEndElement(); WriteInfo(writer, this.SI, "Overview", "plot"); string genre = this.SI.TheSeries().GetItem("Genre"); if (!string.IsNullOrEmpty(genre)) { genre = genre.Trim('|'); genre = genre.Replace("|", " / "); writer.WriteStartElement("genre"); writer.WriteValue(genre); writer.WriteEndElement(); } WriteInfo(writer, this.SI, "FirstAired", "premiered"); WriteInfo(writer, this.SI, "Year", "year"); WriteInfo(writer, this.SI, "Rating", "rating"); WriteInfo(writer, this.SI, "Status", "status"); // actors... string actors = this.SI.TheSeries().GetItem("Actors"); if (!string.IsNullOrEmpty(actors)) { foreach (string aa in actors.Split('|')) { if (string.IsNullOrEmpty(aa)) continue; writer.WriteStartElement("actor"); writer.WriteStartElement("name"); writer.WriteValue(aa); writer.WriteEndElement(); // name writer.WriteEndElement(); // actor } } WriteInfo(writer, this.SI, "ContentRating", "mpaa"); WriteInfo(writer, this.SI, "IMDB_ID", "id", "moviedb","imdb"); writer.WriteStartElement("tvdbid"); writer.WriteValue(this.SI.TheSeries().TVDBCode); writer.WriteEndElement(); string rt = this.SI.TheSeries().GetItem("Runtime"); if (!string.IsNullOrEmpty(rt)) { writer.WriteStartElement("runtime"); writer.WriteValue(rt + " minutes"); writer.WriteEndElement(); } writer.WriteEndElement(); // tvshow } writer.Close(); this.Done = true; return true; }
private void OSMoveRename(TVRenameStats stats) { try { if (Helpers.Same(this.From, this.To)) { // XP won't actually do a rename if its only a case difference string tempName = TempFor(this.To); this.From.MoveTo(tempName); File.Move(tempName, this.To.FullName); } else this.From.MoveTo(this.To.FullName); KeepTimestamps(this.From, this.To); this.Done = true; System.Diagnostics.Debug.Assert((this.Operation == ActionCopyMoveRename.Op.Move) || (this.Operation == ActionCopyMoveRename.Op.Rename)); if (this.Operation == ActionCopyMoveRename.Op.Move) stats.FilesMoved++; else if (this.Operation == ActionCopyMoveRename.Op.Rename) stats.FilesRenamed++; } catch (System.Exception e) { this.Done = true; this.Error = true; this.ErrorText = e.Message; } }
private void CopyItOurself(ref bool pause, TVRenameStats stats) { const int kArrayLength = 1 * 1024 * 1024; Byte[] dataArray = new Byte[kArrayLength]; bool useWin32 = Version.OnWindows() && !Version.OnMono(); Win32FileIO.WinFileIO copier = null; BinaryReader msr = null; BinaryWriter msw = null; try { long thisFileCopied = 0; long thisFileSize = this.SourceFileSize(); string tempName = TempFor(this.To); if (File.Exists(tempName)) File.Delete(tempName); if (useWin32) { copier = new Win32FileIO.WinFileIO(dataArray); copier.OpenForReading(this.From.FullName); copier.OpenForWriting(tempName); } else { msr = new BinaryReader(new FileStream(this.From.FullName, FileMode.Open, FileAccess.Read)); msw = new BinaryWriter(new FileStream(tempName, FileMode.CreateNew)); } for (;;) { int n = useWin32 ? copier.ReadBlocks(kArrayLength) : msr.Read(dataArray, 0, kArrayLength); if (n == 0) break; if (useWin32) { copier.WriteBlocks(n); } else { msw.Write(dataArray, 0, n); } thisFileCopied += n; double pct = (thisFileSize != 0) ? (100.0 * thisFileCopied / thisFileSize) : this.Done ? 100 : 0; if (pct > 100.0) pct = 100.0; this.PercentDone = pct; while (pause) System.Threading.Thread.Sleep(100); } if (useWin32) { copier.Close(); } else { msr.Close(); msw.Close(); } // rename temp version to final name if (this.To.Exists) this.To.Delete(); // outta ma way! File.Move(tempName, this.To.FullName); KeepTimestamps(this.From, this.To); // if that was a move/rename, delete the source if (this.IsMoveRename()) this.From.Delete(); if (this.Operation == ActionCopyMoveRename.Op.Move) stats.FilesMoved++; else if (this.Operation == ActionCopyMoveRename.Op.Rename) stats.FilesRenamed++; else if (this.Operation == ActionCopyMoveRename.Op.Copy) stats.FilesCopied++; this.Done = true; } // try catch (System.Threading.ThreadAbortException) { if (useWin32) { this.NicelyStopAndCleanUp_Win32(copier); } else { this.NicelyStopAndCleanUp_Streams(msr, msw); } return; } catch (Exception ex) { // handle any exception type this.Error = true; this.Done = true; this.ErrorText = ex.Message; if (useWin32) { this.NicelyStopAndCleanUp_Win32(copier); } else { this.NicelyStopAndCleanUp_Streams(msr, msw); } } }