Changeset 1858

Show
Ignore:
Timestamp:
02/11/08 18:36:05 (2 months ago)
Author:
duncan
svm:headrev:

cc3e1ea1-1e01-0410-8d68-8b121e83a9d5:11140
Message:

Removed timer functions as these are not needed, because the files have been downloaded
The timer functions were not 100% accurate.
Cleaned up most print messages

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • freevo/src/audio/plugins/lastfm2.py

    r1857 r1858  
    3434from threading import Thread 
    3535 
    36 import kaa 
    37 from kaa import Timer, OneShotTimer 
    38  
     36# Freevo modules 
    3937import config 
    4038import plugin 
     
    5755benchmarking = config.DEBUG_BENCHMARKING 
    5856benchmarkcall = config.DEBUG_BENCHMARKCALL 
     57 
     58# Debugging modules 
    5959import pprint, traceback 
     60 
    6061 
    6162 
     
    6768    def __init__(self, why): 
    6869        Exception.__init__(self) 
    69         print 'DJW:why:', why, type(why), dir(why) 
    7070        self.why = str(why) 
    7171 
     
    133133    @benchmark(benchmarking, benchmarkcall) 
    134134    def shutdown(self): 
    135         print 'PluginInterface.shutdown' 
    136135        if self.menuitem is not None: 
    137136            self.menuitem.shutdown() 
     
    178177    @benchmark(benchmarking, benchmarkcall) 
    179178    def shutdown(self): 
    180         print 'LastFMMainMenuItem.shutdown' 
    181179        if self.webservices is not None: 
    182180            self.webservices.shutdown() 
     
    202200        self.xspf = None 
    203201        self.feed = None 
    204         self.timer = None 
    205202        self.player = None 
    206203        self.arg = None 
     
    230227            self.stop(self.arg, self.menuw) 
    231228            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': 
    233235            self.skip() 
    234236            return True 
     
    252254            self.menuw = menuw 
    253255 
    254         if self.feed is not None: 
    255             print 'DJW:len(self.feed.entries):', len(self.feed.entries) 
    256256        if self.feed is None or len(self.feed.entries) <= 0: 
    257257            try: 
     
    278278                _debug_(why, DWARNING) 
    279279                if menuw: 
    280                     print 'DJW:why:', why, type(why), '%r' % str(why) 
    281280                    AlertBox(text=str(why)).show() 
    282                 traceback.print_stack() 
    283281                rc.post_event(PLAY_END) 
    284282                return 
    285283 
    286284        entry = self.feed.entries[0] 
    287         print 'DJW:entry:', entry.artist, '/', entry.album, '/', entry.title 
     285        _debug_('entry "%s / %s / %s" of %s' % (entry.artist, entry.album, entry.title, len(self.feed.entries))) 
    288286        self.stream_name = urllib.unquote_plus(self.feed.title) 
    289287        self.album = entry.album 
     
    320318            time.sleep(0.1) 
    321319        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) 
    326320        error = self.player.play() 
    327321        if error: 
     
    334328 
    335329    @benchmark(benchmarking, benchmarkcall) 
    336     def timerhandler(self): 
    337         """ 
    338         Handle the timer event when at the end of a track 
    339         """ 
    340         if self.timer is None: 
    341             _debug_('timer is not running', DINFO) 
    342             return 
    343         if self.track_downloader is None: 
    344             _debug_('downloader is not running', DERROR) 
    345             return 
    346         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) 
    355330    def stop(self, arg=None, menuw=None): 
    356331        """ 
     
    358333        """ 
    359334        _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 = None 
    363335 
    364336 
     
    368340        _debug_('skip()', 1) 
    369341        self.feed.entries.pop(0) 
    370         if self.timer is not None and self.timer.active(): 
    371             self.timer.stop() 
    372         self.timer = None 
    373342        self.play(self.arg, self.menuw) 
    374343 
     
    412381    download it to a file and then play it 
    413382    """ 
     383    @benchmark(benchmarking, benchmarkcall) 
    414384    def __init__(self, url, filename, headers=None): 
    415385        Thread.__init__(self) 
     
    421391 
    422392 
     393    @benchmark(benchmarking, benchmarkcall) 
    423394    def run(self): 
    424395        """ 
     
    436407                if len(reply) == 0: 
    437408                    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) 
    440412                    # what we could do now is to add tags to track 
    441413                    break 
    442414                self.size += len(reply) 
    443415            else: 
    444                 print 'DJW:aborted %s' % self.filename 
     416                print '%s download aborted' % self.filename 
     417                #_debug_('%s download aborted' % self.filename) 
    445418                os.remove(self.filename) 
    446                 #_debug_('%s aborted' % self.filename) 
    447419            fd.close() 
    448420            f.close() 
     
    453425 
    454426 
     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) 
    455436    def stop(self): 
    456437        """ 
     
    461442 
    462443 
    463     def filesize(self): 
    464         """ 
    465         Get the downloaded file size 
    466         """ 
    467         return self.size 
    468  
    469  
     444    @benchmark(benchmarking, benchmarkcall) 
    470445    def isrunning(self): 
    471446        """ 
     
    505480        Shutdown the lasf.fm webservices 
    506481        """ 
    507         print 'LastFMWebServices.shutdown' 
    508482        if self.downloader is not None: 
    509483            self.downloader.stop() 
     
    511485 
    512486    @benchmark(benchmarking, benchmarkcall) 
    513     def _urlopen(self, url, data=None, lines=True): 
     487    def _urlopen(self, url, lines=True): 
    514488        """ 
    515489        Wrapper to see what is sent and received 
     
    522496        @returns: reply from request 
    523497        """ 
    524         _debug_('url=%r, data=%r' % (url, data), 1) 
     498        _debug_('url=%r, lines=%r' % (url, lines), 1) 
    525499        request = urllib2.Request(url, headers=LastFMWebServices.headers) 
    526500        opener = urllib2.build_opener(SmartRedirectHandler()) 
    527         if lines: 
    528             reply = [] 
    529             try: 
     501        try: 
     502            if lines: 
     503                reply = [] 
    530504                f = opener.open(request) 
    531505                lines = f.readlines() 
     
    534508                for line in lines: 
    535509                    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 = '' 
    549513                f = opener.open(request) 
    550514                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) 
    558516            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) 
    559523 
    560524