Skip to content

Commit

Permalink
can play single song from the F2 menu. can open .jammer playlist by t…
Browse files Browse the repository at this point in the history
…yping it. Looping works without any noticable problems seems to work, very glad about that. Can open folders
  • Loading branch information
jooapa committed Dec 28, 2023
1 parent 7592c68 commit 9879820
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 24 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/Absolute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
2 changes: 1 addition & 1 deletion src/Keyboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public static void CheckKeyboard()
TUI.Help();

AnsiConsole.MarkupLine("\nPress any key to continue.");
Console.ReadLine();
Console.ReadKey(true);
break;
}

Expand Down
38 changes: 30 additions & 8 deletions src/Play.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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.");
Expand All @@ -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[/]");
Expand All @@ -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");
Expand All @@ -90,7 +114,6 @@ public static void PlaySong(string[] songs, int Currentindex)
Debug.dprint("Error: " + e);
return;
}
// LoadMusic(Utils.currentSong);
}

public static void PauseSong()
Expand All @@ -113,7 +136,6 @@ public static void PlaySong()
{
return;
}
// Utils.currentMusic.Stop();
Utils.currentMusic.Play();
}

Expand Down
18 changes: 5 additions & 13 deletions src/Start.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ public static void Run(string[] args)
TUI.ClearScreen();
}


//
// StartPlaying
//
public static void StartPlaying()
{
Play.PlaySong(Utils.songs, Utils.currentSongIndex);
Expand Down Expand Up @@ -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;
}
Expand Down
27 changes: 26 additions & 1 deletion src/TUI.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Spectre.Console;
using jammer;
using System.Runtime.CompilerServices;
static class TUI
{

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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; }
Expand All @@ -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();
Expand Down Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}

0 comments on commit 9879820

Please sign in to comment.