Changeset 1903

Show
Ignore:
Timestamp:
20/11/08 19:50:01 (7 weeks ago)
Author:
duncan
svm:headrev:

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

Some small fixes

Location:
freevo/src/audio/plugins
Files:
2 modified

Legend:

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

    r1902 r1903  
    233233        elif event == 'PLAY_END': 
    234234            if self.feed is not None and len(self.feed.entries) > 0: 
    235                 self.feed.entries.pop(0) 
     235                entry = self.feed.entries.pop(0) 
     236                if entry: 
     237                    time.sleep(3) 
     238                    from kaa.metadata.audio import eyeD3 
     239                    try: 
     240                        tag = eyeD3.Tag() 
     241                        tag.link(entry.trackpath) 
     242                        tag.header.setVersion(eyeD3.ID3_V2_3) 
     243                        tag.setArtist(entry.artist) 
     244                        tag.setAlbum(entry.album) 
     245                        tag.setTitle(entry.title) 
     246                        #tag.setGenre(entry.genre) 
     247                        if entry.image: 
     248                            tag.addImage(eyeD3.ImageFrame.FRONT_COVER, entry.image) 
     249                        tag.update() 
     250                    except Exception, why: 
     251                        print why 
    236252            self.play() 
    237253            return False 
     
    280296            self.location_url = entry.location_url 
    281297            self.length = entry.duration 
    282             basename = os.path.join(config.LASTFM_DIR, self.stream_name, entry.artist, entry.album, entry.title) 
     298            basename = os.path.join(config.LASTFM_DIR, entry.artist, entry.album, entry.title) 
    283299            self.basename = basename.lower().replace(' ', '_').\ 
    284300                replace('.', '').replace('\'', '').replace(':', '').replace(',', '') 
     
    288304            # url is changed, to include file:// 
    289305            self.url = os.path.join(self.basename + os.path.splitext(entry.location_url)[1]) 
    290             self.trackpath = os.path.join(self.basename + os.path.splitext(entry.location_url)[1]) 
     306            entry.trackpath = os.path.join(self.basename + os.path.splitext(entry.location_url)[1]) 
    291307            if entry.image_url: 
    292308                self.image = os.path.join(self.basename + os.path.splitext(entry.image_url)[1]) 
     
    299315            else: 
    300316                self.image = None 
    301             self.track_downloader = self.webservices.download(self.location_url, self.trackpath, self) 
     317            entry.image = self.image 
     318            track_downloader = self.webservices.download(self.location_url, entry.trackpath, self) 
    302319            # Wait for a bit of the file to be downloaded 
    303             while self.track_downloader.filesize() < 1024 * 20: 
    304                 if not self.track_downloader.isrunning(): 
     320            while track_downloader.filesize() < 1024 * 20: 
     321                if not track_downloader.isrunning(): 
    305322                    raise LastFMError('Failed to download track', entry.location_url) 
    306323                time.sleep(0.1) 
    307324            if not self.player: 
    308                 self.player = PlayerGUI(self, menuw) 
     325                self.player = PlayerGUI(self, self.menuw) 
    309326            error = self.player.play() 
    310327            if error: 
     
    312329 
    313330        except LastFMError, why: 
    314             traceback.print_exc() 
    315331            _debug_('play error: %s' % (why,), DWARNING) 
    316             if menuw: 
     332            if self.menuw: 
    317333                AlertBox(text=str(why)).show() 
    318334            rc.post_event(STOP) 
     
    473489            return reply 
    474490        except urllib2.HTTPError, why: 
    475             _debug_('%s: %s' % (url, why), DWARNING) 
    476491            raise LastFMError(why, url) 
    477492        except Exception, why: 
     
    690705                    #_debug_('%s downloaded' % self.filename) 
    691706                    # XXX this may upset mplayer, stopping playback before the end of the track 
    692                     if self.entry: 
    693                         time.sleep(3) 
    694                         from kaa.metadata.audio import eyeD3 
    695                         try: 
    696                             tag = eyeD3.Tag() 
    697                             tag.link(self.filename) 
    698                             tag.header.setVersion(eyeD3.ID3_V2_3) 
    699                             tag.setArtist(self.entry.artist) 
    700                             tag.setAlbum(self.entry.album) 
    701                             tag.setTitle(self.entry.title) 
    702                             #tag.setGenre(self.entry.genre) 
    703                             tag.addImage(eyeD3.ImageFrame.FRONT_COVER, self.entry.image) 
    704                             tag.update() 
    705                         except Exception, why: 
    706                             print why 
    707707                    break 
    708708                self.size += len(reply) 
  • freevo/src/audio/plugins/mplayervis1.py

    r1796 r1903  
    3535__author__ = 'Viggo Fredriksen <viggo@katatonic.org>' 
    3636 
     37import os, time 
    3738try: 
    3839    import pygoom 
     
    4142                    'or remove this plugin (http://freevo.sf.net/pygoom).') 
    4243 
    43  
    4444# pygame  modules 
    4545from pygame import Rect, image, transform, Surface 
    4646 
     47# kaa modules 
     48from kaa import Timer 
     49 
    4750# freevo modules 
    48 import plugin, config, rc, skin, osd, time 
     51import plugin, config, rc, skin, osd 
    4952 
    5053from event import * 
    5154from animation import render, BaseAnimation 
    52 from kaa import Timer 
     55 
     56from util.benchmark import benchmark 
     57benchmarking = config.DEBUG_BENCHMARKING 
     58benchmarkcall = config.DEBUG_BENCHMARKCALL 
     59 
     60if config.DEBUG_DEBUGGER: 
     61    import pdb, pprint, traceback 
    5362 
    5463mmap_file = '/tmp/mpav' 
     
    6473    coversurf  = None 
    6574 
     75    @benchmark(benchmarking, benchmarkcall) 
    6676    def __init__(self, x, y, width, height, coverfile=None): 
    67         """ Initialise the MPlayer Visualization Goom """ 
     77        """ 
     78        Initialise the MPlayer Visualization Goom 
     79        """ 
    6880        _debug_('MpvGoom.__init__(x=%r y=%r width=%r height=%r coverfile=%r)' % (x, y, width, height, coverfile), 1) 
    6981        self.mode = config.MPLAYERVIS_MODE 
    7082        self.coverfile = coverfile 
     83 
     84        if not os.path.exists(mmap_file): 
     85            f = open(mmap_file, 'w') 
     86            s = str(chr(0)) * 2064 
     87            f.write(s) 
     88            f.close() 
    7189 
    7290        BaseAnimation.__init__(self, (x, y, width, height), fps=100, bg_update=False, bg_redraw=False) 
     
    96114        self.alpha = self.set_alpha(self.counter, 0) 
    97115 
    98         self.running = True 
     116        self.running = False 
    99117        Timer(self.timerhandler).start(0.1) 
    100118        self.last_time = 0 
    101119 
    102120 
     121    @benchmark(benchmarking, benchmarkcall) 
    103122    def set_cover(self, coverfile): 
    104123        """ 
     
    110129 
    111130 
     131    @benchmark(benchmarking, benchmarkcall) 
    112132    def set_visual(self, visual): 
    113133        """ pass the visualisation effect to pygoom """ 
     
    116136 
    117137 
     138    @benchmark(benchmarking, benchmarkcall) 
    118139    def set_title(self, title): 
    119140        """ pass the song title to pygoom """ 
     
    122143 
    123144 
     145    @benchmark(benchmarking, benchmarkcall) 
    124146    def set_message(self, message): 
    125147        """ pass the song message to pygoom """ 
     
    128150 
    129151 
     152    #@benchmark(benchmarking, benchmarkcall) 
    130153    def set_alpha(self, high, low): 
    131154        """ Get the alpha level for a count """ 
     
    137160 
    138161 
     162    @benchmark(benchmarking, benchmarkcall) 
    139163    def set_resolution(self, x, y, width, height, cinemascope=0, clear=False): 
    140164        """ Set the resolution of the pygoom window """ 
     
    180204 
    181205 
     206    @benchmark(benchmarking, benchmarkcall) 
    182207    def set_fullscreen(self): 
    183208        """ Set the mode to full screen """ 
     
    207232 
    208233 
     234    @benchmark(benchmarking, benchmarkcall) 
    209235    def set_info(self, info, timeout=5): 
    210236        """ 
     
    231257 
    232258 
     259    #@benchmark(benchmarking, benchmarkcall) 
    233260    def init_state(self): 
    234261        if self.counter > 0: 
     
    243270 
    244271 
     272    #@benchmark(benchmarking, benchmarkcall) 
    245273    def fade_in_wait_state(self): 
    246274        if self.counter > 0: 
     
    253281 
    254282 
     283    #@benchmark(benchmarking, benchmarkcall) 
    255284    def fade_in_state(self): 
    256285        if self.counter > 0: 
     
    264293 
    265294 
     295    #@benchmark(benchmarking, benchmarkcall) 
    266296    def fade_out_wait_state(self): 
    267297        if self.counter > 0: 
     
    274304 
    275305 
     306    #@benchmark(benchmarking, benchmarkcall) 
    276307    def fade_out_state(self): 
    277308        if self.counter > 0: 
     
    285316 
    286317 
     318    #@benchmark(benchmarking, benchmarkcall) 
    287319    def timerhandler(self): 
    288320        """ 
     
    293325        # draw the cover 
    294326        if not self.running: 
    295             return self.running 
     327            return False 
     328 
    296329        gooms = pygoom.get_surface() 
    297330        if self.coversurf: 
     
    304337                gooms.blit(s, (x, y)) 
    305338 
     339        #if not self.running: 
     340        #    return False 
     341 
    306342        # draw the info 
    307         if not self.running: 
    308             return self.running 
    309343        if self.info: 
    310344            s, x, y, w, h = self.info 
     
    334368            self.lastmode = self.mode 
    335369 
    336         return self.running 
    337  
    338  
     370        return True 
     371 
     372 
     373    #@benchmark(benchmarking, benchmarkcall) 
    339374    def poll(self, current_time): 
    340375        """ 
     
    389424    detached = False 
    390425 
     426    @benchmark(benchmarking, benchmarkcall) 
    391427    def __init__(self): 
    392428        """ Initialist the PluginInterface """ 
     
    422458        self.view = config.MPLAYERVIS_MODE 
    423459        self.view_func = [self.dock, self.fullscreen, self.noview] 
    424  
    425  
     460        self.initialised = False 
     461 
     462 
     463    @benchmark(benchmarking, benchmarkcall) 
    426464    def config(self): 
    427         """ """ 
     465        """ 
     466        """ 
    428467        return [ 
    429468            ('MPLAYERVIS_MODE', 0, 'Set the initial mode of the display, 0)DOCK, 1)FULL or 2)NOVI'), 
     
    437476            ('MPLAYERVIS_FULL_GEOMETRY', '%dx%d' % (config.CONF.width, config.CONF.height), 'Full screen geometry'), 
    438477            ('MPLAYERVIS_FAST_FULLSCREEN', True, 'Fullscreen surface is doubled'), 
    439             ('MPLAYERVIS_FPS', 25, 'Max FPS of visualization') 
     478            ('MPLAYERVIS_FPS', 25, 'Max FPS of visualization'), 
     479            ('MPLAYERVIS_HAS_TRACK', False, 'Set to True if mplayer has -af track patch'), 
    440480        ] 
    441481 
    442482 
    443     def play(self, command, player): 
    444         """ 
    445         Play it 
    446         """ 
    447         _debug_('play(command, player)', 1) 
    448         self.player = player 
    449         self.item   = player.playerGUI.item 
    450  
    451         return command + [ "-af", "export=" + mmap_file ] 
    452  
    453  
     483    @benchmark(benchmarking, benchmarkcall) 
    454484    def toggle_view(self): 
    455485        """ 
     
    467497 
    468498 
     499    @benchmark(benchmarking, benchmarkcall) 
    469500    def eventhandler(self, event=None, arg=None): 
    470501        """ 
     
    479510            PluginInterface.detached = False 
    480511            self.start_visual() 
     512        elif event == PLAY_START: 
     513            self.start_visual() 
     514        elif event == PLAY_END: 
     515            self.pause_visual() 
    481516        elif event == STOP: 
    482517            PluginInterface.detached = False 
     518            self.stop_visual() 
    483519 
    484520        if event == 'CHANGE_MODE': 
     
    519555                self.visual.set_info(event.arg) 
    520556                return True 
    521  
    522557            if self.passed_event: 
    523558                self.passed_event = False 
    524559                return False 
    525  
    526560            self.passed_event = True 
    527561 
     
    532566 
    533567 
     568    @benchmark(benchmarking, benchmarkcall) 
    534569    def item_info(self, fmt=None): 
    535570        """ 
    536         Returns info about the current running song 
     571        Returns info about the current playing song 
    537572        """ 
    538573        _debug_('item_info(fmt=%r)' % (fmt,), 1) 
     
    573608 
    574609 
     610    @benchmark(benchmarking, benchmarkcall) 
    575611    def dock(self): 
    576612        _debug_('dock()', 1) 
     
    603639 
    604640 
     641    @benchmark(benchmarking, benchmarkcall) 
    605642    def fullscreen(self): 
    606643        _debug_('fullscreen()', 1) 
     
    616653 
    617654 
     655    @benchmark(benchmarking, benchmarkcall) 
    618656    def noview(self): 
    619657        _debug_('noview()', 1) 
     
    631669 
    632670 
     671    @benchmark(benchmarking, benchmarkcall) 
    633672    def start_visual(self): 
    634673        _debug_('start_visual()', 1) 
    635         if self.visual or self.view == NOVI: 
     674        if self.view == NOVI: 
    636675            return 
    637676 
     677        if self.visual: 
     678            if self.visual.running: 
     679                return 
     680 
    638681        if rc.app() == self.player.eventhandler: 
    639  
     682            #if self.visual is None: 
     683            #    self.visual = MpvGoom(300, 300, 150, 150, self.item.image) 
    640684            self.visual = MpvGoom(300, 300, 150, 150, self.item.image) 
    641685 
     
    644688 
    645689            self.view_func[self.view]() 
     690            self.visual.running = True 
    646691            self.visual.start() 
    647692 
    648693 
     694    @benchmark(benchmarking, benchmarkcall) 
     695    def pause_visual(self): 
     696        _debug_('pause_visual()', 1) 
     697        if self.visual: 
     698            self.visual.running = False 
     699 
     700 
     701    @benchmark(benchmarking, benchmarkcall) 
    649702    def stop_visual(self): 
    650703        _debug_('stop_visual()', 1) 
     
    657710 
    658711 
     712    @benchmark(benchmarking, benchmarkcall) 
     713    def play(self, command, player): 
     714        """ 
     715        Play the track 
     716        @param command: mplayer command 
     717        @param player: the player object 
     718        """ 
     719        _debug_('play(command=%r, player=%r)' % (command, player), 1) 
     720        self.player = player 
     721        self.item   = player.playerGUI.item 
     722 
     723        if config.MPLAYERVIS_HAS_TRACK: 
     724            return command + [ '-af', 'export=%s' % mmap_file + ',track=5:1500' ] 
     725        return command + [ '-af', 'export=%s' % mmap_file ] 
     726 
     727 
     728    @benchmark(benchmarking, benchmarkcall) 
    659729    def stop(self): 
    660730        _debug_('stop()', 1) 
    661         self.stop_visual() 
    662  
    663  
     731        if self.visual: 
     732            self.visual.running = False 
     733 
     734 
     735    #@benchmark(benchmarking, benchmarkcall) 
    664736    def stdout(self, line): 
    665737        """ 
     
    670742        """ 
    671743        #_debug_('stdout(line=%r)' % (line), 1) 
    672         if self.visual: 
    673             return 
     744        memory_mapped = False 
     745        if line.find('[export] Memory mapped to file: ' + mmap_file) == 0: 
     746            memory_mapped = True 
     747            _debug_("Detected MPlayer 'export' audio filter! Using MPAV.") 
    674748 
    675749        if PluginInterface.detached: 
    676750            return 
    677751 
    678         if line.find("[export] Memory mapped to file: " + mmap_file) == 0: 
    679             _debug_("Detected MPlayer 'export' audio filter! Using MPAV.") 
     752        if memory_mapped: 
    680753            self.start_visual() 
     754            if self.visual: 
     755                self.visual.running = True