Skip to content

Commit

Permalink
Merge pull request #444 from TV-Rename/code-tidy
Browse files Browse the repository at this point in the history
Code tidy
  • Loading branch information
SirSparkles authored Jul 4, 2018
2 parents b91dd33 + bc09cb3 commit 57a5c41
Show file tree
Hide file tree
Showing 34 changed files with 1,707 additions and 1,309 deletions.
2 changes: 1 addition & 1 deletion TVRename/DownloadIdentifers/DownloadEpisodeJPG.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public override ItemList ProcessEpisode(ProcessedEpisode dbep, FileInfo filo, bo

ItemList theActionList = new ItemList();

string ban = dbep.GetFilename();
string ban = dbep.Filename;
if (string.IsNullOrEmpty(ban)) return null;

string basefn = filo.RemoveExtension();
Expand Down
2 changes: 1 addition & 1 deletion TVRename/DownloadIdentifers/DownloadXBMCImages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public override ItemList ProcessEpisode(ProcessedEpisode dbep, FileInfo filo, bo

private ActionDownloadImage DoEpisode(ShowItem si, Episode ep, FileInfo filo,string extension, bool forceRefresh)
{
string ban = ep.GetFilename();
string ban = ep.Filename;
if (!string.IsNullOrEmpty(ban))
{
string basefn = filo.RemoveExtension();
Expand Down
69 changes: 5 additions & 64 deletions TVRename/Exporter/ShowsHTML.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;

namespace TVRename
Expand All @@ -22,13 +23,13 @@ public override void Run()
{
using (System.IO.StreamWriter file = new System.IO.StreamWriter(Location()))
{
file.WriteLine(HTMLHeader());
file.WriteLine(ShowHtmlHelper.HTMLHeader(8, Color.White));
foreach (ShowItem si in Shows)
{
file.WriteLine(CreateHtml(si));
}

file.WriteLine(HTMLFooter());
file.WriteLine(ShowHtmlHelper.HTMLFooter());
}
}
catch (Exception e)
Expand All @@ -44,8 +45,8 @@ private static string CreateHtml(ShowItem si)
int maxYear = si.TheSeries().MaxYear();
string yearRange = (minYear == maxYear) ? minYear.ToString() : minYear + "-" + maxYear;
string episodeSummary = si.TheSeries().AiredSeasons.Sum(pair => pair.Value.Episodes.Count).ToString();
string stars = StarRating(si.TheSeries().GetSiteRating());
string genreIcons = string.Join(" ", si.TheSeries().GetGenres().Select(GenreIconHtml));
string stars = ShowHtmlHelper.StarRating(si.TheSeries().GetSiteRating());
string genreIcons = string.Join(" ", si.TheSeries().GetGenres().Select(ShowHtmlHelper.GenreIconHtml));
bool ratingIsNumber = float.TryParse(si.TheSeries().GetSiteRating(), out float rating);
string siteRating = ratingIsNumber && rating > 0 ? rating + "/10" : "";

Expand All @@ -68,65 +69,5 @@ private static string CreateHtml(ShowItem si)
</div></div></div>";
}

private static string GenreIconHtml(string genre)
{
string[] availbleIcons =
{
"Action", "Adventure", "Animation", "Children", "Comedy", "Crime", "Documentary", "Drama", "Family",
"Fantasy", "Food", "Horror", "Mini-Series", "Mystery", "Reality", "Romance", "Science-Fiction", "Soap",
"Talk Show", "Thriller", "Travel", "War", "Western"
};

const string root = "https://www.tvrename.com/assets/images/GenreIcons/";

return availbleIcons.Contains(genre)
? $@"<img width=""30"" height=""30"" src=""{root}{genre}.svg"" alt=""{genre}"">"
: "";
}

private static string StarRating(string rating)
{
return StarRating(float.TryParse(rating, out float f) ? f / 2 : 3);
}

private static string StarRating(float f)
{
const string star = @"<i class=""fas fa-star""></i>";
const string halfstar = @"<i class=""fas fa-star-half""></i>";

if (f < .25) return "";
if (f <= .75) return halfstar;
if (f > 1) return star + StarRating(f - 1);
return star;
}

// ReSharper disable once InconsistentNaming
private static string HTMLHeader()
{
return @"<!DOCTYPE html>
<html><head>
<meta charset=""utf-8"">
<meta name = ""viewport"" content = ""width=device-width, initial-scale=1.0"" >
<title> TV Rename - Show Summary</title>
<link rel = ""stylesheet"" href = ""http://maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css"" />
<link rel = ""stylesheet"" href = ""https://use.fontawesome.com/releases/v5.0.13/css/all.css"" />
</head >
<body >
<div class=""col-sm-8 offset-sm-2"">";
}

// ReSharper disable once InconsistentNaming
private static string HTMLFooter()
{
return @"
</div>
<script src=""http://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js""></script>
<script src = ""http://cdnjs.cloudflare.com/ajax/libs/popper.js/1.13.0/umd/popper.min.js"" ></script>
<script src = ""http://maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"" ></script>
<script >$(document).ready(function(){ })</script>
</body>
</html>
";
}
}
}
2 changes: 1 addition & 1 deletion TVRename/Exporter/UpcomingXML.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected override bool Generate(System.IO.Stream str, List<ProcessedEpisode> e
writer.WriteEndElement();

XmlHelper.WriteElementToXml( writer,"Rating",ei.EpisodeRating);
XmlHelper.WriteElementToXml( writer,"filename",ei.GetFilename());
XmlHelper.WriteElementToXml( writer,"filename",ei.Filename);

writer.WriteEndElement(); // item
}
Expand Down
4 changes: 2 additions & 2 deletions TVRename/Finders/SABnzbdFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public override void Check(SetProgressDelegate prog, int startpct, int totPct)

try
{
SAB.result res = SAB.result.Deserialize(r);
SAB.Result res = SAB.Result.Deserialize(r);
if (res != null && res.status == "False")
{
Logger.Error("Error processing data from SABnzbd (Queue Check): {0}",res.error );
Expand Down Expand Up @@ -102,7 +102,7 @@ public override void Check(SetProgressDelegate prog, int startpct, int totPct)

string showname = Helpers.SimplifyName(Action.Episode.SI.ShowName);

foreach (SAB.queueSlotsSlot te in sq.slots)
foreach (SAB.QueueSlotsSlot te in sq.slots)
{
//foreach (queueSlotsSlot te in qs)
{
Expand Down
2 changes: 1 addition & 1 deletion TVRename/Forms/ActorsGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private void BuildData()
{
foreach (Episode ep in kvp.Value.Episodes)
{
foreach (string g in ep.GetGuestStars())
foreach (string g in ep.GuestStars)
{
string aa = g.Trim();
if (!string.IsNullOrEmpty(aa))
Expand Down
Loading

0 comments on commit 57a5c41

Please sign in to comment.