Categories
Latest Posts
Running Cromwell on AWS/Batch
- Posted: 2018-11-21.
Parallel mysql myisam repair
- Posted: 2018-11-21.
Does a TKI like Crizotinib kill tumor cells ?
- Posted: 2018-10-28.
Save Spotify to flac or mp3
- Posted: 2018-07-14.
Replace all symlinks by the original file
- Posted: 2018-03-02.
Tag Collection
mysql galaxy levenshtein bioinformatics Silverlight Rcran NSCLC Batch api FTP todo.txt timer antialias SLURM python torque/pbs ExecOnCommand NGS TrainOfThought Conky Ubuntu mpd VMplayer LaTeX Paired-End natbib R cloudformation PHP compress Perl Image cotd javascript XFS telenet tikz Password windows Yelo.tv Searching terraform GATK osd_cat apoptosis Cluster cromwell HPC NFS Recovery Remote fancy line-end BASH AWS Installation Typesetting whitespace proftpd dos2unix preamble indent Linespacing spam Literature Headless Apache CPAN bibtex docker drmaa sudoers VMware fuzzy match spotify
Log in
Save Spotify to flac or mp3
Posted on 2018-07-14 14:23:10
by Geert Vandeweyer
Loading Content
Save Spotify to flac or mp3
Posted on 2018-07-14 14:23:10
by Geert Vandeweyer
Disclaimer
I like spotify. That's why I have a paid subscription. I also like music in general, as do my kids. That's why I have a "jooki" media player, which has a built in spotify client. The problem here is, that jooki needs an active wifi connection to connect to spotify, in order to listen to music. when the kids want to use it on the road, you need to have the music on an internal SD card, which makes sense.
Given that I paid for the media center, and for the spotify subscription, I feel that I'm allowed to save spotify songs to the SD card to re-listen to them while not connected to wifi (jooki does not support spotify offline).
I do realize that the script discussed below might be used for actions that are not compatible with local laws and or contracts. So use it at your own risk & responsibility !
Best,
Geert
NOTE: This method relies on pulseaudio-tools version 8 or higher. It was tested on linux minut 18.2
Overview
I needed a way to save spotify playlists into regular MP3 and/or FLAC files, instead of the encoded spotify downloads. The below procedure allows you to do this, and gives a structured library in the format of "artist / album / nr - track", with metadata filled in in the ID3 tags. It has the following prerequisites:
- a linux machine using pulse-audio (eg kubuntu)
- ffmpeg : the all-round media conversion tool, with support for mp3 and flac (compile-time options, usually, this is default)
- spotify (duh)
- pacmd , pactl : pulse-audio commandline control tools. Part of pulseaudio-utils on ubuntu
- qdbus : part of the QT intrface libraries (KDE related)
- sp : a commandline spotify handler : see here
- sox : another media conversion tool.
Get the script.
The script is hosted on bitbucket. To get the latest version, run the following command (you need git for this):
git clone https://bitbucket.org/geertvandeweyer/spotify_recorder
Use the script
First, you need a spotify-URI of the playlist, album, or song you want to save. Open spotify, and for any item, click the three dots next to the item, go to 'share' and select 'copy spotify URI (shows with while pushing Ctrl):
Next, run the command as follows:
perl stream_recorder.pl --uri 'spotify:album:3BS9MUmVKghsOa7Y3otqpE' --silent --format flac --outdir /home/gvandeweyer/media/Spotify_Recordings/
Options are:
- silent : mute spotify while recording
- outdir : where to create the media files
- uri : either a single uri, or a fille of uris (one per line)
- format : either flac or mp3
- tmpdir : use a custom tmp dir, which will not be deleted
- postprocess : Only reperform the splitting on a wav in the tmp dir. This allows you to alter the track timings manually
- latency : set the parec latency. This can help if the beginning of the track is missing
- compilation : for compilation disks, alter the file structure
- ignore : if set, detection if commercials is ignored
Perl, spotify
Comments
How do you install the sp script as a binary / command?
perl command results in:
Missing Binaries: - sp Note: sp (command line controller) can be downloaded from : https://gist.github.com/wandernauta/6800547
Hi Eddie,
Follow these steps to add the script to your $PATH.
# download the script from github (or use git clone) wget -O sp.zip 'https://gist.github.com/wandernauta/6800547/archive/2c2ad0f3849b1b1cd1116b80718d986f1c1e7966.zip' # unpack to 'sp' folder unzip -d sp sp.zip # enter the folder. * enters the created subfolder (version specific) cd sp/* # make the script executable by all users chmod a+x sp # or only bu the current user chmod u+x sp # view your current $PATH echo $PATH # if /home/<user>/bin is present: cp sp ~/bin/ # else: put it in a global folder (pick one from $PATH): sudo cp sp /usr/local/bin
Now you should be able to run 'sp' from any location, and it should be recognized by the script.
Hi,
I have 2 issues with the script:
- Error "Could not find spotify sink" - "Stream error: Entity killed".
It seems that pacmd list-sink-inputs finds no sink when called in the script (too early?). I have to re-run the script when spotify is already playing to find the sink.
I only know that the second comes from pulseaudio, but no idea what is the issue.
OK, fixed my issues. I used an URI that looked like: https://open.spotify.com/album/xxxxxxxxxxxx instead of spotify:album:xxxxxxxxxxxxxxxxx. This opens the right album but does not play it correctly.
Hello,
Works very well, but the first song of each album is not working: very small file with duration of a few seconds. Did you notice anything similar?
Hi,
I have tried to run:
random@non-usable:~/Music/spotify.rip/spotify_recorder$ perl stream_recorder.pl --uri 'spotify:album:4ROcfZVam2pemXs3hxXLQo' --silent --format flac --outdir /home/random/Music/spotify.rip/ Muting speakers to load spotify stream... Loading spotify URI Unmuting speakers Could not find spotify sink
@KK
I had the same problem. with this change it works for me (on ubuntu 18.04):
diff -r 22d04a8af142 stream_recorder.pl --- a/stream_recorder.pl Sat Jul 14 13:16:44 2018 +0200 +++ b/stream_recorder.pl Mon Jul 30 16:23:16 2018 +0200 @@ -203,7 +203,7 @@ $current_out = $1; next; } - if ($sink_idx ne '' && $line =~ m/client.*Spotify/) { + if ($sink_idx ne '' && $line =~ m/application\.name.*spotify/) { $ok = 1; last; }
ah and not 100% sure, but I guess it started working after I installed sox via apt.
Hi tobo,
Thanks for the fix. I've applied it to repository !
thank you for your work. I've started looking for a solution today and found your project within a minute, about 15 minutes later, everything was working! thanks!
no problem. now up to fixing this 5 year old & nevere maintained website :-)
Hi. Many thanks for the provided method! Everything works like a clock :)
Hi Geert, thanks for your tool! I've got only one problem: it worked for me in August, but now I run into the same problem as shown above and don't know why:
Could not find spotify sink
Do you have any reason why this happens again? I installed your latest version, but it doesn't work.
Regards, Mikl
noel@noel-X55A:~$ perl stream_recorder.pl --uri 'spotify:album:3BS9MUmVKghsOa7Y3otqpE' --silent --format flac --outdir /home/gvandeweyer/media/Spotify_Recordings/perl stream_recorder.pl --uri spotify:artist:44NX2ffIYHr6D4n7RaZF7A --silent --format flac --outdir /home/gvandeweyer/media/Spotify_Recordings/ Can't open perl script "stream_recorder.pl": No such file or directory noel@noel-X55A:~$
Hi Miki,
I've had some troubles with using the script in combination with Bluetooth headphones. I've adapted and uploaded. Can you try the last version. If it doesn't work, please send me the output of 'pacmd list-sinks' and 'pacmd list-sink-inputs'
Best, Geert
Hi Noe,
Are you sure that you are in the directory holding the script? can you run the follwing command , and make sure you see stream_recorder.pl :
ls -alh
Also, in the past above, you copied the command twice, but that might be a copy/paste error here.
Third, Make sure you adapt the output location (here /home/gvandeweyer/media/Spotify_Recordings) to a location on you system. the example you pasted is from the tuturial here, but is a path on my laptop, so that's not gonna work for you.
best
geert
Hi Geert,
Thanks for the great script. It *should* be working for me; I can see it's performing almost as expected. I'm just having a couple problems, as you can see:
>>> >>> Recording... parec: unrecognized option '--monitor-stream=1' 0.0004s Hiram 345.5720s Love It All 516.7919s Hiram2 Splitting the stream into tracks... Hiram sox error splitting file: 512
So I'm guessing the "unrecognized option" is from pulseaudio. I don't know if that is what is causing the sox file-splitting error. As another user mentioned, the first file in any album or playlist I try to record is truncated after only a couple of seconds.
Do you have any idea where my problem lies? (I know you have much better things to do than act as tech support, but greatly appreciate your input)
Hi netaloid,
Could you tell me the version of your distro, parec and sox?
I've also revised the loading and starting this week. Check if you have the latest version using
Hg incoming Hg pull -u
Hi Geert,
hi netaloid,
I've just added some more error handling and logging. Make sure to update if you're still having troubles :-)
Hi Peter,
I've tried realtime splitting, while recording but that didn't work out. I can have a look on how to implement your suggestion.
If you're up to it, feel free to make a pull request
Hi Geert,
I assumed so :) But maybe real-time splitting is the wrong approach. Would stopping the recording (as if the Playlist would be finished) and resuming the playlist after splitting & storing with a new temp file etc be possible?
Regards,
Peter
Thanks, Geert,
I'm running Linux Mint 17.3, parec version returns this: "pacat 4.0 Compiled with libpulse 4.0.0 Linked with libpulse 4.0.0" and my sox version is 14.4.1
best,
netaloid
Hi,
I've tested on an old machine, and the 'monitor-stream' is not available yet in ubuntu 14 / mint 17, using pacat 4. I'm on mint 18 and have pacat version 8.
The sox error is due to the captured file being absent, so it's related to the outdated pulseaudio-utils package (offering pacat & parec)
Maybe you can upgrade that package ?
Best,
Geert
Hello!
At the output, I get files with variable bitrate (mp3). I guess the encoder is VBR?
How can I change it to CBR?
Thanks.
Hi Vladislav,
You are right, mp3 is set equivalent to lame -V 0 settings. To use constant bitrate, change the script at line 124:
if ($format eq 'mp3') { $options{'encoder_opts'} = '-vn -y -codec:a libmp3lame -q:a 0'; $options{'encoder'} = 'ffmpeg'; }
This must be changed to :
if ($format eq 'mp3') { $options{'encoder_opts'} = '-vn -y -codec:a libmp3lame -b:a 320k'; $options{'encoder'} = 'ffmpeg'; }
Where -b:a 320K is the constant bitrate. See here for details: https://trac.ffmpeg.org/wiki/Encode/MP3
Couldnt detect spotify binary after I installed via snap for some reason, had to symlink in /usr/bin/ and then all ok :-)
Hi Geert,
sorry, it took a while ... just tested your actual version, but didn't get far :)
BTW: my spotify URI was not recognized correctly - another album was taken.
And this eror is shown:
Spotify StreamRecorder encountered a problem with ffmpeg:
(version info: libGL error: unable to load driver: i965_dri.so)
ffmpeg could not convert the splitted stream:
The exit code was 256
Thanks :)
Hi, thanks for an amazing script!! Appart from Windows, I've only ever dabbled with Raspbian and Android but managed to get this working running Kubuntu on a VM off a Win10 host. Thanks very much.
Hi, thanks for the script an tutorial.
Im new ti linus and so on. But i got i going.
One question: how can i get sound for another application like youtube or other streaming site during download from spotify (in silent mode)?
Thanks for the great work
Hi Sebb,
For me, this just works. Only the spotify stream is silenced. I can listen to youtube in a browser without a problem.
Do you get errors somewhere?
Hi Geert,
when I open the sound settings (Klangeinstellungen in German) there is "Null-Ausgabe" (?Zero-Output?) marked. All is silenced. If I change to build-in speakers (Lautsprecher eigebautes Tongerät) all streams, also the spotify-stream is not muted.
I am using a Notebook. Maybe there is only on or off for speakers and no "this application on, this muted"?
got this message after entered the spotify url of a song,
"Can't
open
perl script
"stream_recorder.pl"
: No such
file
or directory"
any solution?
heyy thanks for this awsome script. Only one problem though:
Spotify StreamRecorder encountered a problem with sox:
(version info: sox: SoX v14.4.2)
Sox could not split the streamfile
Inappropriate ioctl for device
The exit code was 512
this happents to me while using a txt file with different uris (one for line)
the script loads one or two of the links and than gives this error
Hey Geert!
Thanks for this awesome script. One small improvement: Can you automatically turn off "repeat"? Otherwise the script can hang in an endless loop unless one ends it manually :)
Best regards, knut
@Helpless : make sure the script is in your path "/home/myUsername/bin/stream_recorder.pl". Otherwise use 'perl stream_recorder.pl' in the dir where the script is.
@kris : are you sure the URI is correct? I've seen that error if there is no recorded file to split (the actual parec didn't work).
@Knut : unfortunately not. There is no commandline control on repeat & shuffle for spotify.
Hey,
I could need some help with this error message:
-
Error org.freedesktop.DBus.Error.ServiceUnknown: The name org.mpris.MediaPlayer2.spotify was not provided by any .service files
-
Failing program : sp
-
sp 0.1
https://pastebin.com/abxFd789
I don't know whats wrong.. I even had everything running a month ago, but now I am missing something?
Sorry for douple post, but now its working.
I have the script running inside a virtual machine (virtualbox) and I was trying to get it running with ssh, vnc etc. The only thing thats working right now is, when I start spotify first within the remote desktop and then the script. Otherwise it always fails..
Hi zhe,
Since you mention ssh, make sure that you have x-forwarding enabled. can you start other GUI programs form the commandline? try 'xeyes' or gedit ?
Yeah that option is activated. I don't know why, but there seems to be a difference in the behavior of spotify, when its manually started by the gui compared to the behavior when its started by the script or terminal. Is that possible?
In the remote desktop everything seems to work.
So I think I am missing one little step to get it to work. Maybe I will just have to live with the solution, that I have to start spotify manually first
Hey Geert,
thanks for your awesome work to share with us. Its works very good, but ive a problem if you want to record a whole album. I think theres a kind of copy protection from spotify, but im not sure. I just want to use it to rip some audio for my car. Ive no bluetooth or other possibilty to get the music directly playable from spotify. So i tried this way.
My problem is that if you want to rip a whole album, some songs will end in the beginning of the next song. So if you rip this, youll have a cut in the end of the song and the next song starts with the end of the first song.
If you go to the album childrem of bodom - are you dead yet (I know its not the kind of music for everyone). So if you play the first song and just jump to the past 5 seconds, you can regconize my problem. Just want to double check if you have the same issue like me.
thanks!
regards
Hey Geert,
im sorry for posting again. Just want to say that ive tested a few other tracks too and its looks to me that the timing is not correct. You did some settings in your script for "strange commerical timings". But I dont get it what it does, maybe you can explain it a little bit.
regards
Hi, I'll look into it next week. I'm not at home right now.
The 'cormmercial timing' was a hack to get around the commercials, because they lead to incorrect song cutting for some reason. I now have a full version, so I don't use it anymore. are you on a free or full version?
Hi Geert,
thanks for your reply. You mean the spotify account? Ive a premium account, so the full version.
regards!
Hello,
I am getting the following error:
"Can't
open
perl script
"stream_recorder.pl"
: No such
file
or directory
I ran ls - alh as you recommended above, and I do not see stream_recorder.pl anywhere
I cannot figure this out. :/
Hi. Regarding the sox error error while splitting: I traced it to a Spotify setting, specifically the one that enables autoplay. So go to Spotify->Settings and disable autoplay, and everything should work.
Longer explanation: when autoplay is on, Spotify will continue to play music adding similar tracks to your playlist. This confuses the script as it keeps monitoring the playback status of the application, and it might not "stop" as predicted, under control of the script, depending on how you close the app.
Hi Geert,
could you already take a look? ive tested this now on linux mint 19.1 with the lastest spotify release 1.0.96.181.gf6bc1b6b. Ive still the same problem.
regards!
@Kat : make sure you enter the created folder :
hg clone https://bitbucket.org/geertvandeweyer/spotify_recorder cd spotify_recorder perl stream_recorder.pl
That should do it...
@pLEX : I'm recording the CoB album right now, and will get back to you. Nice album by the way. I've seen them live a few times at festivals (wasn't really my cup of tea), but never tried their studio work. Its more digestible
@pLEX : The incorrect timing seems to be album specific, and related to this particular COB album.
I have the same issue, but haven't seen it for different albums. Do you also see it on other albums? And do you consider it to be progressing (more delay for each consecutive track) ?
I'll see if I can find a fix, but I can't think of one immediately.
Hey Geert,
thanks for your reply. Nice to hear that you like it too :) But i know what you mean, I saw them on some festivals too, but I like the studio album more :)
Yes, i had that on the most albums which I tried, but the timestamps are very different, so maybe it will be hard to fix it.
For example:
Terror - Total Retaliation
Eyes Wilde Open - And so It Begins
Grup Huub - Charivari
This are the albums where im sure that i had the problem. I will do some more tests and can reply again.
regards
Hello Geert,
thanks for this great script. I also see issues like pLex discribed. Full spotify version here as well.
Best regards
Stephan
HI, cool script.
so I believe I am doing everything corectly, and the script runs. but my output, using either flac or mp3 as the format, comes up far too small. flac ~34kb. mp3 ~700kb.
Hi Geert,
Just like Evan, I dont see any errors, yet my output is very small in size and I can't play the files.
Do you maybe have any idea why is this happening and what can be done?
Thanks
Hi Greet, cool script by the way.
I was thinking if there is a way to download the album artwork along with the songs and attach them in the end.
hi so this happens when i try to run the command
luke@luke:~/spotify_recorder$ perl stream_recorder.pl --uri 'spotify:user:d2ae4c6e2bnp74xf8sx7ro6cd:playlist:0VQzDpHUQyYyEj8iDpsLwy' --silent --format mp3 --outdir /home/user/Music/
Missing Binaries:
- ffmpeg
luke@luke:~/spotify_recorder$
edit: the comment format messed the thing up but i did type the command correctly
hi geert,
thank you for this awesome script!
I would have 2 (small???) modification request and was wondering if you could do this (if it doesn't take too long and is too much work of course!). I'm using the "file" option with single uri's per line.
1. Is it possible to show the line/uri number when Recording starts? e.g. likt htis in the line "Loading spotify URI: $uri, $LinenumberofFile" With this you could easily adapt (e.g. delete already downloaded lines of uris) and restart the uri file when there is an error in between.
2. Would it be possible to implement an option to skip already downloaded files? In this case the first modification would still be useful but not needed.
If you don't have time or interest, could you give me some hints for commands that I could google and try to implement? I can program but perl is new to me :)
Thanks in advance!
hey Luke,
try "sudo apt-get install ffmpeg"
cheers,
Jonathan
Thank you very much for this wonderful script, i was able to use it compiling sox and lame, choosing --
format
flac doesn't work for me the mp3 file generated is corrypted only a few bytes, i changed this option to
--
format
mp3 and works great, thanks a lot
Hi Is´t posible to optimize/adjust the recorder?...
It´s no longer posible to adjust the gab in Spotify and the recorder cuts about 3 sec of the track, these 3-5 sec i paste in, in the next track :-/
I have an premium account.
Can I adjust timings for commercial or the trim time?....
I think it´s commercials setting there give me this problems
# commercials lead to strange timings.
my @pp = split(///,$this_title);
if ($pp[0] eq '') {
# this_ is a commercial.
# extend previous.
$this_start += 1.5;
$commercial = 2;
}
elsif ($commercial == 2) {
# prev_ was a commercial, need to adjust the next round.
$commercial = 1;
}
elsif ($commercial == 1) {
# writing song after commercial.
$prev_start += 1.5;
$commercial = 0;
Hi Agian
I Have now a problem with the 1st song in the playlist, it´s only 49 KB, insted of aboud 4-5 MB... Why?
I use Allavsoft to download and convert Spotifty to MP3.
Allavsoft can download Spotify to MP3, FLAC, WAV, M4A, AAC etc
It also helps to download from Spotify, Deezer, Soundcloud, YouTube, Vimeo etc
Awesome job. Larry Wall would be proud :) Your code is clean and consise as well! TYVM.
Hi, I have a problem with the spotify sink as well:
using tmpdir : /tmp/a3DTJHTWLq
Muting speakers to load spotify stream...
Loading spotify URI
Could not find spotify sink : This was the output from pacmd list-sink-inputs:
4 sink input(s) available.
index: 67
driver: <protocol-native.c>
flags:
state: DRAINED
sink: 0 <alsa_output.pci-0000_00_1b.0.analog-stereo>
volume: mono: 65536 / 100% / 0,00 dB
balance 0,00
muted: no
current latency: 0,00 ms
requested latency: 0,50 ms
sample spec: s16le 1ch 44100Hz
channel map: mono
Mono
resample method: copy
module: 10
client: 36 <speech-dispatcher>
properties:
media.name = "playback"
application.name = "speech-dispatcher"
native-protocol.peer = "UNIX socket client"
native-protocol.version = "30"
application.process.id = "19903"
application.process.user = "patricia"
application.process.host = "Miezekatz"
application.process.binary = "sd_dummy"
application.language = "C"
window.x11.display = ":0"
application.process.machine_id = "47388fbb1e434c5bbc90cc3e255231d2"
application.process.session_id = "c2"
module-stream-restore.id = "sink-input-by-application-name:speech-dispatcher"
index: 68
driver: <protocol-native.c>
flags:
state: DRAINED
sink: 0 <alsa_output.pci-0000_00_1b.0.analog-stereo>
volume: mono: 65536 / 100% / 0,00 dB
balance 0,00
muted: no
current latency: 0,00 ms
requested latency: 1,00 ms
sample spec: s16le 1ch 44100Hz
channel map: mono
Mono
resample method: copy
module: 10
client: 37 <speech-dispatcher>
properties:
media.name = "playback"
application.name = "speech-dispatcher"
native-protocol.peer = "UNIX socket client"
native-protocol.version = "30"
application.process.id = "19906"
application.process.user = "patricia"
application.process.host = "Miezekatz"
application.process.binary = "sd_espeak"
application.language = "C"
window.x11.display = ":0"
application.process.machine_id = "47388fbb1e434c5bbc90cc3e255231d2"
application.process.session_id = "c2"
module-stream-restore.id = "sink-input-by-application-name:speech-dispatcher"
index: 69
driver: <protocol-native.c>
flags:
state: DRAINED
sink: 0 <alsa_output.pci-0000_00_1b.0.analog-stereo>
volume: mono: 65536 / 100% / 0,00 dB
balance 0,00
muted: no
current latency: 0,00 ms
requested latency: 2,00 ms
sample spec: s16le 1ch 44100Hz
channel map: mono
Mono
resample method: copy
module: 10
client: 38 <speech-dispatcher>
properties:
media.name = "playback"
application.name = "speech-dispatcher"
native-protocol.peer = "UNIX socket client"
native-protocol.version = "30"
application.process.id = "19911"
application.process.user = "patricia"
application.process.host = "Miezekatz"
application.process.binary = "sd_cicero"
application.language = "C"
window.x11.display = ":0"
application.process.machine_id = "47388fbb1e434c5bbc90cc3e255231d2"
application.process.session_id = "c2"
module-stream-restore.id = "sink-input-by-application-name:speech-dispatcher"
index: 70
driver: <protocol-native.c>
flags:
state: DRAINED
sink: 0 <alsa_output.pci-0000_00_1b.0.analog-stereo>
volume: mono: 65536 / 100% / 0,00 dB
balance 0,00
muted: no
current latency: 0,00 ms
requested latency: 2,00 ms
sample spec: s16le 1ch 44100Hz
channel map: mono
Mono
resample method: copy
module: 10
client: 39 <speech-dispatcher>
properties:
media.name = "playback"
application.name = "speech-dispatcher"
native-protocol.peer = "UNIX socket client"
native-protocol.version = "30"
application.process.id = "19915"
application.process.user = "patricia"
application.process.host = "Miezekatz"
application.process.binary = "sd_generic"
application.language = "C"
window.x11.display = ":0"
application.process.machine_id = "47388fbb1e434c5bbc90cc3e255231d2"
application.process.session_id = "c2"
module-stream-restore.id = "sink-input-by-application-name:speech-dispatcher"
perl stream_recorder.pl --uri 'spotify:album:5up2eDxegvbaShlzLPiQEQ' --silent --format flac --outdir /home/brian/Music
using tmpdir : /tmp/dfAsg48ndr
Muting speakers to load spotify stream...
Loading spotify URI
rerouting spotify stream to a black hole (you won't hear it)
Recording...
0.0008s Mary Black/No Frontiers/01 - No Frontiers
Splitting the stream into tracks...
Creating Mary Black/No Frontiers/01 - No Frontiers
Cleaning up tmpdir
Sadly, as above, only one short file is produced.
Ideas?
root@kali:/home/linux/git/spotify_recorder# perl stream_recorder.pl --uri 'spotify:album:3BS9MUmVKghsOa7Y3otqpE' --silent --format mp3 --outdir /home/linux/Music/Spotify
Missing Binaries:
- sox
- lame
- qdbus
root@kali:/home/linux/git/spotify_recorder#
Hi Geert,
Thanks for your clever work on this and for sharing it, it works a treat. Running Spotify premium, Linux Mint 19.
Regards Malcolm
Thanks for amazing script. I ve returned Linux from Mac and this kind of mac was the thing i most miss from Mac. Working great as long as Pulseaudio has been upgraded to v12.0.
Hi Geert and/or others who might be able to help
I am trying to use this script but keep on getting errors when its supposed to split and save the tracks to respective folders:
Spotify StreamRecorder encountered a problem with mkdir: (version info: mkdir (GNU coreutils) 8.28)
Could not create output directory /home/...
The exit code was 256
Does anyone have a clue?
All help is much appreciated
Although it says rerouting to a black hole, I can still hear the track? There are no errors and a 5mb mp3 file is produced however it is silent? Any advice?
Hey Geert, thanks for your amazing script, but it was appear:
perl stream_recorder.pl --uri 'spotify:album:0Jj2DO9zXQwZJIdljOX7O5' --unmute --format mp3 --outdir /home/vinceney/Music/
Unknown option: unmute
using tmpdir : /tmp/CHhVhEACGs
Muting speakers to load spotify stream...
Loading spotify URI
sh: 1: sp: not found
Spotify StreamRecorder encountered a problem with sp:
(version info: )
Spotify stream could not be loaded
No such file or directory
The exit code was 32512
The temporary folder is retained, so make sure to delete it:
- /tmp/CHhVhEACGs
Please provide the contents of the logs when reporting this issue:
- General Log : /tmp/CHhVhEACGs/run.log
- parec Log : /tmp/CHhVhEACGs/parec.log
- Share on : https://pastebin.com/
Hi Geert,
Great script, works like a charm, thank you very much for sharing !
cheers,
yann
(config: spotify premium and Ubuntu 18.04.4 LTS)
@error_reading_file (post 2020-04-04 17:23:30 above) : you need to have "sp" installed, the instructions of Geert (see above post: 2018-07-23 12:07:45) worked for me
Allavsoft also helps to download Spotify music to MP3 or FLAC.
Spotify to MP3:
Step 1: Copy and paste the Spotify url to Allavsoft.
Step 2: Click Download button.
Spotify to FLAC:
Step 1: Copy and paste the Deezer music url
Step 2: Click Option-> Preference to open the Preference window (Mac computer: Click the "Allavsoft" ->"Preference" button), then switch to Advanced tap to check before "Download FLAC music with cover art"
Step 3: Click Download button.
qdbus: could not find a Qt installation of ''
It would be nice if you could specify a different tmp dir than /tmp
/tmp on my system is on ram so fairly small/
ripping compilation CD's is a bit annoying as titleArtist is used to write the tags.
I changed into artist.
But after that each item is recorded in a different folder as artist the top level folder.
I changed locally to have the album as top level folder.
It may be interesting to make this an option (didn't get to it yet, my merl is not that good).
Hi Geert,
Cool script..
I was the one who make the comment on /tmp before.
I'm not really a perl programmer but below is a context diff to add an option tmpdir to specify the directory to be used as tmp dir.
Feel free to reuse whatever you find useful
Frans
*** stream_recorder.pl.orig 2020-08-02 11:42:14.439764282 +0200
--- stream_recorder.pl 2020-08-02 12:23:46.560179643 +0200
***************
*** 4,9 ****
--- 4,10 ----
use Getopt::Long;
use Data::Dumper;
use File::Temp;
+ use File::Path qw(make_path);
##############
## SETTINGS ##
***************
*** 21,27 ****
#############
## PREPARE ##
#############
! our $tmpdir = File::Temp->newdir(CLEANUP => 0);
print "using tmpdir : $tmpdirn";
## get main sink.
my $main_out = GetMainSink();
--- 22,39 ----
#############
## PREPARE ##
#############
! our $tmpdir = $options->{'tmpdir'};
! if ($tmpdir eq "") {
! $tmpdir = File::Temp->newdir(CLEANUP => 0);
! }
! else {
! if (!-d $tmkdir) {
! make_path $tmpdir or die "Could not create $tmpdir";
! }
! else {
! die "$tmpdir already exists";
! }
! }
print "using tmpdir : $tmpdirn";
## get main sink.
my $main_out = GetMainSink();
***************
*** 114,125 ****
my $format = 'mp3'; # can be mp3 or flac
my $outdir = './Results'; # where should we create the artist/album/track structure
my $uri = '';
GetOptions ( 'silent' => $silent,
'format=s' => $format,
'outdir=s' => $outdir,
! 'uri=s' => $uri
);
! my %options = (silent => $silent, 'format' => $format, 'outdir' => $outdir, 'uri' => $uri);
if ($format eq 'mp3') {
$options{'encoder_opts'} = '-vn -y -codec:a libmp3lame -q:a 0';#"-r -V0 -b 192 - -";
$options{'encoder'} = 'ffmpeg'; #'lame';
--- 126,139 ----
my $format = 'mp3'; # can be mp3 or flac
my $outdir = './Results'; # where should we create the artist/album/track structure
my $uri = '';
+ my $tmpdir = '';
GetOptions ( 'silent' => $silent,
'format=s' => $format,
'outdir=s' => $outdir,
! 'uri=s' => $uri,
! 'tmdir=s' => $tmpdir
);
! my %options = (silent => $silent, 'format' => $format, 'outdir' => $outdir, 'uri' => $uri, 'tmpdir' => $tmpdir);
if ($format eq 'mp3') {
$options{'encoder_opts'} = '-vn -y -codec:a libmp3lame -q:a 0';#"-r -V0 -b 192 - -";
$options{'encoder'} = 'ffmpeg'; #'lame';
***************
*** 365,370 ****
--- 379,388 ----
$cmd = "pactl unload-module $module >>$tmpdir/run.log 2>&1";
system($cmd) == 0 or SpeakEnglishAndDie("Error closing the black holen$!",$?,"pactl");
}
+ # if we created our own tmpdir remove it
+ if $options->{'tmpdir'} eq "") {
+ rmdir $tmpdir
+ }
}
And this patch uses the artist tag instead of the albumArtist tag
Better for complilations
index 4f8cabc..03801ec 100755
--- a/stream_recorder.pl.sav
+++ b/stream_recorder.pl
@@ -321,11 +321,11 @@ sub ChildOfTimer {
}
my $track = '';
if ($meta{'discNumber'} > 1) {
- $track = $meta{'albumArtist'}."/".$meta{'album'}." - CD".$meta{'discNumber'}."/".sprintf("%02d",$meta{'trackNumber'})." - ".$meta{'title'};
+ $track = $meta{'artist'}."/".$meta{'album'}." - CD".$meta{'discNumber'}."/".sprintf("%02d",$meta{'trackNumber'})." - ".$meta{'title'};
}
else {
- $track = $meta{'albumArtist'}."/".$meta{'album'}."/".sprintf("%02d",$meta{'trackNumber'})." - ".$meta{'title'};
+ $track = $meta{'artist'}."/".$meta{'album'}."/".sprintf("%02d",$meta{'trackNumber'})." - ".$meta{'title'};
}
# new track : write out startpoint.webapps/ua-pintra_shib_translate_module-BBLEARN/module/sbmt_index.jsp
if ($track ne $current) {
oops, made a error in the tmpdir diff;
THis line: ! 'tmdir=s' => $tmpdir
should be
! 'tmpdir=s' => $tmpdir
so the option name should be tmpdir. I only tested with -t :-(
Next set of changes: this adds a flag for compilation albums and fixes an issue with tmpdir
*** stream_recorder.pl.sav2 2020-08-02 13:02:23.352193301 +0200
--- stream_recorder.pl 2020-08-02 23:20:10.444989116 +0200
***************
*** 35,40 ****
--- 35,41 ----
}
}
print "using tmpdir : $tmpdirn";
+ print "compilation : $compilationn";
## get main sink.
my $main_out = GetMainSink();
my $all_sinks = GetAllSinks();
***************
*** 127,137 ****
my $outdir = './Results'; # where should we create the artist/album/track structure
my $uri = '';
my $tmpdir = '';
GetOptions ( 'silent' => $silent,
'format=s' => $format,
'outdir=s' => $outdir,
'uri=s' => $uri,
! 'tmdir=s' => $tmpdir
);
my %options = (silent => $silent, 'format' => $format, 'outdir' => $outdir, 'uri' => $uri, 'tmpdir' => $tmpdir);
if ($format eq 'mp3') {
--- 128,140 ----
my $outdir = './Results'; # where should we create the artist/album/track structure
my $uri = '';
my $tmpdir = '';
+ our $compilation = 0;
GetOptions ( 'silent' => $silent,
'format=s' => $format,
+ 'compilation!' => $compilation,
'outdir=s' => $outdir,
'uri=s' => $uri,
! 'tmpdir=s' => $tmpdir
);
my %options = (silent => $silent, 'format' => $format, 'outdir' => $outdir, 'uri' => $uri, 'tmpdir' => $tmpdir);
if ($format eq 'mp3') {
***************
*** 380,386 ****
system($cmd) == 0 or SpeakEnglishAndDie("Error closing the black holen$!",$?,"pactl");
}
# if we created our own tmpdir remove it
! if $options->{'tmpdir'} eq "") {
rmdir $tmpdir
}
}
--- 383,389 ----
system($cmd) == 0 or SpeakEnglishAndDie("Error closing the black holen$!",$?,"pactl");
}
# if we created our own tmpdir remove it
! if ($options->{'tmpdir'} eq "") {
rmdir $tmpdir
}
}
***************
*** 448,453 ****
--- 451,459 ----
$pp[0] = 'Commercials';
}
my $path = join("/",@pp);
+ if ($compilation == 1) {
+ $path = $pp[1];
+ }
my $artist = $pp[0];
my $album = $pp[1];
$nr_title =~ m/(d+) - (.*)/;
Hmm, it seems that parec initially gets some bad or unsychronised data. There are some gaps in the first 30 seconds or so.
If I start spotify first manually I seem to have no problem
Hi, it looks like the projects is gone on bitbucket could you upload it somewhere please ?
jep - i get massage like : "abort: HTTP Error 404: Not Found" when trying to download your script
Hi Geert
i also cant find the "streamrecorder.pl".
i would really appreciate it if you could upload the file.
thanks!
peter
I recommend Allavsoft. Allavsoft can download music from Spotify to MP3, FLAC, WAV etc
It also can download from soundcloud, youtube, vimeo, twitter, facebook etc
Could you please convert your project to GIT and post it again on bitbucket? Bitbucket shut down all of its mercurial based repos. I recommend using fast-export.
I found the script here: https://github.com/maximilianvoss/spotify-toniebox-sync/blob/master/bin/stream_recorder.pl
It is gone from that github too. Did you sell and got rid of everything?
Archived here:
https://archive.softwareheritage.org/browse/content/sha1_git:1946c7eb96d77b1494ed88ed1b60412ae5cad999/?origin_url=https://bitbucket.org/geertvandeweyer/spotify_recorder&path=stream_recorder.pl
Less complicated URL :
https://archive.softwareheritage.org/browse/origin/directory/?origin_url=https://bitbucket.org/geertvandeweyer/spotify_recorder
Thank you for the link to the archive ! I've recreated the repository using git, and included Franks suggestions.
Geert
qdbus: could not find a Qt installation of ''
try "sudo apt install qdbus-qt5"
Spotify StreamRecorder encountered a problem with mkdir: (version info: mkdir (GNU coreutils) 8.28)
Could not create output directory /home/...
The exit code was 256
Make sure the outdir exists!
Hi Geert, thanks for this program. The timings seem off for me, even when just capturing a single track. I noticed that the ignore and postprocess switches don't seem to be catered for in the version currently hosted on Git. Have these been removed? Postprocess in particular would be useful...
Hi Geert
I was trying to install but I need authentication. Can you help me?
Thanks
Hi Geert,
Thanks for sharing this program. I'm having the following problem:
"Could not find spotify sink "
I read the comments and I know that some users experienced the same problem, but I couldn't find a solution for my case. This is the script that I used:
perl stream_recorder.pl --uri 'https://open.spotify.com/playlist/7qpmBEeVSoRAxie3bePhTr?si=be1c0b31d4404d3b' --silent --format flac --outdir /home/gvandeweyer/media/Spotify_Recordings/
The output was the following:
using tmpdir : /tmp/_4TM1GAFqp
Shutting down spotify
Restart Spotify
... waiting for spotify to start
Muting speakers to load spotify stream...
Loading spotify URI : https://open.spotify.com/playlist/7qpmBEeVSoRAxie3bePhTr?si=be1c0b31d4404d3b.
Could not find spotify sink : This was the output from pacmd list-sink-inputs:
1 sink input(s) available.
index: 22
driver: <protocol-native.c>
flags: START_CORKED
state: RUNNING
sink: 4 <alsa_output.pci-0000_00_1f.3-platform-skl_hda_dsp_generic.HiFi__hw_sofhdadsp__sink>
volume: front-left: 65536 / 100% / 0.00 dB, front-right: 65536 / 100% / 0.00 dB
balance 0.00
muted: no
current latency: 31.25 ms
requested latency: 18.75 ms
sample spec: float32le 2ch 48000Hz
channel map: front-left,front-right
Stereo
resample method: copy
module: 10
client: 5 <Firefox>
properties:
media.name = "AudioCallbackDriver"
application.name = "Firefox"
native-protocol.peer = "UNIX socket client"
native-protocol.version = "33"
application.process.id = "7191"
application.process.user = "meneses"
application.process.host = "6400l-212660-l.mobility.unimelb.net.au"
application.process.binary = "firefox"
application.language = "en_AU.UTF-8"
window.x11.display = ":1"
application.process.machine_id = "5e1075df20337bf263b0991e63c89121"
module-stream-restore.id = "sink-input-by-application-name:Firefox"
Please report this
Could you please help me with this problem?
Huge thanks for the script, and thanks to Franz for the tmpdir fix. I think the easiest thing for compilations is to manually change the outdir each time to include a parent directory for the title of the playlist/album.
Hi,
Is there any way to continue the post process if the script failed to create a folder?. Because I've the .wav file now, but is not chopped into different .mp3 files.
Thanks.
Hi!
I cannot figure out how to let it work. The script closes and re-open spotify client and then it returns the answer:
Could not find spotify sink : This was the output from pacmd list-sink-inputs:
0 sink input(s) available.
If I quickly press play after the script started the spotify client, it starts downloading the first song and then end without error, but the downloaded song is a very little file with no sound and the rest of the playlist is not downloaded at all.
How did you solve it?
Same here:
Could not find spotify sink : This was the output from pacmd list-sink-inputs:
Please report this
Hey!
I used the script and had everything functioning fine when i used your example of the zztop album, but when i try to give it a playlist from spotify it keeps telling me that there is no sink available. The output of pacmd list-sink-inputs also gives the same output as above - i.e. 0 sink input(s) available.
Any idea what the issue could be?
Hi,
I just wanted to let you know it worked for me. Kudos to you .
HI,
Thanks for this, seems great, I hope I can use it but for now am stuck trying to figure out the missing sp binaries missing.
I get to the last of the steps you gave back in july 2018, but the cp command at the end ('sudo cp /usr/local/bin' in my case) won't work.
I'm not familiar enough with command line to understand why it fails but from the error message I get it seems like something is missing after '/usr/local/bin' (the error message is about a missing target).
I hope someone can help !
Finally got past the missing sp issue !
Works great, thanks geert !
Hi,
Thank you for creating this tool. I like how your tool actually creates the folders and cover metadata. I attempted to use it, but I didn't have good success, it wasn't working properly, it would only convert the first 45 seconds of each track. I didn't bother trying to figure what the problem was, because I do not prefer the use of pulseaudio, which I believe was assocated with the issues encountered.. Actually, I prefer the use of pipewire and the pipewire-pulse audio server.
Pipewire actually operates very well with my Arch Linux distribution. When I attempted to use pulseaudio and the pacmd is where I seemed to run into issues that I wasn't able to resolve or troubleshoot. Plus, when using pulseaudio, I would get static sound ouput in the higher frequency audio output, which I didn't like.
I was wondering if your tool could be converted to use the preferred pipewire-pulse?
Kind regards
Hi Friend,
I couldn't test your script. I get 2 missing binaries. Do you have these also in a repo?
Missing Binaries:
- sox
- lame
got it working by installing sox and lame via apt.
now i receive the following error:
using tmpdir : /tmp/9Dpgp33vID
No PulseAudio daemon running, or not running as session daemon.
No PulseAudio daemon running, or not running as session daemon.
Shutting down spotify
Restart Spotify
... waiting for spotify to start
Muting speakers to load spotify stream...
Loading spotify URI : https://open.spotify.com/track/309THLFEXgGwta8jjgR0zq.
No PulseAudio daemon running, or not running as session daemon.
Could not find spotify sink : This was the output from pacmd list-sink-inputs:
Please report this
Hi, i update the source for using pipewire. It is possible to upload in the git to a new branch? Cheers
Comments
Loading Comments