public bool Scrobble(string filename) { StopScrobble(); if (!g_Player.IsTVRecording) { return(false); } // get recording details from tv database ControlServiceAgent layer = new ControlServiceAgent(); Recording recording = layer.GetRecordingByFileName(filename); if (recording == null || string.IsNullOrEmpty(recording.Title)) { TraktLogger.Info("Unable to get recording details from argus database."); return(false); } // get year from title if available, some EPG entries contain this string title = null; string year = null; BasicHandler.GetTitleAndYear(recording.Title, out title, out year); CurrentRecording = new VideoInfo { Type = recording.EpisodeNumber != null || recording.SeriesNumber != null ? VideoType.Series : VideoType.Movie, Title = title, Year = year, SeasonIdx = recording.SeriesNumber == null ? null : recording.SeriesNumber.ToString(), EpisodeIdx = recording.EpisodeNumber == null ? null : recording.EpisodeNumber.ToString(), IsScrobbling = true }; TraktLogger.Info("Current program details. Title='{0}', Year='{1}', Season='{2}', Episode='{3}', StartTime='{4}', Runtime='{5}'", CurrentRecording.Title, CurrentRecording.Year.ToLogString(), CurrentRecording.SeasonIdx.ToLogString(), CurrentRecording.EpisodeIdx.ToLogString(), CurrentRecording.StartTime == null ? "<empty>" : CurrentRecording.StartTime.ToString(), CurrentRecording.Runtime); if (CurrentRecording.Type == VideoType.Series) { TraktLogger.Info("Detected tv show playing in Argus TV Recordings. Title = '{0}'", CurrentRecording.ToString()); } else { TraktLogger.Info("Detected movie playing in Argus TV Recordings. Title = '{0}'", CurrentRecording.ToString()); } BasicHandler.StartScrobble(CurrentRecording); return(true); }
public bool Scrobble(string filename) { StopScrobble(); if (!g_Player.IsTVRecording) return false; // get recording details from tv database ControlServiceAgent layer = new ControlServiceAgent(); Recording recording = layer.GetRecordingByFileName(filename); if (recording == null || string.IsNullOrEmpty(recording.Title)) { TraktLogger.Info("Unable to get recording details from argus database."); return false; } // get year from title if available, some EPG entries contain this string title = null; string year = null; BasicHandler.GetTitleAndYear(recording.Title, out title, out year); CurrentRecording = new VideoInfo { Type = recording.EpisodeNumber != null || recording.SeriesNumber != null ? VideoType.Series : VideoType.Movie, Title = title, Year = year, SeasonIdx = recording.SeriesNumber == null ? null : recording.SeriesNumber.ToString(), EpisodeIdx = recording.EpisodeNumber == null ? null : recording.EpisodeNumber.ToString(), IsScrobbling = true }; TraktLogger.Info("Current program details. Title='{0}', Year='{1}', Season='{2}', Episode='{3}', StartTime='{4}', Runtime='{5}'", CurrentRecording.Title, CurrentRecording.Year.ToLogString(), CurrentRecording.SeasonIdx.ToLogString(), CurrentRecording.EpisodeIdx.ToLogString(), CurrentRecording.StartTime == null ? "<empty>" : CurrentRecording.StartTime.ToString(), CurrentRecording.Runtime); if (CurrentRecording.Type == VideoType.Series) { TraktLogger.Info("Detected tv show playing in Argus TV Recordings. Title = '{0}'", CurrentRecording.ToString()); } else { TraktLogger.Info("Detected movie playing in Argus TV Recordings. Title = '{0}'", CurrentRecording.ToString()); } BasicHandler.StartScrobble(CurrentRecording); return true; }
static int Main(string[] args) { try { if (args.Length > 0 && String.Equals(args[0], "Help", StringComparison.InvariantCultureIgnoreCase)) { ShowHelp(); } else if (args.Length >= 2 && String.Equals(args[0], "MyVideo", StringComparison.InvariantCultureIgnoreCase)) { InitializeServiceChannelFactories(); Log(LogSeverity.Information, "Creating MP xml"); if (ServiceChannelFactories.IsInitialized) { using (ControlServiceAgent controlServiceAgent = new ControlServiceAgent()) { string recordedFileName = args[1]; Recording recording = controlServiceAgent.GetRecordingByFileName(recordedFileName); if (recording != null) { Tags tags = new Tags(); tags.SimpleTags.Add(new SimpleTag("TITLE", recording.Title)); tags.SimpleTags.Add(new SimpleTag("COMMENT", recording.Description)); tags.SimpleTags.Add(new SimpleTag("GENRE", recording.Category)); tags.SimpleTags.Add(new SimpleTag("CHANNEL_NAME", recording.ChannelDisplayName)); string myVideoFileName = Path.ChangeExtension(recordedFileName, "xml"); FileStream outFile = new FileStream(myVideoFileName, FileMode.Create, FileAccess.Write, FileShare.None); try { XmlSerializerNamespaces nspaces = new XmlSerializerNamespaces(); nspaces.Add(String.Empty, String.Empty); XmlSerializer serializer = new XmlSerializer(typeof(Tags)); serializer.Serialize(outFile, tags, nspaces); } catch (SerializationException ex) { Debug.WriteLine("Failed to serialize. Reason: " + ex.Message, "Error"); } catch (Exception ex) { Debug.WriteLine(ex.Message); } finally { outFile.Close(); } } else { Log(LogSeverity.Error, string.Format("Failed to find recording \"{0}\"", recordedFileName)); } } } } else if (args.Length == 2 && String.Equals(args[0], "Log", StringComparison.InvariantCultureIgnoreCase)) { Log(LogSeverity.Information, args[1]); } else if (args.Length >= 3 && String.Equals(args[0], "Delete", StringComparison.InvariantCultureIgnoreCase)) { InitializeServiceChannelFactories(); Log(LogSeverity.Information, string.Format("Deleting {0} from ARGUS TV {1} the actual recording", args[1], (args[2] == "1" ? "and" : "but not"))); if (ServiceChannelFactories.IsInitialized) { using (ControlServiceAgent controlServiceAgent = new ControlServiceAgent()) { string recordedFileName = args[1]; Boolean keepGile = (args[2] == "1" ? true : false); controlServiceAgent.DeleteRecording(recordedFileName, keepGile); } } } else if (args.Length == 4 && String.Equals(args[0], "description", StringComparison.InvariantCultureIgnoreCase)) { InitializeServiceChannelFactories(); string recordedFileName = args[1]; string outputFileName = Path.ChangeExtension(args[1], args[2]); string fileString = args[3].ToLower(); Log(LogSeverity.Information, string.Format("Creating description file for {0} called {1}", args[1], outputFileName)); if (ServiceChannelFactories.IsInitialized) { using (ControlServiceAgent controlServiceAgent = new ControlServiceAgent()) { Recording tvRecording = controlServiceAgent.GetRecordingByFileName(recordedFileName); fileString = fileString.Replace("{description}", tvRecording.Description); fileString = fileString.Replace("{starttime}", tvRecording.StartTime.ToString()); fileString = fileString.Replace("{stoptime}", tvRecording.StopTime.ToString()); fileString = fileString.Replace("{title}", tvRecording.Title.ToString()); fileString = fileString.Replace("{episodenumber}", tvRecording.EpisodeNumber.ToString()); fileString = fileString.Replace("{seriesnumber}", tvRecording.SeriesNumber.ToString()); using (StreamWriter descriptionfile = new StreamWriter(outputFileName, false, Encoding.UTF8)) { descriptionfile.WriteLine(fileString); } } } } else if (args.Length >= 3 && String.Equals(args[0], "Rename", StringComparison.InvariantCultureIgnoreCase)) { InitializeServiceChannelFactories(); Log(LogSeverity.Information, string.Format("Renaming {0} to {1}", args[1], args[2])); if (ServiceChannelFactories.IsInitialized) { using (ControlServiceAgent controlServiceAgent = new ControlServiceAgent()) { string recordedFileName = args[1]; string newFileName = args[2]; Recording recording; using (ControlServiceAgent controlAgent = new ControlServiceAgent()) { recording = controlAgent.GetRecordingByFileName(newFileName); } if (recording == null) { string lUncPath; if (newFileName.StartsWith("\\")) lUncPath = newFileName; else { try { lUncPath = GetUncPath(newFileName); } catch (IOException) { Console.Error.WriteLine("Could not get a UNC path for recording"); Log(LogSeverity.Warning, string.Format("Could not convert {0} to an unc path", newFileName)); LogArgs(LogSeverity.Information, args); return -2; } } controlServiceAgent.ChangeRecordingFile(recordedFileName, lUncPath, null, null); } else { Console.Error.WriteLine("Could not move recording as another one with same name allready exsist"); Log(LogSeverity.Warning, string.Format("Could not rename as a recording with the name {0} allready exist in database", newFileName)); LogArgs(LogSeverity.Information, args); return -2; } } } } else if (args.Length >= 2 && String.Equals(args[0], "IsPartial", StringComparison.InvariantCultureIgnoreCase)) { InitializeServiceChannelFactories(); if (ServiceChannelFactories.IsInitialized) { using (ControlServiceAgent controlServiceAgent = new ControlServiceAgent()) { string recordedFileName = args[1]; Recording recording; using (ControlServiceAgent controlAgent = new ControlServiceAgent()) { recording = controlAgent.GetRecordingByFileName(recordedFileName); } if (recording != null) return (recording.IsPartialRecording ? -1 : 0); else { Console.Error.WriteLine("Could not check recording as it could not be found in the database"); Log(LogSeverity.Warning, string.Format("{0} not found in the ARGUS TV database", args[1])); LogArgs(LogSeverity.Information, args); return -2; } } } else { return -2; } } else if (args.Length >= 2 && String.Equals(args[0], "Exist", StringComparison.InvariantCultureIgnoreCase)) { InitializeServiceChannelFactories(); if (ServiceChannelFactories.IsInitialized) { using (ControlServiceAgent controlServiceAgent = new ControlServiceAgent()) { string recordedFileName = args[1]; Recording recording; using (ControlServiceAgent controlAgent = new ControlServiceAgent()) { recording = controlAgent.GetRecordingByFileName(recordedFileName); } if (recording != null) return 0; else return -1; } } else { return -2; } } else if (args.Length >= 1 && String.Equals(args[0], "Wake", StringComparison.InvariantCultureIgnoreCase)) { } else { Log(LogSeverity.Warning, "Batch processor did not get valid command(s)"); LogArgs(LogSeverity.Information, args); } } catch { return -2; } if (ServiceChannelFactories.IsInitialized) return 0; else return -3; }
public bool Scrobble(string filename) { StopScrobble(); if (!g_Player.IsTVRecording) { return(false); } // get recording details from tv database ControlServiceAgent layer = new ControlServiceAgent(); Recording recording = layer.GetRecordingByFileName(filename); if (recording == null || string.IsNullOrEmpty(recording.Title)) { TraktLogger.Info("Unable to get recording details from argus database."); return(false); } // get year from title if available, some EPG entries contain this string title = null; string year = null; GetTitleAndYear(recording, out title, out year); CurrentRecording = new VideoInfo { Type = recording.EpisodeNumber != null || recording.SeriesNumber != null ? VideoType.Series : VideoType.Movie, Title = title, Year = year, SeasonIdx = recording.SeriesNumber == null ? null : recording.SeriesNumber.ToString(), EpisodeIdx = recording.EpisodeNumber == null ? null : recording.EpisodeNumber.ToString(), IsScrobbling = true }; if (CurrentRecording.Type == VideoType.Series) { TraktLogger.Info("Detected tv-series '{0}' playing in Argus TV-Recordings", CurrentRecording.ToString()); } else { TraktLogger.Info("Detected movie '{0}' playing in Argus TV-Recordings", CurrentRecording.ToString()); } #region scrobble timer TraktTimer = new Timer(new TimerCallback((stateInfo) => { Thread.CurrentThread.Name = "Scrobble"; VideoInfo videoInfo = stateInfo as VideoInfo; // maybe the program does not exist on trakt // ignore in future if it failed previously if (videoInfo.IsScrobbling) { if (videoInfo.Type == VideoType.Series) { videoInfo.IsScrobbling = BasicHandler.ScrobbleEpisode(videoInfo, TraktScrobbleStates.watching); } else { videoInfo.IsScrobbling = BasicHandler.ScrobbleMovie(videoInfo, TraktScrobbleStates.watching); } if (videoInfo.Equals(CurrentRecording)) { CurrentRecording.IsScrobbling = videoInfo.IsScrobbling; } } }), CurrentRecording, 3000, 900000); #endregion return(true); }
public bool Scrobble(string filename) { StopScrobble(); if (!g_Player.IsTVRecording) return false; // get recording details from tv database ControlServiceAgent layer = new ControlServiceAgent(); Recording recording = layer.GetRecordingByFileName(filename); if (recording == null || string.IsNullOrEmpty(recording.Title)) { TraktLogger.Info("Unable to get recording details from argus database."); return false; } // get year from title if available, some EPG entries contain this string title = null; string year = null; GetTitleAndYear(recording, out title, out year); CurrentRecording = new VideoInfo { Type = recording.EpisodeNumber != null || recording.SeriesNumber != null ? VideoType.Series : VideoType.Movie, Title = title, Year = year, SeasonIdx = recording.SeriesNumber == null ? null : recording.SeriesNumber.ToString(), EpisodeIdx = recording.EpisodeNumber == null ? null : recording.EpisodeNumber.ToString(), IsScrobbling = true }; if (CurrentRecording.Type == VideoType.Series) TraktLogger.Info("Detected tv-series '{0}' playing in Argus TV-Recordings", CurrentRecording.ToString()); else TraktLogger.Info("Detected movie '{0}' playing in Argus TV-Recordings", CurrentRecording.ToString()); #region scrobble timer TraktTimer = new Timer(new TimerCallback((stateInfo) => { Thread.CurrentThread.Name = "Scrobble"; VideoInfo videoInfo = stateInfo as VideoInfo; // maybe the program does not exist on trakt // ignore in future if it failed previously if (videoInfo.IsScrobbling) { if (videoInfo.Type == VideoType.Series) { videoInfo.IsScrobbling = BasicHandler.ScrobbleEpisode(videoInfo, TraktScrobbleStates.watching); } else { videoInfo.IsScrobbling = BasicHandler.ScrobbleMovie(videoInfo, TraktScrobbleStates.watching); } if (videoInfo.Equals(CurrentRecording)) CurrentRecording.IsScrobbling = videoInfo.IsScrobbling; } }), CurrentRecording, 3000, 900000); #endregion return true; }
static int Main(string[] args) { try { if (args.Length > 0 && String.Equals(args[0], "Help", StringComparison.InvariantCultureIgnoreCase)) { ShowHelp(); } else if (args.Length >= 2 && String.Equals(args[0], "MyVideo", StringComparison.InvariantCultureIgnoreCase)) { InitializeServiceChannelFactories(); Log(LogSeverity.Information, "Creating MP xml"); if (ServiceChannelFactories.IsInitialized) { using (ControlServiceAgent controlServiceAgent = new ControlServiceAgent()) { string recordedFileName = args[1]; Recording recording = controlServiceAgent.GetRecordingByFileName(recordedFileName); if (recording != null) { Tags tags = new Tags(); tags.SimpleTags.Add(new SimpleTag("TITLE", recording.Title)); tags.SimpleTags.Add(new SimpleTag("COMMENT", recording.Description)); tags.SimpleTags.Add(new SimpleTag("GENRE", recording.Category)); tags.SimpleTags.Add(new SimpleTag("CHANNEL_NAME", recording.ChannelDisplayName)); string myVideoFileName = Path.ChangeExtension(recordedFileName, "xml"); FileStream outFile = new FileStream(myVideoFileName, FileMode.Create, FileAccess.Write, FileShare.None); try { XmlSerializerNamespaces nspaces = new XmlSerializerNamespaces(); nspaces.Add(String.Empty, String.Empty); XmlSerializer serializer = new XmlSerializer(typeof(Tags)); serializer.Serialize(outFile, tags, nspaces); } catch (SerializationException ex) { Debug.WriteLine("Failed to serialize. Reason: " + ex.Message, "Error"); } catch (Exception ex) { Debug.WriteLine(ex.Message); } finally { outFile.Close(); } } else { Log(LogSeverity.Error, string.Format("Failed to find recording \"{0}\"", recordedFileName)); } } } } else if (args.Length == 2 && String.Equals(args[0], "Log", StringComparison.InvariantCultureIgnoreCase)) { Log(LogSeverity.Information, args[1]); } else if (args.Length >= 3 && String.Equals(args[0], "Delete", StringComparison.InvariantCultureIgnoreCase)) { InitializeServiceChannelFactories(); Log(LogSeverity.Information, string.Format("Deleting {0} from ARGUS TV {1} the actual recording", args[1], (args[2] == "1" ? "and" : "but not"))); if (ServiceChannelFactories.IsInitialized) { using (ControlServiceAgent controlServiceAgent = new ControlServiceAgent()) { string recordedFileName = args[1]; Boolean keepGile = (args[2] == "1" ? true : false); controlServiceAgent.DeleteRecording(recordedFileName, keepGile); } } } else if (args.Length == 4 && String.Equals(args[0], "description", StringComparison.InvariantCultureIgnoreCase)) { InitializeServiceChannelFactories(); string recordedFileName = args[1]; string outputFileName = Path.ChangeExtension(args[1], args[2]); string fileString = args[3].ToLower(); Log(LogSeverity.Information, string.Format("Creating description file for {0} called {1}", args[1], outputFileName)); if (ServiceChannelFactories.IsInitialized) { using (ControlServiceAgent controlServiceAgent = new ControlServiceAgent()) { Recording tvRecording = controlServiceAgent.GetRecordingByFileName(recordedFileName); fileString = fileString.Replace("{description}", tvRecording.Description); fileString = fileString.Replace("{starttime}", tvRecording.StartTime.ToString()); fileString = fileString.Replace("{stoptime}", tvRecording.StopTime.ToString()); fileString = fileString.Replace("{title}", tvRecording.Title.ToString()); fileString = fileString.Replace("{episodenumber}", tvRecording.EpisodeNumber.ToString()); fileString = fileString.Replace("{seriesnumber}", tvRecording.SeriesNumber.ToString()); using (StreamWriter descriptionfile = new StreamWriter(outputFileName, false, Encoding.UTF8)) { descriptionfile.WriteLine(fileString); } } } } else if (args.Length >= 3 && String.Equals(args[0], "Rename", StringComparison.InvariantCultureIgnoreCase)) { InitializeServiceChannelFactories(); Log(LogSeverity.Information, string.Format("Renaming {0} to {1}", args[1], args[2])); if (ServiceChannelFactories.IsInitialized) { using (ControlServiceAgent controlServiceAgent = new ControlServiceAgent()) { string recordedFileName = args[1]; string newFileName = args[2]; Recording recording; using (ControlServiceAgent controlAgent = new ControlServiceAgent()) { recording = controlAgent.GetRecordingByFileName(newFileName); } if (recording == null) { string lUncPath; if (newFileName.StartsWith("\\")) { lUncPath = newFileName; } else { try { lUncPath = GetUncPath(newFileName); } catch (IOException) { Console.Error.WriteLine("Could not get a UNC path for recording"); Log(LogSeverity.Warning, string.Format("Could not convert {0} to an unc path", newFileName)); LogArgs(LogSeverity.Information, args); return(-2); } } controlServiceAgent.ChangeRecordingFile(recordedFileName, lUncPath, null, null); } else { Console.Error.WriteLine("Could not move recording as another one with same name allready exsist"); Log(LogSeverity.Warning, string.Format("Could not rename as a recording with the name {0} allready exist in database", newFileName)); LogArgs(LogSeverity.Information, args); return(-2); } } } } else if (args.Length >= 2 && String.Equals(args[0], "IsPartial", StringComparison.InvariantCultureIgnoreCase)) { InitializeServiceChannelFactories(); if (ServiceChannelFactories.IsInitialized) { using (ControlServiceAgent controlServiceAgent = new ControlServiceAgent()) { string recordedFileName = args[1]; Recording recording; using (ControlServiceAgent controlAgent = new ControlServiceAgent()) { recording = controlAgent.GetRecordingByFileName(recordedFileName); } if (recording != null) { return(recording.IsPartialRecording ? -1 : 0); } else { Console.Error.WriteLine("Could not check recording as it could not be found in the database"); Log(LogSeverity.Warning, string.Format("{0} not found in the ARGUS TV database", args[1])); LogArgs(LogSeverity.Information, args); return(-2); } } } else { return(-2); } } else if (args.Length >= 2 && String.Equals(args[0], "Exist", StringComparison.InvariantCultureIgnoreCase)) { InitializeServiceChannelFactories(); if (ServiceChannelFactories.IsInitialized) { using (ControlServiceAgent controlServiceAgent = new ControlServiceAgent()) { string recordedFileName = args[1]; Recording recording; using (ControlServiceAgent controlAgent = new ControlServiceAgent()) { recording = controlAgent.GetRecordingByFileName(recordedFileName); } if (recording != null) { return(0); } else { return(-1); } } } else { return(-2); } } else if (args.Length >= 1 && String.Equals(args[0], "Wake", StringComparison.InvariantCultureIgnoreCase)) { } else { Log(LogSeverity.Warning, "Batch processor did not get valid command(s)"); LogArgs(LogSeverity.Information, args); } } catch { return(-2); } if (ServiceChannelFactories.IsInitialized) { return(0); } else { return(-3); } }