Changeset 1857
- Timestamp:
- 02/11/08 14:57:53 (2 months ago)
- svm:headrev:
cc3e1ea1-1e01-0410-8d68-8b121e83a9d5:11139- Files:
-
- 1 modified
-
freevo/src/audio/plugins/lastfm2.py (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
freevo/src/audio/plugins/lastfm2.py
r1855 r1857 67 67 def __init__(self, why): 68 68 Exception.__init__(self) 69 self.why = why 69 print 'DJW:why:', why, type(why), dir(why) 70 self.why = str(why) 70 71 71 72 def __str__(self): … … 106 107 plugin.MainMenuPlugin.__init__(self) 107 108 self.menuitem = None 108 if not os.path.isdir(config.LASTFM_DIR):109 os.makedirs(config.LASTFM_DIR, 0777)110 109 111 110 … … 224 223 225 224 226 @benchmark(benchmarking, True) #benchmarkcall)225 @benchmark(benchmarking, benchmarkcall) 227 226 def eventhandler(self, event, menuw=None): 228 227 _debug_('LastFMItem.eventhandler(event=%s, menuw=%r)' % (event, menuw), 2) 228 print 'LastFMItem.eventhandler(event=%r, arg=%r)' % (event.name, event.arg) 229 229 if event == 'STOP': 230 230 self.stop(self.arg, self.menuw) … … 264 264 if menuw: 265 265 AlertBox(text='No recs :(').show() 266 traceback.print_stack() 266 267 rc.post_event(PLAY_END) 267 268 return … … 271 272 if menuw: 272 273 AlertBox(text=_('Cannot get XSFP')).show() 274 traceback.print_stack() 273 275 rc.post_event(PLAY_END) 274 276 return … … 276 278 _debug_(why, DWARNING) 277 279 if menuw: 280 print 'DJW:why:', why, type(why), '%r' % str(why) 278 281 AlertBox(text=str(why)).show() 282 traceback.print_stack() 279 283 rc.post_event(PLAY_END) 284 return 280 285 281 286 entry = self.feed.entries[0] 282 self.stream_name = urllib.unquote_plus(self.feed.feed.title) 287 print 'DJW:entry:', entry.artist, '/', entry.album, '/', entry.title 288 self.stream_name = urllib.unquote_plus(self.feed.title) 283 289 self.album = entry.album 284 290 self.artist = entry.artist … … 286 292 self.location_url = entry.location_url 287 293 self.length = entry.duration 288 basename = entry.artist + '-' + entry.album + '-' + entry.title 289 self.basename = basename.lower().replace(' ', '_').replace('.', '').replace('\'', '').replace(':', '') 290 self.url = os.path.join(config.LASTFM_DIR, self.basename + os.path.splitext(entry.location_url)[1]) 291 self.trackpath = os.path.join(config.LASTFM_DIR, self.basename + os.path.splitext(entry.location_url)[1]) 292 self.image = os.path.join(config.LASTFM_DIR, self.basename + os.path.splitext(entry.image_url)[1]) 293 self.image_downloader = self.webservices.download(entry.image_url, self.image) 294 self.track_downloader = self.webservices.download(self.location_url, self.trackpath, istrack=True) 294 basename = os.path.join(config.LASTFM_DIR, self.stream_name, entry.artist, entry.album, entry.title).lower() 295 self.basename = basename.replace(' ', '_').replace('.', '').replace('\'', '').replace(':', '').replace(',', '') 296 if not os.path.exists(os.path.dirname(self.basename)): 297 _debug_('make directory %r' % (os.path.dirname(self.basename),), DINFO) 298 os.makedirs(os.path.dirname(self.basename), 0777) 299 # url is changed, to include file:// 300 self.url = os.path.join(self.basename + os.path.splitext(entry.location_url)[1]) 301 self.trackpath = os.path.join(self.basename + os.path.splitext(entry.location_url)[1]) 302 self.track_downloader = self.webservices.download(self.location_url, self.trackpath) 303 if entry.image_url: 304 self.image = os.path.join(self.basename + os.path.splitext(entry.image_url)[1]) 305 self.image_downloader = self.webservices.download(entry.image_url, self.image) 306 # Wait three seconds for the image to be downloaded 307 for i in range(30): 308 if not self.image_downloader.isrunning(): 309 break 310 time.sleep(0.1) 311 else: 312 self.image = None 295 313 #self.is_playlist = True 296 314 # Wait for a bit of the file to be downloaded 297 315 while self.track_downloader.filesize() < 1024 * 20: 298 316 if not self.track_downloader.isrunning(): 317 traceback.print_stack() 299 318 rc.post_event(PLAY_END) 300 319 return 301 time.sleep(0.1)302 # Wait for the image to be downloaded303 for i in range(30):304 if not self.image_downloader.isrunning():305 break306 320 time.sleep(0.1) 307 321 self.player = PlayerGUI(self, menuw) … … 315 329 if menuw: 316 330 AlertBox(text=error).show() 331 traceback.print_stack() 317 332 rc.post_event(PLAY_END) 318 333 … … 421 436 if len(reply) == 0: 422 437 self.running = False 438 print 'DJW:downloaded %s' % self.filename 423 439 _debug_('%s downloaded' % self.filename) 424 print 'DJW:downloaded %s' % self.filename425 440 # what we could do now is to add tags to track 426 441 break 427 442 self.size += len(reply) 428 443 else: 429 _debug_('%s aborted' % self.filename) 444 print 'DJW:aborted %s' % self.filename 445 os.remove(self.filename) 446 #_debug_('%s aborted' % self.filename) 430 447 fd.close() 431 448 f.close() 432 449 except ValueError, why: 433 _debug_('%s: %s' % (self. filename, why), DWARNING)450 _debug_('%s: %s' % (self.url, why), DWARNING) 434 451 except urllib2.HTTPError, why: 435 _debug_('%s: %s' % (self. filename, why), DWARNING)452 _debug_('%s: %s' % (self.url, why), DWARNING) 436 453 437 454 … … 532 549 f = opener.open(request) 533 550 reply = f.read() 551 except urllib2.HTTPError, why: 552 _debug_('%s: %s' % (url, why), DWARNING) 553 raise LastFMError(why) 534 554 except Exception, why: 535 555 _debug_('%s: %s' % (url, why), DWARNING) 536 raise 556 raise LastFMError(why) 537 557 _debug_('len(reply)=%r' % (len(reply),), 1) 538 558 return reply … … 577 597 if not self.session: 578 598 self._login() 579 #request_url = 'http://%s%s/xspf.php?sk=%s&discovery=0&desktop=%s' % \ 580 request_url = 'http://%s%s/xspf.php?sk=%s&discovery=1&desktop=%s' % \ 599 request_url = 'http://%s%s/xspf.php?sk=%s&discovery=0&desktop=%s' % \ 581 600 (self.base_url, self.base_path, self.session, LastFMWebServices._version) 582 601 return self._urlopen(request_url, lines=False) … … 618 637 619 638 @benchmark(benchmarking, benchmarkcall) 620 def download(self, url, filename , istrack=False):639 def download(self, url, filename): 621 640 """ 622 641 Download album cover or track to last.fm directory. … … 634 653 'User-agent': 'Freevo-%s (r%s)' % (version.__version__, revision.__revision__) 635 654 } 636 if istrack:637 headers.update({'Host': 'play.last.fm'})638 655 self.downloader = LastFMDownloader(url, filename, headers) 639 656 self.downloader.start() … … 717 734 @benchmark(benchmarking, benchmarkcall) 718 735 def __init__(self): 719 self.entries = []720 736 self.feed = feedparser.FeedParserDict() 737 self.feed.entries = [] 721 738 722 739 … … 755 772 trackauth = track_elem.find('{%s}trackauth' % LastFMXSPF._LASTFM_NS) 756 773 track.trackauth = trackauth is not None and trackauth.text or u'' 757 self. entries.append(track)758 return self 774 self.feed.entries.append(track) 775 return self.feed 759 776 760 777
