/// <summary> /// Generates a new name. /// </summary> /// <param name="format">The format.</param> /// <param name="file">The file.</param> /// <returns>New file name.</returns> public static string FormatFileName(string format, ShowFile file) { var variables = new Dictionary<string, string> { { "$show", file.Show }, { "$seasonz", file.Episode.Season.ToString("0") }, { "$season", file.Episode.Season.ToString("00") }, { "$episodez", file.Episode.SecondEpisode.HasValue ? file.Episode.Episode.ToString("0") + "-" + file.Episode.SecondEpisode.Value.ToString("0") : file.Episode.Episode.ToString("0") }, { "$episode", file.Episode.SecondEpisode.HasValue ? file.Episode.Episode.ToString("00") + "-" + file.Episode.SecondEpisode.Value.ToString("00") : file.Episode.Episode.ToString("00") }, { "$title", file.Episode.SecondEpisode.HasValue ? Regexes.PartText.Replace(file.Title, string.Empty) : file.Title }, { "$quality", file.Quality }, { "$group", file.Group }, { "$ext", file.Extension }, { "$year", file.Airdate.Year.ToString() }, { "$monthz", file.Airdate.Month.ToString() }, { "$month", file.Airdate.Month.ToString("00") }, { "$dayz", file.Airdate.Day.ToString() }, { "$day", file.Airdate.Day.ToString("00") } }; foreach (var variable in variables) { format = format.Replace(variable.Key, variable.Value); } return format; }
/// <summary> /// Updates the status message on configures social networks. /// </summary> /// <param name="file">The identified file.</param> public static void PostToSocial(ShowFile file) { if (Settings.Get("Post only recent", true) && (DateTime.Now - file.Airdate).TotalDays > 21) { Log.Debug("Not posting " + file + " to social networks because it is not a recent episode."); return; } var listed = Settings.Get("Post restrictions list", new List<int>()) .Contains(Database.TVShows.Values.First(x => x.Name == file.Show).ID); switch (Settings.Get("Post restrictions list type", "black")) { case "black": if (listed) { Log.Debug("Not posting " + file + " to social networks because the show is blacklisted."); return; } break; case "white": if (!listed) { Log.Debug("Not posting " + file + " to social networks because the show is not whitelisted."); return; } break; } foreach (var engine in Extensibility.GetNewInstances<SocialEngine>()) { if (!Settings.Get<bool>("Post to " + engine.Name)) { continue; } if (engine is OAuthEngine) { var tokens = Settings.Get<List<string>>(engine.Name + " OAuth"); if (tokens != null && tokens.Count != 0) { ((OAuthEngine)engine).Tokens = tokens; } else { Log.Debug("Not posting " + file + " to " + engine.Name + " because it required OAuth tokens are missing."); continue; } } var format = Settings.Get(engine.Name + " Status Format", engine.DefaultStatusFormat); if (string.IsNullOrWhiteSpace(format)) { return; } try { engine.PostMessage(FileNames.Parser.FormatFileName(format, file)); Log.Debug("Successfully posted " + file + " to " + engine.Name + "."); } catch (Exception ex) { Log.Warn("Unhandled exception while posting " + file + " to " + engine.Name + ".", ex); } } }
/// <summary> /// Updates the status message on configures social networks. /// </summary> /// <param name="file">The identified file.</param> public static void PostToSocial(ShowFile file) { if (Settings.Get("Post only recent", true) && (DateTime.Now - file.Airdate).TotalDays > 21) { return; } var listed = Settings.Get("Post restrictions list", new List<int>()) .Contains(Database.TVShows.Values.First(x => x.Name == file.Show).ID); switch (Settings.Get("Post restrictions list type", "black")) { case "black": if (listed) { return; } break; case "white": if (!listed) { return; } break; } foreach (var engine in Extensibility.GetNewInstances<SocialEngine>()) { if (!Settings.Get<bool>("Post to " + engine.Name)) { continue; } if (engine is OAuthEngine) { var tokens = Settings.Get<List<string>>(engine.Name + " OAuth"); if (tokens != null && tokens.Count != 0) { ((OAuthEngine)engine).Tokens = tokens; } else { continue; } } var format = Settings.Get(engine.Name + " Status Format", engine.DefaultStatusFormat); if (string.IsNullOrWhiteSpace(format)) { return; } try { engine.PostMessage(FileNames.Parser.FormatFileName(format, file)); } catch { } } }
/// <summary> /// Marks the specified episode as seen. /// </summary> /// <param name="showid">The ID of the show.</param> /// <param name="file">The identified file.</param> public static void MarkAsSeen(int showid, ShowFile file) { var @new = false; var eps = file.Episode.SecondEpisode.HasValue ? Enumerable.Range(file.Episode.Episode, (file.Episode.SecondEpisode.Value - file.Episode.Episode + 1)).ToArray() : new[] { file.Episode.Episode }; foreach (var epnr in eps) { Episode ep; if (Database.TVShows[showid].EpisodeByID.TryGetValue(file.Episode.Season * 1000 + epnr, out ep)) { if (!ep.Watched) { @new = ep.Watched = true; } } } if (@new) { Log.Debug("Marking " + file + " as seen."); Database.TVShows[showid].SaveTracking(); PostToSocial(file); } MainWindow.Active.DataChanged(); }
/// <summary> /// Generates a new name. /// </summary> /// <param name="format">The format.</param> /// <param name="file">The file.</param> /// <returns>New file name.</returns> public static string FormatFileName(string format, ShowFile file) { var variables = new Dictionary <string, string> { { "$show", file.Show }, { "$seasonz", file.Episode.Season.ToString("0") }, { "$season", file.Episode.Season.ToString("00") }, { "$episodez", file.Episode.SecondEpisode.HasValue ? file.Episode.Episode.ToString("0") + "-" + file.Episode.SecondEpisode.Value.ToString("0") : file.Episode.Episode.ToString("0") }, { "$episode", file.Episode.SecondEpisode.HasValue ? file.Episode.Episode.ToString("00") + "-" + file.Episode.SecondEpisode.Value.ToString("00") : file.Episode.Episode.ToString("00") }, { "$title", file.Episode.SecondEpisode.HasValue ? Regexes.PartText.Replace(file.Title, string.Empty) : file.Title }, { "$quality", file.Quality }, { "$group", file.Group }, { "$ext", file.Extension }, { "$year", file.Airdate.Year.ToString() }, { "$monthz", file.Airdate.Month.ToString() }, { "$month", file.Airdate.Month.ToString("00") }, { "$dayz", file.Airdate.Day.ToString() }, { "$day", file.Airdate.Day.ToString("00") } }; foreach (var variable in variables) { format = format.Replace(variable.Key, variable.Value); } return(format); }