Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Is there a way to insert a song behind current song from command-line? (Read 2426 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Is there a way to insert a song behind current song from command-line?

Hello.

I am looking for a way to insert a song with command-line-parameters to the active playlist behind the the currently playing song - so that it will be played next. The existing /add-parameter adds the song to the end of the playlist, which is not what i want.
 The only theoretical way, that I found so far is by using foo_utils, which adds a context-command called "insert into playlist" (either to the current playlist or a specified one), but I didnt manage to get it working from command-line.
 And even if does work somehow, then i am not sure if it would work in a way where i can specify the song to be inserted via command-line. I have the suspicion that it would insert a song that is highlighted/selected in foobar and not the one i specified in the command-line. Also it's listed as "legacy command", so it's unsure for how much longer it would work.

A workaround (which wouldn't suit me as much as the above) would be to do the same with queues. Something like: add a song to the end of playlist and queue it after the current playing song in the queue. But I cant see a way to do that either.

As kind of a suggestion and as an example: Would be awesome to have  command-line-parameters like "/add-next". To do "foobar2000.exe /add-next d:\MusikCollection\song.mp3".

Any clue to solve this problem of mine would be appreciated.

Re: Is there a way to insert a song behind current song from command-line?

Reply #1
Oh screw it. Right after posting this and continuing to search for a solution, I noticed that I made a basic logic mistake:  The above wouldnt work in a satisfying  way when done multiple times as it would push the oldest insert further and further away.

Example:

 - current song
 - inserted song 4
 - inserted song 3
 - inserted song 2
 - inserted song 1

Which is not what I am looking for.

The thing i am trying to achieve is that the inserted songs are being played in the order they were inserted after the currently playing song.

 This would in theory also work with two playlists. One default playlist, that keeps playing for as long as there is no song in the second playlist.  Then I'd add the songs to the (end of) second playlist, they are being played and deleted from the second playlist. And once it's empty the first playlist is being continued.

Sorry if this is confusing, but sometimes my brain eats up itself.


Re: Is there a way to insert a song behind current song from command-line?

Reply #3
Hi there,

Some more info. You can queue tracks with this -

Code: [Select]
foobar2000.exe /context_command:"Add to playback queue" "insert file path here"

- however it is funky. Songs play in order added but do not get added to playlist (just added to queue). They play invisibly.

If you also do /add songs get added to playlist, but do not get played from there (played from queue) until end of playlist. There seems no way to directly add and queue in the way you want.(?)

As mentioned with Playlist Attributes you might find a workaround - a pretty neat component that one.

Cheers :)

Re: Is there a way to insert a song behind current song from command-line?

Reply #4
This is how I'd do something along the lines of what you're after using the Queue Contents Editor plugin. I don't think it needs to be added as a UI element to work, as you can open it via the View menu, but I have it as a UI element myself. I also use the Facets library viewer so my method would use it.

Create a temporary folder for music files and add it to your library. Put any songs you want to insert into the playlist queue in that folder (or add them to your regular library). Create Facets filters to switch between viewing your regular library and the temporary library. Switch to viewing the temporary library. You can right click on a file in the temporary library and select "Play Next" (I think you have to add them one at a time), or "Add To Playback Queue" adds a file to the end of the list of file being inserted into the queue rather than at the beginning. You can re-arrange the order later anyway.
When the added files have played, fb2k will continue playing the current playlist. You can also access the menus from within a playlist, but unfortunately if it's not the current playlist, once a file from a different playlist is inserted into the queue it becomes the active playlist. Unless there's a way around that I haven't discovered yet.

There's a screenshot of my configuration below. Facets columns on the left viewing my Temporary Library folder containing three MP3s. On the right is a Playlist at the top and the Queue Contents Editor editor below. There may be other ways to go about it with with the Queue Contents Editor. I don't use it much myself.

Re: Is there a way to insert a song behind current song from command-line?

Reply #5
Hey cool. Thanks for the feedback. I'll try out the various ways.

For now i tested anamorphics method. I think that using 'foobar2000.exe /context_command:"Add to playback queue" "insert file path here"' would already be sufficient. It's  a bit strange indeed, that the song does not appear anywhere, but on the other hand it's logical as the user chose to only queue and not add the song. So the program has no way to list the song.
  What helps is to install the Queue Content Editor that yetanotherid mentioned and enable it's queue-playlist-feature in the setting. Then the queued songs are being shown in a separate playlist named "queue".

 There are two slight flaws with this method though:

 - if you (for some reason) queue a song via command-line that is already in the playlist (maybe ANY playlist? didnt try that) then foobar does not continue to play where it was before the queue started, but instead continues the playlist at the position that queued song was at.

- the maximum queue-length is 64. This _might_ be an issue in some situations, but probably rarely.

Re: Is there a way to insert a song behind current song from command-line?

Reply #6
@yetanotherid:

I  experimented a bit with facet, though I didnt fully understand how to "Create Facets filters to switch between viewing your regular library and the temporary library" in the short time that i invested. But that doesn't really matter. From what I noticed and what you described, the point of your solution seems to be adding songs directly from the library and not from an opened playlists. Because if you do the later, then foobar does not return to the playlist/playlistposition that it was at before songs were queued (as i already mentioned in the reply to anamorphic).
 Since I dont use libraries much and want to find a solution that works  without using the GUI, i'll now instead try that foo_playlist_attributes-plugin that i discovered yesterday. Thanks anyway for your reply.

One more thing: I saw that you have Dire Straits in your Library. Here is a link to a song that you might like. It's a legal, free download:
http://ocremix.org/remix/OCR03700

Re: Is there a way to insert a song behind current song from command-line?

Reply #7
TheLomaxx,
For Facets you can create a new filter under Media Library/Facets/Filters. Give it any name you want and for the Query, add the path to your folder. ie "D:\Music Temp" (you can open Facets and use it from the Library menu without having to add it to the GUI). If you're not into that, the following works using the Queue Contents Editor and Playlist Attributes (I've only just started playing with Playlist Attributes as I haven't used it before)....

For my example the playlists are called PL1, PL2 and Queue, with PL1 being a normal playlist, PL2 being the playlist fb2k uses to open new files from the explorer context menus (configured under Preferences/Shell Integration), and Queue being the "Queue Contents Editor" playlist. Before enabling the latter, create a Playlist Attributes template like the screenshot below (or disable the global options as required). Set "Continue on Playlist" to "PL1" or "last playlist".

Start PL1 playing.
Right click on some files in Explorer and "Enqueue in Foobar2000". They should be added to PL2.
Copy and paste them into the Queue playlist.
When the current track has finished playing in PL1, the tracks in the Queue Playlist will play. When they're finished FB2k should continue playing the tracks in PL1.

Instead of using the PL2 Playlist for opening files, and then copying and pasting the tracks into the Queue Playlist, there's probably no reason why you couldn't configure "Enqueue in Foobar2000" to open files directly into the Queue Playlist. That way once the current track in PL1 has finished, fb2k should automatically switch to playing the files you just loaded into the Queue Playlist, and then automatically switch back to PL1, making the process even more automatic.

Edit: I just tried loading files directly into the Queue playlist via "Enqueue in Foobar2000" and it did work.

PS Thanks for the link. I'll have a listen.

Re: Is there a way to insert a song behind current song from command-line?

Reply #8
The hint regarding the Shell Integration Settings and setting the default playlist for enqueueing is quite helpful. Because so far i do not manage to find a command-line-parameter to add a song to a specific playlist.
 Other than that i tried to use "prioritized playlist" and "continue on playlist" (both shown in your screenshot).  That does in general work, but at least for me (my configuration) foobar does not cleanly switch songs when using it so far. I configured PL1 to prioritize PL2, and PL2 to continue on PL1 when done, as well as to remove played songs from PL2.
 Now when i add a song to PL2 and the currently playing song in PL1 is over, the next song in PL1 is being started for a few milliseconds (less than half a second) before it switches to the song in PL2.  I managed to reduce this to a minimum by setting all settings for fading songs in/out to zero at Settings/Playback/Output, but for songs that immediately start it's still audible. :/ Big bummer. I will try some more.

Re: Is there a way to insert a song behind current song from command-line?

Reply #9
Now when i add a song to PL2 and the currently playing song in PL1 is over, the next song in PL1 is being started for a few milliseconds (less than half a second) before it switches to the song in PL2.
Preferences > Advanced > Tools > Playlist Attributes > 'Use DSP' - setting that might help with that. (See right at the end of documentation you posted above)

Cheers ;)

Re: Is there a way to insert a song behind current song from command-line?

Reply #10
<3 Though I found that too myself. xD I already wrote a reply about it and pressed the reply-button, when I was informed about your new post. ^^
Oh wait, you do not exactly point to the correct option. The option is a bit hidden, but can be found in File->Preferences->Adavanced->Tools->Playlist Attributes->Use DSP for smooth transition.

Re: Is there a way to insert a song behind current song from command-line?

Reply #11
nvm i am a confused dumbass <sigh>

Re: Is there a way to insert a song behind current song from command-line?

Reply #12
All good. 8) I was curious what your usage scenario is using command line this way. I was thinking maybe you could write a simple batch file to queue multiple commands into foobar? (Athough I myself have not done anything with batch files since 'autoexec.bat' back in the Win95 days :D ). Theoretically though with all foobar menus being available to command line, you should be able to string together (with separate calls of foobar2000.exe) - Switch to playlist, Add tracks, Queue (selected) tracks, Show now playing, etc. Just an idea anyway, not at my computer to test any of it...

Cheers

Re: Is there a way to insert a song behind current song from command-line?

Reply #13
I am trying to turn foobar2000 in some sort of private IRC(internet relay chat)-radiostation by using hexchat with some plugins, icecast and including youtube-dl for songrequest. In the end, friends would be able to tune in via a simple URL i provide, connect to any IRC-like server (twitch would work too), request songs, skip songs etc. All that with very minimal scripting knowledge of mine.

So far i implemented that the songs automatically get announced in the irc-channel and that a specified irc user can skip songs. The next thing (where this threat is relevant) is to offer a trigger like "!songrequest <youtubecode>" that is then passed to a batchfile, which downloads the song from youtube and queues it into foobar2000.
 I know that there are twitchbots or similar for all this, but I'd like to stick to foobar to use my playlists, benefit from decoder-plugins for strange music formats (amiga, c64, pc-mods) and by using youtube-dl i hope to be able to also include requests for soundcloud or other platforms. And maybe use stuff like replay-gain etc. pp.


Re: Is there a way to insert a song behind current song from command-line?

Reply #14
Oh wow, that is quite extensive. And all of it beyond my level of expertise :D

The hint regarding the Shell Integration Settings and setting the default playlist for enqueueing is quite helpful. Because so far i do not manage to find a command-line-parameter to add a song to a specific playlist.
I was curious myself about switching playlists with command line. Unfortunately the (hold shift key) View > Switch to playlist menu does not work at all to get a specific one. That leaves (shift) File > Next / Previous playlist as the only way, which is fine as long as one knows the order of playlists and has them arranged to switch back and forth. Can follow that up with /add on same command line -

Code: [Select]
foobar2000.exe /command:"Next playlist" /add "M:\for example.mp3"

^ (Adds the file to whatever playlist is after the active one. You would need Shell Integration > 'Always send new files to playlist' setting switched off however)

Anyway, best of luck with everything!

Cheers 8)

Re: Is there a way to insert a song behind current song from command-line?

Reply #15
Thank you.

I managed to come up with a small python-script. So now the songrequest works. However the playlistattributes seems to have an issue. Unless I configured something wrong.
 Whith my setup where PL1 prioritises PL2 and PL2 continues with PL1 (when done and empty), I must not skip the last song in PL2 or foobar2000 gets confused. If I do it, I end up in a situation where PL1 does not continue automatically and songs in the active playlist are being removed from the playlist without being played when I press the play-button (or my global hotkey for it). I can fix that by adding another song to PL2 and letting it play to the end (can click the progress-bar near the end of song).
 Seem to me like a bug in the plugin. Like some variables are not correctly reset/initiated when skipping songs.

 

Re: Is there a way to insert a song behind current song from command-line?

Reply #16
Update: The issue only shows up when I set "Removed skipped tracks" to "enabled" for PL2. Though from my understanding it should work with it. And I would want it to be that way.