Bleuzen / SpotRec

Spotify desktop client recorder for PulseAudio
MIT License
75 stars 17 forks source link

Time padding after song stops #11

Closed NicoHood closed 3 years ago

NicoHood commented 3 years ago

Why did you choose 2 seconds after the song stops? https://github.com/Bleuzen/SpotRec/blob/master/spotrec.py#L48

Isnt a smaller value also working? With the current setup you must always cut the track, which is annoying. I know that recording to less is also not the best idea. Maybe this can be automated with ffmpeg? Did you check that already? Or what about also using 0.2 or 0.5 seconds?

Bleuzen commented 3 years ago

As I already wrote here: https://github.com/Bleuzen/SpotRec/issues/10#issuecomment-746894222

it is hard to cut the songs accurate and to find good default values for the paddings which work for all users.

I did some testing again and lowered the values for the new version 0.13.0. It is 1.35 seconds for the ending now and I wouldn't go much lower because it already cut it really close for some songs during my tests.

Feel free to play around with the values and try what fits best in your case.

NicoHood commented 3 years ago

I have a really hacky but great idea: What about adding a song that starts with silence after each recording? If we can modify the queue we could always add a particular song that is played afterwards. This way we could avoid recording other tracks. A bit longer silence is more acceptable than the beginning of a new song.

Wikipedia even has a whole list of that: https://en.wikipedia.org/wiki/List_of_silent_musical_compositions#Songs

Checkout "Pause by Rob Dougan": https://open.spotify.com/track/7xUBiCTg33f6fvwzKQsRpH?si=97reKNBbTJWx8NLWZRyaUA

Bleuzen commented 3 years ago

If we can modify the queue [...]

it looks like we can't do that. These are all Spotify mpris methods:

grafik

The only one looking interesting here is "OpenUri(String Uri)". We can start playing the silence track with this command: qdbus org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.OpenUri "spotify:track:7xUBiCTg33f6fvwzKQsRpH" but this plays the song right away, not adding it to the queue. So it is not useful in our case.

NicoHood commented 3 years ago

I am no expert, but what about that: https://specifications.freedesktop.org/mpris-spec/2.2/Track_List_Interface.html

Edit: We could also use the spotify REST API. This would be even more hacky, but might work XD

Bleuzen commented 3 years ago

I am no expert, but what about that: https://specifications.freedesktop.org/mpris-spec/2.2/Track_List_Interface.html

Well, I may be missing something, but as far as I see, Spotify doesn't expose this.

We could also use the spotify REST API. This would be even more hacky, but might work XD

While this may be possible...

1.) What about the ads? How do we know if really a silent track is coming next and no ad? We can't insert a silent track before ads.

2.) I don't want to complicate the script too much with things not really necessary for the average user. Will have to see if this will ever be implemented in this repo, but in a fork / PR, everything is possible.

3.) What if someone wants to record exactly that silent track xD

NicoHood commented 3 years ago

1) I think it is worth to pay for spotify, I only record music to play the mp3s with my ipod shuffle. I use it for doing sports, and using my phone is way too large. I would not care about free members.

2) Correct, it should be optional. As I said, its a really dirty hack, but its the best idea for now it seems

3) Very unlikely.

Bleuzen commented 3 years ago

SpotRec is not targeted at payed users only, so it has to be optional. In fact, I can't even test payed only features myself since I'm not using Spotify anymore (only having a free account left for testing SpotRec).

So while your idea might work, you may understand that I'm currently less motivated for implementing such features in SpotRec, while I'm trying to maintain it for those who are still using it.

That said, anyone can fork it and submit a pull request implementing such an option/feature. Depending on how much it complicates the code, I may consider merging it in this repo.

NicoHood commented 3 years ago

Just a quick question that came up to my mind: How do you determine the end of a song? Do you read the song metadata and stop recording after that time has passed or do you watch for a dbus event that tells us the song finished? Did you try both options?

Bleuzen commented 3 years ago

Currently SpotRec listens for the "PropertiesChanged" dbus event of Spotify. When the event is fired, it compares the track id from before and after the event. If the trackid is the same, something else like for example the playback status must have changed. If the trackid is different, SpotRec knows that the song changed / ended and also stops the recording.

There is no internal timer waiting for the length of the song. I haven't tried this option yet and I guess it won't make a (big) difference because this would depend on the song start time being accurate (which also comes from the "PropertiesChanged" event currently in use).