diff --git a/README.md b/README.md index 97034f3..9481ec2 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,8 @@ jammer playlist list - **AAC:** Advanced Audio Coding - **WMA:** Windows Media Audio - **MP4:** MPEG-4 +- **JAMMER:** Jammer playlist +- **FOLDER:** Folder / Directory ### Controls @@ -66,6 +68,17 @@ jammer playlist list ### Install Github latest [Release](https://github.com/jooapa/signal-jammer/releases/latest) +### Example usage +```bash +jammer "path/to/song.mp3" ./another/song.aac C:\Users\user\jammer\playlists\playlist.jammer "path/to/folder" +``` +```bash +jammer https://soundcloud.com/username/track-name https://soundcloud.com/username/sets/playlist-name +``` +```bash +jammer https://www.youtube.com/watch?v=video-id +``` + ### Build/Run yourself ``` dotnet build --configuration Release diff --git a/src/Absolute.cs b/src/Absolute.cs index 91507db..86475dd 100644 --- a/src/Absolute.cs +++ b/src/Absolute.cs @@ -49,6 +49,13 @@ public static string[] Correctify(string[] args) args[i] = item; } + // if folder exists, convert to absolute path + else if (Directory.Exists(item)) + { + if (IsRelativePath(item)) { + args[i] = ConvertToAbsolutePath(item); + } + } // if exits, convert to absolute path else if (File.Exists(item)) { diff --git a/src/Keyboard.cs b/src/Keyboard.cs index 5382ea7..198263e 100644 --- a/src/Keyboard.cs +++ b/src/Keyboard.cs @@ -169,7 +169,7 @@ public static void CheckKeyboard() TUI.Help(); AnsiConsole.MarkupLine("\nPress any key to continue."); - Console.ReadLine(); + Console.ReadKey(true); break; } diff --git a/src/Play.cs b/src/Play.cs index 47be27b..7720fc3 100644 --- a/src/Play.cs +++ b/src/Play.cs @@ -11,6 +11,7 @@ public class Play private static Thread loopThread = new Thread(() => { }); public static void PlaySong(string[] songs, int Currentindex) { + if (Currentindex < 0 || Currentindex >= songs.Length) { Start.playerView = "fake"; @@ -26,6 +27,19 @@ public static void PlaySong(string[] songs, int Currentindex) // id related to local file path, convert to absolute path path = Path.GetFullPath(songs[Currentindex]); } + // iof folder + else if (Directory.Exists(songs[Currentindex])) + { + // add all files in folder to Utils.songs + string[] files = Directory.GetFiles(songs[Currentindex]); + foreach (string file in files) + { + AddSong(file); + } + // remove folder from Utils.songs + Utils.songs = Utils.songs.Where((source, i) => i != Currentindex).ToArray(); + path = Utils.songs[Currentindex]; + } else if (URL.isValidSoundCloudPlaylist(songs[Currentindex])) { // id related to url, download and convert to absolute path Debug.dprint("Soundcloud playlist."); @@ -41,12 +55,6 @@ public static void PlaySong(string[] songs, int Currentindex) // id related to url, download and convert to absolute path path = Download.DownloadSong(songs[Currentindex]); } - // else if (URL.IsUrl(songs[Currentindex])) - // { - // AnsiConsole.MarkupLine("[green]URL is valid[/]"); - // isInternetURL = true; - // path = songs[Currentindex]; - // } else { AnsiConsole.MarkupLine("[red] Song not found[/]"); @@ -70,6 +78,22 @@ public static void PlaySong(string[] songs, int Currentindex) { PlayOgg(); } + else if (extension == ".jammer") { + // read playlist + string[] playlist = File.ReadAllLines(path); + // add all songs in playlist to Utils.songs + foreach (string song in playlist) { + AddSong(song); + } + // remove playlist from Utils.songs + Utils.songs = Utils.songs.Where((source, i) => i != Currentindex).ToArray(); + if (Currentindex == Utils.songs.Length) + { + Utils.currentSongIndex = Utils.songs.Length - 1; + } + Start.state = MainStates.playing; + PlaySong(Utils.songs, Utils.currentSongIndex); + } else { Console.WriteLine("Unsupported file format"); @@ -90,7 +114,6 @@ public static void PlaySong(string[] songs, int Currentindex) Debug.dprint("Error: " + e); return; } - // LoadMusic(Utils.currentSong); } public static void PauseSong() @@ -113,7 +136,6 @@ public static void PlaySong() { return; } - // Utils.currentMusic.Stop(); Utils.currentMusic.Play(); } diff --git a/src/Start.cs b/src/Start.cs index fe760cd..dcfeda6 100644 --- a/src/Start.cs +++ b/src/Start.cs @@ -94,10 +94,6 @@ public static void Run(string[] args) TUI.ClearScreen(); } - - // - // StartPlaying - // public static void StartPlaying() { Play.PlaySong(Utils.songs, Utils.currentSongIndex); @@ -157,18 +153,14 @@ public static void Loop() drawOnce = false; } - // if song is finished, play next song - if (Utils.preciseTime == lastPlaybackTime) - { - // If the time hasn't changed, it might be near the end of the song - // Check if it's close to the end and play the next song - if (Utils.preciseTime >= Utils.audioStream.Length - treshhold) - { + // If the song is finished, play next song + if (treshhold % 100 == 0) { + // If the time hasn't changed, the song is finished + if (lastPlaybackTime == Utils.preciseTime) { Play.MaybeNextSong(); } } - else - { + else { // If the time has changed, update the last observed playback time lastPlaybackTime = Utils.preciseTime; } diff --git a/src/TUI.cs b/src/TUI.cs index 22cec5c..becbdc3 100644 --- a/src/TUI.cs +++ b/src/TUI.cs @@ -1,5 +1,6 @@ using Spectre.Console; using jammer; +using System.Runtime.CompilerServices; static class TUI { @@ -57,6 +58,11 @@ static public void DrawPlayer() { AnsiConsole.Write(table); AnsiConsole.Write(controlsTable); + // var debug = new Table(); + // debug.AddColumn("Debug"); + // debug.AddRow(Utils.preciseTime + " / " + Utils.audioStream.Length); + // AnsiConsole.Write(debug); + AnsiConsole.Markup("Press [red]h[/] for help"); AnsiConsole.Markup("\nPress [yellow]c[/] to hide settings"); AnsiConsole.Markup("\nPress [green]f[/] to show playlist"); @@ -137,6 +143,8 @@ public static void PlaylistInput() { AnsiConsole.MarkupLine("[grey]6. save/replace playlist[/]"); // AnsiConsole.MarkupLine("[grey]7. goto song in playlist[/]"); AnsiConsole.MarkupLine("[grey]8. suffle playlist[/]"); + AnsiConsole.MarkupLine("[grey]9. play song(s)[/]"); + AnsiConsole.MarkupLine("[grey]0. exit[/]"); string? playlistInput = Console.ReadLine(); if (playlistInput == "" || playlistInput == null) { return; } @@ -159,7 +167,7 @@ public static void PlaylistInput() { // show songs in playlist Playlists.Show(playlistNameToShow); AnsiConsole.Markup("\nPress any key to continue"); - Console.ReadLine(); + Console.ReadKey(true); break; case "4": // list all playlists Playlists.List(); @@ -197,6 +205,23 @@ public static void PlaylistInput() { // set newsong from suffle to the current song Utils.currentSong = Utils.songs[Utils.currentSongIndex]; break; + + case "9": // play single song + AnsiConsole.Markup("\nEnter song(s) to play: "); + string[]? songsToPlay = Console.ReadLine()?.Split(" "); + if (songsToPlay == null) { break; } + // remove " from start and end of each song + for (int i = 0; i < songsToPlay.Length; i++) { + songsToPlay[i] = songsToPlay[i].Replace("\"", ""); + } + Utils.songs = songsToPlay; + Utils.currentSongIndex = 0; + Play.StopSong(); + Play.PlaySong(Utils.songs, Utils.currentSongIndex); + break; + + case "0": // exit + break; } AnsiConsole.Clear(); } diff --git a/src/Utils.cs b/src/Utils.cs index bae2eb9..08ddd07 100644 --- a/src/Utils.cs +++ b/src/Utils.cs @@ -21,6 +21,6 @@ public struct Utils public static string jammerPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\jammer\\"; public static bool isDebug = false; public static string currentPlaylist = ""; - public static string version = "1.1.3"; + public static string version = "1.1.4"; } } \ No newline at end of file