Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions jbripper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
import threading
import time

## Options
dldir = "ripped/" # "": put mp3 directly into spotifyripper directory; "ripped/": put into "ripped" subdir
sort = True #True: sort mp3 into artist/album subdir; False: don't sort; put all mp3 into same directory

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 = False # also saves a .pcm file with the raw PCM data as delivered by libspotify ()

Expand All @@ -16,6 +20,7 @@
ripping = False
end_of_track = threading.Event()


def printstr(str): # print without newline
sys.stdout.write(str)
sys.stdout.flush()
Expand All @@ -24,11 +29,16 @@ def shell(cmdline): # execute shell commands (unicode support)
call(cmdline, shell=True)

def rip_init(session, track):
global pipe, ripping, pcmfile, rawpcm
global pipe, ripping, pcmfile, rawpcm, directory
num_track = "%02d" % (track.index(),)
mp3file = track.name()+".mp3"
pcmfile = track.name()+".pcm"
directory = os.getcwd() + "/" + track.artists()[0].name() + "/" + track.album().name() + "/"

if sort:
directory = os.getcwd() + "/" + dldir + track.artists()[0].name() + "/" + track.album().name() + "/"
else:
directory = os.getcwd() + "/" + dldir

if not os.path.exists(directory):
os.makedirs(directory)
printstr("ripping " + mp3file + " ...")
Expand Down Expand Up @@ -56,13 +66,13 @@ def rip(session, frames, frame_size, num_frames, sample_type, sample_rate, chann
pcmfile.write(frames)

def rip_id3(session, track): # write ID3 data
global directory
num_track = "%02d" % (track.index(),)
mp3file = 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())
Expand All @@ -80,7 +90,6 @@ def rip_id3(session, track): # write ID3 data
" -A \"" + album + "\"" + \
" -n " + str(num_track) + \
" -Y " + str(year) + \
" -Q " + \
" \"" + directory + mp3file + "\""
shell(cmd)

Expand Down