Changeset 1858
- Timestamp:
- 02/11/08 18:36:05 (2 months ago)
- svm:headrev:
cc3e1ea1-1e01-0410-8d68-8b121e83a9d5:11140- Files:
-
- 1 modified
-
freevo/src/audio/plugins/lastfm2.py (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
freevo/src/audio/plugins/lastfm2.py
r1857 r1858 34 34 from threading import Thread 35 35 36 import kaa 37 from kaa import Timer, OneShotTimer 38 36 # Freevo modules 39 37 import config 40 38 import plugin … … 57 55 benchmarking = config.DEBUG_BENCHMARKING 58 56 benchmarkcall = config.DEBUG_BENCHMARKCALL 57 58 # Debugging modules 59 59 import pprint, traceback 60 60 61 61 62 … … 67 68 def __init__(self, why): 68 69 Exception.__init__(self) 69 print 'DJW:why:', why, type(why), dir(why)70 70 self.why = str(why) 71 71 … … 133 133 @benchmark(benchmarking, benchmarkcall) 134 134 def shutdown(self): 135 print 'PluginInterface.shutdown'136 135 if self.menuitem is not None: 137 136 self.menuitem.shutdown() … … 178 177 @benchmark(benchmarking, benchmarkcall) 179 178 def shutdown(self): 180 print 'LastFMMainMenuItem.shutdown'181 179 if self.webservices is not None: 182 180 self.webservices.shutdown() … … 202 200 self.xspf = None 203 201 self.feed = None 204 self.timer = None205 202 self.player = None 206 203 self.arg = None … … 230 227 self.stop(self.arg, self.menuw) 231 228 return 232 if event == 'PLAYLIST_NEXT': 229 if event == 'PLAY_END': 230 if self.feed is not None and len(self.feed.entries) > 0: 231 self.feed.entries.pop(0) 232 self.play() 233 return False 234 elif event == 'PLAYLIST_NEXT': 233 235 self.skip() 234 236 return True … … 252 254 self.menuw = menuw 253 255 254 if self.feed is not None:255 print 'DJW:len(self.feed.entries):', len(self.feed.entries)256 256 if self.feed is None or len(self.feed.entries) <= 0: 257 257 try: … … 278 278 _debug_(why, DWARNING) 279 279 if menuw: 280 print 'DJW:why:', why, type(why), '%r' % str(why)281 280 AlertBox(text=str(why)).show() 282 traceback.print_stack()283 281 rc.post_event(PLAY_END) 284 282 return 285 283 286 284 entry = self.feed.entries[0] 287 print 'DJW:entry:', entry.artist, '/', entry.album, '/', entry.title285 _debug_('entry "%s / %s / %s" of %s' % (entry.artist, entry.album, entry.title, len(self.feed.entries))) 288 286 self.stream_name = urllib.unquote_plus(self.feed.title) 289 287 self.album = entry.album … … 320 318 time.sleep(0.1) 321 319 self.player = PlayerGUI(self, menuw) 322 if self.timer is not None and self.timer.active():323 self.timer.stop()324 self.timer = kaa.OneShotTimer(self.timerhandler)325 self.timer.start(entry.duration)326 320 error = self.player.play() 327 321 if error: … … 334 328 335 329 @benchmark(benchmarking, benchmarkcall) 336 def timerhandler(self):337 """338 Handle the timer event when at the end of a track339 """340 if self.timer is None:341 _debug_('timer is not running', DINFO)342 return343 if self.track_downloader is None:344 _debug_('downloader is not running', DERROR)345 return346 if self.track_downloader.isrunning():347 _debug_('still playing', DINFO)348 self.timer.start(LastFMItem.poll_interval)349 else:350 self.feed.entries.pop(0)351 self.play(self.arg, self.menuw)352 353 354 @benchmark(benchmarking, benchmarkcall)355 330 def stop(self, arg=None, menuw=None): 356 331 """ … … 358 333 """ 359 334 _debug_('LastFMItem.stop(arg=%r, menuw=%r)' % (arg, menuw), 1) 360 if self.timer is not None and self.timer.active():361 self.timer.stop()362 self.timer = None363 335 364 336 … … 368 340 _debug_('skip()', 1) 369 341 self.feed.entries.pop(0) 370 if self.timer is not None and self.timer.active():371 self.timer.stop()372 self.timer = None373 342 self.play(self.arg, self.menuw) 374 343 … … 412 381 download it to a file and then play it 413 382 """ 383 @benchmark(benchmarking, benchmarkcall) 414 384 def __init__(self, url, filename, headers=None): 415 385 Thread.__init__(self) … … 421 391 422 392 393 @benchmark(benchmarking, benchmarkcall) 423 394 def run(self): 424 395 """ … … 436 407 if len(reply) == 0: 437 408 self.running = False 438 print 'DJW:downloaded %s' % self.filename 439 _debug_('%s downloaded' % self.filename) 409 print '%s downloaded' % self.filename 410 # debugs fail during shutdown 411 #_debug_('%s downloaded' % self.filename) 440 412 # what we could do now is to add tags to track 441 413 break 442 414 self.size += len(reply) 443 415 else: 444 print 'DJW:aborted %s' % self.filename 416 print '%s download aborted' % self.filename 417 #_debug_('%s download aborted' % self.filename) 445 418 os.remove(self.filename) 446 #_debug_('%s aborted' % self.filename)447 419 fd.close() 448 420 f.close() … … 453 425 454 426 427 @benchmark(benchmarking, benchmarkcall) 428 def filesize(self): 429 """ 430 Get the downloaded file size 431 """ 432 return self.size 433 434 435 @benchmark(benchmarking, benchmarkcall) 455 436 def stop(self): 456 437 """ … … 461 442 462 443 463 def filesize(self): 464 """ 465 Get the downloaded file size 466 """ 467 return self.size 468 469 444 @benchmark(benchmarking, benchmarkcall) 470 445 def isrunning(self): 471 446 """ … … 505 480 Shutdown the lasf.fm webservices 506 481 """ 507 print 'LastFMWebServices.shutdown'508 482 if self.downloader is not None: 509 483 self.downloader.stop() … … 511 485 512 486 @benchmark(benchmarking, benchmarkcall) 513 def _urlopen(self, url, data=None,lines=True):487 def _urlopen(self, url, lines=True): 514 488 """ 515 489 Wrapper to see what is sent and received … … 522 496 @returns: reply from request 523 497 """ 524 _debug_('url=%r, data=%r' % (url, data), 1)498 _debug_('url=%r, lines=%r' % (url, lines), 1) 525 499 request = urllib2.Request(url, headers=LastFMWebServices.headers) 526 500 opener = urllib2.build_opener(SmartRedirectHandler()) 527 if lines:528 reply = []529 try:501 try: 502 if lines: 503 reply = [] 530 504 f = opener.open(request) 531 505 lines = f.readlines() … … 534 508 for line in lines: 535 509 reply.append(line.strip('\n')) 536 except httplib.BadStatusLine, why: 537 print 'BadStatusLine:', why 538 reply = None 539 except AttributeError, why: 540 reply = None 541 except Exception, why: 542 _debug_('%s: %s' % (url, why), DWARNING) 543 raise 544 _debug_('reply=%r' % (reply,), 1) 545 return reply 546 else: 547 reply = '' 548 try: 510 _debug_('reply=%r' % (reply,), 1) 511 else: 512 reply = '' 549 513 f = opener.open(request) 550 514 reply = f.read() 551 except urllib2.HTTPError, why: 552 _debug_('%s: %s' % (url, why), DWARNING) 553 raise LastFMError(why) 554 except Exception, why: 555 _debug_('%s: %s' % (url, why), DWARNING) 556 raise LastFMError(why) 557 _debug_('len(reply)=%r' % (len(reply),), 1) 515 _debug_('len(reply)=%r' % (len(reply),), 1) 558 516 return reply 517 except urllib2.HTTPError, why: 518 _debug_('%s: %s' % (url, why)) 519 raise LastFMError(why) 520 except Exception, why: 521 _debug_('%s: %s' % (url, why)) 522 raise LastFMError(why) 559 523 560 524
