Skip to content

Commit

Permalink
Improvements to YTS recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
SirSparkles committed Jun 9, 2023
1 parent 5483c8f commit 5c7d83f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private void BwScan_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
pbProgress.Value = e.ProgressPercentage.Between(0, 100);
DateTime completionDateTime = scanStartTime.Add((DateTime.Now - scanStartTime) / (pbProgress.Value+1) * 100) ;
lblStatus.Text = $"{e.UserState?.ToString()?.ToUiVersion()} ETC={completionDateTime}";
lblStatus.Text = $"ETC={completionDateTime} {e.UserState?.ToString()?.ToUiVersion()}";
}

private void BwScan_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
Expand Down
5 changes: 4 additions & 1 deletion TVRename/Forms/Tools/YTSRecomendations/YtsViewerView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public partial class YtsViewerView : Form
private readonly List<MovieConfiguration> addedMovies;
string quality;
int minRating;
private DateTime scanStartTime;

public YtsViewerView(TVDoc doc, UI main)
{
Expand Down Expand Up @@ -121,6 +122,7 @@ private void rightClickMenu_ItemClicked(object sender, ToolStripItemClickedEvent
private void BwScan_DoWork(object sender, DoWorkEventArgs e)
{
System.Threading.Thread.CurrentThread.Name ??= "Recommendations Scan Thread"; // Can only set it once
scanStartTime = DateTime.Now;
try
{
recs = YTS.API
Expand All @@ -137,7 +139,8 @@ private void BwScan_DoWork(object sender, DoWorkEventArgs e)
private void BwScan_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
pbProgress.Value = e.ProgressPercentage.Between(0, 100);
lblStatus.Text = e.UserState?.ToString()?.ToUiVersion();
DateTime completionDateTime = scanStartTime.Add((DateTime.Now - scanStartTime) / (pbProgress.Value + 1) * 100);
lblStatus.Text = $"ETC={completionDateTime} {e.UserState?.ToString()?.ToUiVersion()}";
}

private void BwScan_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
Expand Down
16 changes: 7 additions & 9 deletions TVRename/Sources/YTS/API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,12 @@ private static T HandleErrorsFrom<T>(string message, Func<T> handler)
}
}

public static string GetMandatoryString(this JToken r, string key)
{
return (string?)r[key] ?? throw new Exception($"Could not get data element '{key}' from {r}");
}
public static string? GetString(this JToken r, string key)
{
return (string?)r[key];
}
private static string GetMandatoryString(this JToken r, string key)
=> (string?)r[key] ?? throw new Exception($"Could not get data element '{key}' from {r}");

private static string? GetString(this JToken r, string key)
=> (string?)r[key];

public class YtsMovie
{
private readonly JObject result;
Expand Down Expand Up @@ -148,7 +146,7 @@ private static IEnumerable<YtsMovie> GetMoviesInternal(BackgroundWorker sender,

page++;
int totalEntries = updatesJson["data"]?["movie_count"]?.ToObject<int>() ?? throw new Exception();
sender.ReportProgress(100 * page / (totalEntries / 50));
sender.ReportProgress(100 * page / (totalEntries / 50),$"Page {page}");
}
else
{
Expand Down

0 comments on commit 5c7d83f

Please sign in to comment.