Fix bug with parsing tracks

sometimes they don't come with duration.  so parse as string, which can
be null, and then if is not null we try to parse it as a double
This commit is contained in:
Harry 2014-10-07 17:13:25 -04:00
parent 0b48051ce9
commit c8612f8510

View File

@ -88,7 +88,6 @@ internal static LastTrack ParseJToken(JToken token)
{
t.IsLoved = Convert.ToBoolean(lovedToken.Value<int>());
}
var attrToken = token.SelectToken("@attr");
if (attrToken != null && attrToken.HasValues)
{
@ -97,10 +96,15 @@ internal static LastTrack ParseJToken(JToken token)
}
// api returns milliseconds when track.getInfo is called directly
var secs = token.Value<double>("duration");
if (Math.Abs(secs - default(double)) > double.Epsilon)
var secsStr = token.Value<string>("duration");
double secs;
if (double.TryParse(secsStr, out secs))
{
t.Duration = TimeSpan.FromMilliseconds(secs);
if (Math.Abs(secs - default(double)) > double.Epsilon)
{
t.Duration = TimeSpan.FromMilliseconds(secs);
}
}
return t;