You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
any chance we can add a track number at the begining of the filename? like Track Number - Track Title.mp3
edit: i figured it out. i just cant figure out why im getting a "No ID3 v1.x/v2.x tag found!" also not sure why the last file doesnt display a cover image in the file when i go to the folder. finally, isetup to keep the cover.jpg but i cannot for the life of me figure out how to move it to the album directory.
here it is my current jbripper.py...
!/usr/bin/env python
-- coding: utf8 --
from subprocess import call, Popen, PIPE
from spotify import Link, Image
from jukebox import Jukebox, container_loaded
import os, sys
import threading
import time
playback = False # set if you want to listen to the tracks that are currently ripped (start with "padsp ./jbripper.py ..." if using pulse audio)
rawpcm = True # also saves a .pcm file with the raw PCM data as delivered by libspotify ()
def rip_terminate(session, track):
global ripping, pipe, pcmfile, rawpcm
if pipe is not None:
print(' done!')
pipe.close()
if rawpcm:
pcmfile.close()
ripping = False
def rip(session, frames, frame_size, num_frames, sample_type, sample_rate, channels):
if ripping:
printstr('.')
pipe.write(frames);
if rawpcm:
pcmfile.write(frames)
def rip_id3(session, track): # write ID3 data
num_track = "%02d" % (track.index(),)
mp3file = "%02d" % (track.index(),)+"-"+track.name()+".mp3"
artist = track.artists()[0].name()
album = track.album().name()
title = track.name()
year = track.album().year()
directory = os.getcwd() + "/" + track.artists()[0].name() + "/" + track.album().name() + "/"
# download cover
image = session.image_create(track.album().cover())
while not image.is_loaded(): # does not work from MainThread!
time.sleep(0.1)
fh_cover = open('cover.jpg','wb')
fh_cover.write(image.data())
fh_cover.close()
# write id3 data
cmd = "eyeD3" + \
" --add-image cover.jpg:FRONT_COVER" + \
" -t \"" + title + "\"" + \
" -a \"" + artist + "\"" + \
" -A \"" + album + "\"" + \
" -n " + str(num_track) + \
" -Y " + str(year) + \
" \"" + directory + mp3file + "\""
shell(cmd)
# delete cover
shell("rm -f cover.jpg")
class RipperThread(threading.Thread):
def init(self, ripper):
threading.Thread.init(self)
self.ripper = ripper
def run(self):
# wait for container
container_loaded.wait()
container_loaded.clear()
# create track iterator
link = Link.from_string(sys.argv[3])
if link.type() == Link.LINK_TRACK:
track = link.as_track()
itrack = iter([track])
elif link.type() == Link.LINK_PLAYLIST:
playlist = link.as_playlist()
print('loading playlist ...')
while not playlist.is_loaded():
time.sleep(0.1)
print('done')
itrack = iter(playlist)
# ripping loop
session = self.ripper.session
for track in itrack:
self.ripper.load_track(track)
rip_init(session, track)
self.ripper.play()
end_of_track.wait()
end_of_track.clear() # TODO check if necessary
rip_terminate(session, track)
rip_id3(session, track)
self.ripper.disconnect()
any chance we can add a track number at the begining of the filename? like Track Number - Track Title.mp3
edit: i figured it out. i just cant figure out why im getting a "No ID3 v1.x/v2.x tag found!" also not sure why the last file doesnt display a cover image in the file when i go to the folder. finally, isetup to keep the cover.jpg but i cannot for the life of me figure out how to move it to the album directory.
here it is my current jbripper.py...
!/usr/bin/env python
-- coding: utf8 --
from subprocess import call, Popen, PIPE
from spotify import Link, Image
from jukebox import Jukebox, container_loaded
import os, sys
import threading
import time
playback = False # set if you want to listen to the tracks that are currently ripped (start with "padsp ./jbripper.py ..." if using pulse audio)
rawpcm = True # also saves a .pcm file with the raw PCM data as delivered by libspotify ()
pcmfile = None
pipe = None
ripping = False
end_of_track = threading.Event()
def printstr(str): # print without newline
sys.stdout.write(str)
sys.stdout.flush()
def shell(cmdline): # execute shell commands (unicode support)
call(cmdline, shell=True)
def rip_init(session, track):
global pipe, ripping, pcmfile, rawpcm
num_track = "%02d" % (track.index(),)
mp3file = "%02d" % (track.index(),)+"-"+track.name()+".mp3"
pcmfile = "%02d" % (track.index(),)+"-"+track.name()+".pcm"
directory = os.getcwd() + "/" + track.artists()[0].name() + "/" + track.album().name() + "/"
if not os.path.exists(directory):
os.makedirs(directory)
printstr("ripping " + mp3file + " ...")
p = Popen("lame --silent -V0 -h -r - ""+ directory + mp3file+""", stdin=PIPE, shell=True)
pipe = p.stdin
if rawpcm:
pcmfile = open(directory + pcmfile, 'w')
ripping = True
def rip_terminate(session, track):
global ripping, pipe, pcmfile, rawpcm
if pipe is not None:
print(' done!')
pipe.close()
if rawpcm:
pcmfile.close()
ripping = False
def rip(session, frames, frame_size, num_frames, sample_type, sample_rate, channels):
if ripping:
printstr('.')
pipe.write(frames);
if rawpcm:
pcmfile.write(frames)
def rip_id3(session, track): # write ID3 data
num_track = "%02d" % (track.index(),)
mp3file = "%02d" % (track.index(),)+"-"+track.name()+".mp3"
artist = track.artists()[0].name()
album = track.album().name()
title = track.name()
year = track.album().year()
directory = os.getcwd() + "/" + track.artists()[0].name() + "/" + track.album().name() + "/"
shell("rm -f cover.jpg")
class RipperThread(threading.Thread):
def init(self, ripper):
threading.Thread.init(self)
self.ripper = ripper
class Ripper(Jukebox):
def init(self, _a, *_kw):
Jukebox.init(self, _a, *_kw)
self.ui = RipperThread(self) # replace JukeboxUI
self.session.set_preferred_bitrate(1) # 320 bps
if name == 'main':
if len(sys.argv) >= 3:
ripper = Ripper(sys.argv[1],sys.argv[2]) # login
ripper.connect()
else:
print "usage : \n"
print " ./jbripper.py [username] [password] [spotify_url]"
print "example : \n"
print " ./jbripper.py user pass spotify:track:52xaypL0Kjzk0ngwv3oBPR - for a single file"
print " ./jbripper.py user pass spotify:user:username:playlist:4vkGNcsS8lRXj4q945NIA4 - rips entire playlist"
The text was updated successfully, but these errors were encountered: