Skip to content

Commit

Permalink
Merge pull request #361 from MarkSummerville/master
Browse files Browse the repository at this point in the history
Bug fixes for RC3
  • Loading branch information
SirSparkles authored Mar 16, 2018
2 parents 8d358fb + f6bd660 commit e1b5388
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 30 deletions.
2 changes: 1 addition & 1 deletion TVRename#/App/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static class Program
[STAThread]
private static void Main(string[] args)
{
Logger.Info($"TV Rename started with args: {string.Join(" ", args)}");
Logger.Info($"TV Rename {Helpers.DisplayVersion} started with args: {string.Join(" ", args)}");

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Expand Down
19 changes: 14 additions & 5 deletions TVRename#/Forms/UI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1126,13 +1126,22 @@ public static void SetHTMLbody(string body, string path, WebBrowser web)
html += "</body></html>";

web.Navigate("about:blank"); // make it close any file it might have open
try
{
BinaryWriter bw = new BinaryWriter(new FileStream(path, System.IO.FileMode.Create));
bw.Write(System.Text.Encoding.GetEncoding("UTF-8").GetBytes(html));

BinaryWriter bw = new BinaryWriter(new FileStream(path, System.IO.FileMode.Create));
bw.Write(System.Text.Encoding.GetEncoding("UTF-8").GetBytes(html));

bw.Close();
bw.Close();
web.Navigate(LocalFileURLBase(path));
}
catch (Exception ex)
{
//Fail gracefully - no RHS episode guide is not too big of a problem.
//May get errors if TV Rename cannot access the filesystem or disk is full etc
logger.Error(ex);
}

web.Navigate(LocalFileURLBase(path));

}

public void TVDBFor(ProcessedEpisode e)
Expand Down
41 changes: 17 additions & 24 deletions TVRename#/TheTVDB/TheTVDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,7 @@ public bool HasSeries(int id)

public SeriesInfo GetSeries(int id)
{
if (!this.HasSeries(id))
return null;

return this.Series[id];
return this.HasSeries(id) ? this.Series[id] : null;
}

public System.Collections.Generic.Dictionary<int, SeriesInfo> GetSeriesDict()
Expand Down Expand Up @@ -1231,7 +1228,7 @@ private SeriesInfo DownloadSeriesNow(int code, bool episodesToo, bool bannersToo
{
bool forceReload = DoWeForceReloadFor(code);

string txt = "";
string txt;
if (this.Series.ContainsKey(code))
txt = this.Series[code].Name;
else
Expand Down Expand Up @@ -1341,7 +1338,7 @@ private SeriesInfo DownloadSeriesNow(int code, bool episodesToo, bool bannersToo
List<JObject> bannerDefaultLangResponses = new List<JObject>();
if (bannersToo || forceReload ) {
// get /series/id/images if the bannersToo is set - may need to make multiple calls to for each image type
List<string> imageTypes = new List<string> { };
List<string> imageTypes = new List<string>();

try
{
Expand Down Expand Up @@ -1379,7 +1376,7 @@ private SeriesInfo DownloadSeriesNow(int code, bool episodesToo, bool bannersToo
}
if (inForeignLanguage())
{
List<string> imageDefaultLangTypes = new List<string> { };
List<string> imageDefaultLangTypes = new List<string>();

try
{
Expand Down Expand Up @@ -1427,7 +1424,7 @@ private SeriesInfo DownloadSeriesNow(int code, bool episodesToo, bool bannersToo
{
try {
foreach (JObject bannerData in response["data"]) {
Banner b = new Banner((int)si.TVDBCode, bannerData,getLanguageId());
Banner b = new Banner(si.TVDBCode, bannerData,getLanguageId());
if (!this.Series.ContainsKey(b.SeriesID)) throw new TVDBException("Can't find the series to add the banner to (TheTVDB).");
SeriesInfo ser = this.Series[b.SeriesID];
ser.AddOrUpdateBanner(b);
Expand All @@ -1448,7 +1445,7 @@ private SeriesInfo DownloadSeriesNow(int code, bool episodesToo, bool bannersToo
{
foreach (JObject bannerData in response["data"])
{
Banner b = new Banner((int)si.TVDBCode, bannerData, getDefaultLanguageId());
Banner b = new Banner(si.TVDBCode, bannerData, getDefaultLanguageId());
if (!this.Series.ContainsKey(b.SeriesID)) throw new TVDBException("Can't find the series to add the banner to (TheTVDB).");
SeriesInfo ser = this.Series[b.SeriesID];
ser.AddOrUpdateBanner(b);
Expand All @@ -1462,19 +1459,19 @@ private SeriesInfo DownloadSeriesNow(int code, bool episodesToo, bool bannersToo
}
}

this.Series[(int)si.TVDBCode].BannersLoaded = true;
this.Series[si.TVDBCode].BannersLoaded = true;

//Get the actors too then well need another call for that
try
{
JObject jsonActorsResponse = HTTPHelper.JsonHTTPGETRequest(APIRoot + "/series/" + code + "/actors",
null, this.authenticationToken);
IEnumerable<string> seriesActors = from a in jsonActorsResponse["data"] select (string) a["name"];
this.Series[(int) si.TVDBCode].setActors(seriesActors);
this.Series[si.TVDBCode].setActors(seriesActors);
}
catch (WebException ex)
{
logger.Error(ex, "Unble to obtain actors for {0}",this.Series[(int)si.TVDBCode].Name);
logger.Error(ex, "Unble to obtain actors for {0}",this.Series[si.TVDBCode].Name);
this.LastError = ex.Message;
}

Expand All @@ -1485,7 +1482,7 @@ private SeriesInfo DownloadSeriesNow(int code, bool episodesToo, bool bannersToo

}

private bool inForeignLanguage() => !(DefaultLanguage == this.RequestLanguage);
private bool inForeignLanguage() => DefaultLanguage != this.RequestLanguage;

private bool DownloadEpisodeNow(int seriesID, int episodeID, bool dvdOrder = false)
{
Expand Down Expand Up @@ -1593,23 +1590,19 @@ public bool EnsureUpdated(int code, bool bannersToo)
Season seas = kvp.Value;
foreach (Episode e in seas.Episodes)
{
if (e.Dirty && e.EpisodeID >0)
{
this.LockEE();
this.ExtraEpisodes.Add(new ExtraEp(e.SeriesID, e.EpisodeID));
this.UnlockEE();
}
if (!e.Dirty || e.EpisodeID <= 0) continue;
this.LockEE();
this.ExtraEpisodes.Add(new ExtraEp(e.SeriesID, e.EpisodeID));
this.UnlockEE();
}
}

this.LockEE();
foreach (ExtraEp ee in this.ExtraEpisodes)
{
if ((ee.SeriesID == code) && (!ee.Done))
{
ok = this.DownloadEpisodeNow(ee.SeriesID, ee.EpisodeID) && ok;
ee.Done = true;
}
if ((ee.SeriesID != code) || (ee.Done)) continue;
ok = this.DownloadEpisodeNow(ee.SeriesID, ee.EpisodeID) && ok;
ee.Done = true;
}
this.UnlockEE();

Expand Down

0 comments on commit e1b5388

Please sign in to comment.