Skip to content

Commit

Permalink
Added a progress output. Textfile called progress.txt and it stores t…
Browse files Browse the repository at this point in the history
…he current percentage of the songs progression. This can be used in combination with htm / js to create a progressbar
  • Loading branch information
Inzaniity committed Jul 5, 2022
1 parent 2767611 commit fa4d0ea
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Songify Slim/Models/TrackInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ public class TrackInfo
public int DurationMS { get; set; }
public bool isPlaying { get; set; }
public string url { get; set; }
public int DurationPercentage { get; set; }
public int DurationTotal { get; set; }
public int Progress { get; set; }
}
}
8 changes: 7 additions & 1 deletion Songify Slim/Util/Songify/Apihandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ public static TrackInfo GetSongInfo()
Settings.Settings.SpotifyDeviceId = context.Device.Id;

var albums = context.Item.Album.Images;
double totalSeconds = TimeSpan.FromMilliseconds(context.Item.DurationMs).TotalSeconds;
double currentDuration = TimeSpan.FromMilliseconds(context.ProgressMs).TotalSeconds;
double percentage = 100 / totalSeconds * currentDuration;

return new TrackInfo
{
Expand All @@ -178,7 +181,10 @@ public static TrackInfo GetSongInfo()
SongID = context.Item.Id,
DurationMS = context.Item.DurationMs - context.ProgressMs,
isPlaying = context.IsPlaying,
url = "https://open.spotify.com/track/" + context.Item.Id
url = "https://open.spotify.com/track/" + context.Item.Id,
DurationPercentage = (int)percentage,
DurationTotal = context.Item.DurationMs,
Progress = context.ProgressMs
};
}

Expand Down
3 changes: 3 additions & 0 deletions Songify Slim/Util/Songify/SongFetcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
Expand Down Expand Up @@ -308,6 +309,8 @@ public TrackInfo FetchSpotifyWeb()

// gets the current playing songinfo
TrackInfo songInfo = ApiHandler.GetSongInfo();
File.WriteAllText("progress.txt", songInfo.DurationPercentage.ToString());
Console.WriteLine($"{songInfo.Progress} / {songInfo.DurationTotal} ({songInfo.DurationPercentage}%)");
// if no song is playing and custompausetext is enabled
return songInfo ?? new TrackInfo { isPlaying = false };
// return a new stringarray containing artist, title and so on
Expand Down

0 comments on commit fa4d0ea

Please sign in to comment.