Skip to content

Commit

Permalink
Fix crash when cover url is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
keifufu committed Mar 3, 2023
1 parent 93014fd commit 2024416
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions WebNowPlaying.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ enum PlayerTypes {
private static string CoverOutputLocation = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "/Temp/Rainmeter/WebNowPlaying/cover.png";
private string CoverDefaultLocation = "";
private static string LastDownloadedCoverUrl = "";
private static string LastFailedCoverUrl = "";

private static string rainmeterFileSettingsLocation = "";

Expand All @@ -51,7 +52,8 @@ public static void DownloadCoverImage() {
}
} catch (Exception e) {
API.Log(API.LogType.Error, $"WebNowPlaying.dll - Unable to get album art from: {CoverUrl}");
API.Log(API.LogType.Debug, $"WebNowPlaying Trace: {e.Data}");
API.Log(API.LogType.Debug, $"WebNowPlaying Trace: {e}");
LastFailedCoverUrl = CoverUrl;
}
}
private static byte[] ReadStream(Stream input) {
Expand Down Expand Up @@ -87,7 +89,7 @@ private static void WriteStream(Byte[] image) {

} catch (Exception e) {
API.Log(API.LogType.Error, $"WebNowPlaying.dll - Unable to download album art to: {CoverOutputLocation}");
API.Log(API.LogType.Debug, $"WebNowPlaying Trace: {e.Data}");
API.Log(API.LogType.Debug, $"WebNowPlaying Trace: {e}");
}
}

Expand Down Expand Up @@ -117,7 +119,7 @@ void logger(WNPRedux.LogType type, string message) {
WNPRedux.Initialize(8974, adapterVersion, logger, true);
} catch (Exception e) {
API.Log(API.LogType.Error, "WebNowPlaying.dll - Error initializing WNPRedux");
API.Log(API.LogType.Debug, $"WebNowPlaying Trace: {e.Data}");
API.Log(API.LogType.Debug, $"WebNowPlaying Trace: {e}");
}
}

Expand All @@ -144,7 +146,7 @@ internal virtual void Reload(API api, ref double maxValue) {
}
} catch (Exception e) {
API.Log(API.LogType.Error, "WebNowPlaying.dll - Unknown PlayerType:" + playerTypeString);
API.Log(API.LogType.Debug, $"WebNowPlaying Trace: {e.Data}");
API.Log(API.LogType.Debug, $"WebNowPlaying Trace: {e}");
playerType = PlayerTypes.Status;
}
}
Expand All @@ -165,7 +167,7 @@ internal void ExecuteBang(string args) {
WNPRedux.mediaEvents.SetRating(Convert.ToInt16(bang.Substring(bang.LastIndexOf(" ") + 1)));
} catch (Exception e) {
API.Log(API.LogType.Error, "WebNowPlaying.dll - Failed to parse rating number, assuming 0");
API.Log(API.LogType.Debug, $"WebNowPlaying Trace: {e.Data}");
API.Log(API.LogType.Debug, $"WebNowPlaying Trace: {e}");
WNPRedux.mediaEvents.SetRating(0);
}
} else if (bang.Contains("setposition ")) {
Expand All @@ -182,7 +184,7 @@ internal void ExecuteBang(string args) {
}
} catch (Exception e) {
API.Log(API.LogType.Error, $"WebNowPlaying.dll - SetPosition argument could not be converted to a double: {args}");
API.Log(API.LogType.Debug, $"WebNowPlaying Trace: {e.Data}");
API.Log(API.LogType.Debug, $"WebNowPlaying Trace: {e}");
}
} else if (bang.Contains("setvolume ")) {
try {
Expand All @@ -198,19 +200,19 @@ internal void ExecuteBang(string args) {
}
} catch (Exception e) {
API.Log(API.LogType.Error, $"WebNowPlaying.dll - SetVolume argument could not be converted to a double: {args}");
API.Log(API.LogType.Debug, $"WebNowPlaying Trace: {e.Data}");
API.Log(API.LogType.Debug, $"WebNowPlaying Trace: {e}");
}
} else {
API.Log(API.LogType.Warning, $"WebNowPlaying.dll - Unknown bang: {args}");
}
} catch (Exception e) {
API.Log(API.LogType.Error, $"WebNowPlaying.dll - Error using bang: {args}");
API.Log(API.LogType.Debug, $"WebNowPlaying Trace: {e.Data}");
API.Log(API.LogType.Debug, $"WebNowPlaying Trace: {e}");
}
}

internal virtual double Update() {
if (WNPRedux.mediaInfo.CoverUrl.Length > 0 && LastDownloadedCoverUrl != WNPRedux.mediaInfo.CoverUrl && Uri.IsWellFormedUriString(WNPRedux.mediaInfo.CoverUrl, UriKind.RelativeOrAbsolute))
if (WNPRedux.mediaInfo.CoverUrl.Length > 0 && LastFailedCoverUrl != WNPRedux.mediaInfo.CoverUrl && LastDownloadedCoverUrl != WNPRedux.mediaInfo.CoverUrl && Uri.IsWellFormedUriString(WNPRedux.mediaInfo.CoverUrl, UriKind.RelativeOrAbsolute))
DownloadCoverImage();

try {
Expand Down Expand Up @@ -246,7 +248,7 @@ internal virtual double Update() {
}
} catch (Exception e) {
API.Log(API.LogType.Error, "WebNowPlaying.dll - Error doing update cycle");
API.Log(API.LogType.Debug, $"WebNowPlaying Trace: {e.Data}");
API.Log(API.LogType.Debug, $"WebNowPlaying Trace: {e}");
}

return 0.0;
Expand Down Expand Up @@ -278,7 +280,7 @@ internal string GetString() {
}
} catch (Exception e) {
API.Log(API.LogType.Error, "WebNowPlaying.dll - Error doing getString cycle");
API.Log(API.LogType.Debug, $"WebNowPlaying Trace: {e.Data}");
API.Log(API.LogType.Debug, $"WebNowPlaying Trace: {e}");
}

return null;
Expand Down

0 comments on commit 2024416

Please sign in to comment.