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

better unicode support #41

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
35 changes: 19 additions & 16 deletions jbripper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf8 -*-
# -*- coding: utf-8 -*-

from subprocess import call, Popen, PIPE
from spotify import Link, Image
Expand All @@ -26,9 +26,9 @@ def shell(cmdline): # execute shell commands (unicode support)
def rip_init(session, track):
global pipe, ripping, pcmfile, rawpcm
num_track = "%02d" % (track.index(),)
mp3file = track.name()+".mp3"
pcmfile = track.name()+".pcm"
directory = os.getcwd() + "/" + track.artists()[0].name() + "/" + track.album().name() + "/"
mp3file = track.name().encode("utf-8")+".mp3"
pcmfile = track.name().encode("utf-8")+".pcm"
directory = os.getcwd() + "/" + track.artists()[0].name().encode("utf-8") + "/" + track.album().name().encode("utf-8") + "/"
if not os.path.exists(directory):
os.makedirs(directory)
printstr("ripping " + mp3file + " ...")
Expand Down Expand Up @@ -57,12 +57,12 @@ def rip(session, frames, frame_size, num_frames, sample_type, sample_rate, chann

def rip_id3(session, track): # write ID3 data
num_track = "%02d" % (track.index(),)
mp3file = track.name()+".mp3"
artist = track.artists()[0].name()
album = track.album().name()
title = track.name()
mp3file = track.name().encode("utf-8")+".mp3"
artist = track.artists()[0].name().encode("utf-8")
album = track.album().name().encode("utf-8")
title = track.name().encode("utf-8")
year = track.album().year()
directory = os.getcwd() + "/" + track.artists()[0].name() + "/" + track.album().name() + "/"
directory = os.getcwd() + "/" + track.artists()[0].name().encode("utf-8") + "/" + track.album().name().encode("utf-8") + "/"

# download cover
image = session.image_create(track.album().cover())
Expand Down Expand Up @@ -113,18 +113,21 @@ def run(self):
# ripping loop
session = self.ripper.session
for track in itrack:
try:

self.ripper.load_track(track)
self.ripper.load_track(track)

rip_init(session, track)
rip_init(session, track)

self.ripper.play()
self.ripper.play()

end_of_track.wait()
end_of_track.clear() # TODO check if necessary
end_of_track.wait()
end_of_track.clear() # TODO check if necessary

rip_terminate(session, track)
rip_id3(session, track)
rip_terminate(session, track)
rip_id3(session, track)
except:
print('ERROR with a track')

self.ripper.disconnect()

Expand Down
10 changes: 5 additions & 5 deletions jukebox.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf8 -*-
# -*- coding: utf-8 -*-

import cmd
import logging
Expand Down Expand Up @@ -377,7 +377,7 @@ def load_track(self, track):
self.stop()
self.new_track_playing(track)
self.session.load(track)
print "Loaded track: %s" % track.name()
print "Loaded track: %s" % track.name().encode("utf-8")

def load(self, playlist, track):
if self.playing:
Expand All @@ -389,7 +389,7 @@ def load(self, playlist, track):
spot_track = pl[track]
self.new_track_playing(spot_track)
self.session.load(spot_track)
print "Loading %s from %s" % (spot_track.name(), pl.name())
print "Loading %s from %s" % (spot_track.name().encode("utf-8"), pl.name())

def load_playlist(self, playlist):
if self.playing:
Expand All @@ -412,7 +412,7 @@ def queue(self, playlist, track):
if self.playing:
self._queue.append((playlist, track))
else:
print 'Loading %s', track.name()
print 'Loading %s', track.name().encode("utf-8")
self.load(playlist, track)
self.play()

Expand Down Expand Up @@ -458,7 +458,7 @@ def browse(self, link, callback):
while not browser.is_loaded():
time.sleep(0.1)
for track in browser:
print track.name()
print track.name().encode("utf-8")
if link.type() == link.LINK_ARTIST:
browser = ArtistBrowser(link.as_artist())
while not browser.is_loaded():
Expand Down