Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update jbripper.py #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
54 changes: 35 additions & 19 deletions jbripper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
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)

output_folder = os.getcwd() + "/download/" # change if you want to change output folder
pipe = None
ripping = False
skipping = False
end_of_track = threading.Event()

def printstr(str): # print without newline
Expand All @@ -22,37 +23,49 @@ def shell(cmdline): # execute shell commands (unicode support)
call(cmdline, shell=True)

def rip_init(session, track):
global pipe, ripping
global pipe, ripping, skipping, output_folder
num_track = "%02d" % (track.index(),)
mp3file = track.name()+".mp3"
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 -V2 -h -r - \""+ directory + mp3file+"\"", stdin=PIPE, shell=True)
pipe = p.stdin
ripping = True
directory = output_folder + track.artists()[0].name() + "/" + track.album().name() + "/"
if not os.path.isfile(directory+mp3file):
if not os.path.exists(directory):
os.makedirs(directory)
printstr("ripping " + mp3file + " ...")
p = Popen("lame --silent -V2 -h -r - \""+ directory + mp3file+"\"", stdin=PIPE, shell=True)
pipe = p.stdin
ripping = True
f = open("ripping.status",'w')
f.write(num_track+"|"+track.artists()[0].name()+"|"+track.album().name()+"|"+directory+mp3file)
f.close()
else:
printstr("skipping " + mp3file + " (already exists)")
skipping = True


def rip_terminate(session, track):
global ripping
if pipe is not None:
print(' done!')
pipe.close()
ripping = False
ripping = False
f = open("ripping.status",'w')
f.write("")
f.close()

def rip(session, frames, frame_size, num_frames, sample_type, sample_rate, channels):
if ripping:
printstr('.')
pipe.write(frames);

def rip_id3(session, track): # write ID3 data
global output_folder
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() + "/"
directory = output_folder + track.artists()[0].name() + "/" + track.album().name() + "/"

# download cover
image = session.image_create(track.album().cover())
Expand Down Expand Up @@ -83,6 +96,7 @@ def __init__(self, ripper):
self.ripper = ripper

def run(self):
global skipping
# wait for container
container_loaded.wait()
container_loaded.clear()
Expand All @@ -103,18 +117,20 @@ def run(self):
# 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)
if not skipping:
self.ripper.play()
end_of_track.wait()
end_of_track.clear() # TODO check if necessary
rip_terminate(session, track)
rip_id3(session, track)
else:
rip_terminate(session, track)
skipping = False
print('\n\n')

self.ripper.disconnect()

Expand Down