def add_file(self, file): if not self.check_file(file): return # You can add or drag playlist file directly too # Add playlist if file.endswith(LP_PLAYLIST_EXT): self.load(file) return log('Add File ' + file) name, ext = os.path.splitext(os.path.basename(file)) # Add cue files if ext.lower() in ['.flac', '.ape', '.ogg']: # Dont check cue file for mp3 cd = self.load_cue(file) if cd: self.add_cd(cd) return # Add rar file`s if ext.lower() in ['.rar']: p = compress.mount_compressed(file) if not p: return self.add_dir(p) # Add the uncompressed directory, it's so beautiful! return # Add plain files song = {} song['title'] = to_utf8(name) song['type'] = 'file' song['path'] = file song['artist'] = '' self.songlist.append(song)
def play(self, file, id): log('playing %s %s' % (file, id)) self.id = id # Start playing a new song if self.timer: gobject.source_remove(self.timer) # Remove old timer # Uncompressing if needed if compress.MARKER in file: if not compress.mount_compressed(compress.get_real_path(file)): return if not os.path.isfile(file): log(file + 'not exists, play next') self.play_next() return self.idle = False self.index = 0 # Offset for track file self.meta_pos = 0 song = self.proxy.playlist_view.songlist[id] title, artist = song['title'], song['artist'] # Deal with special chars in shell command, yes, it's ugly but very effective self.timer = gobject.timeout_add(1000, self.timer_callback, self) # Start a new one self.error = False if song['type'] == 'file': self.slave.send('loadfile %s\nvolume %d 1' % (escape_path(song['path']), self.volume)) if song['type'] == 'track': log('Play track %d' % song['track']) self.index = song['index'] # We need the function of playing from offset index, but mplayer doesn't provide it # 'pausing loadfile' doesn't work in idle slave mode self.slave.send('loadfile %s\nseek %d 2' % (escape_path(song['path']), self.index)) # Mplayer can't seek to the exact offset, so we sleep for a while if song['track'] != 0: time.sleep(1) self.slave.send('volume %d 1' % self.volume) self.timer_enable = True # Get info, meta data has been converted to utf8 already meta = self.slave.get_meta() if meta == None: log('Bad format ' + file) self.play_next() return # Adjust length if song['type'] == 'file': self.meta_total = meta['length'] l = self.get_length_by_mp3info(song['path']) if l: self.meta_total = l if song['type'] == 'track': if song['length'] == -1: # Final track self.meta_total = int(meta['length'] - self.index) else: self.meta_total = song['length'] self.meta_pos_view_update() if not title: title = os.path.splitext(os.path.basename(song['path']))[0] self.meta.set_label('%s %s' % (title, meta['bitrate'])) self.tooltips.set_tip(self.meta, '%s-%s' % (artist, meta['album'])) self.set_cb_state(self.cb_play, 'pause') # Scroll playlist self.proxy.playlist_view.treeview.set_cursor(id) # Show lyric log('ar: %s ti: %s' % (artist, title)) ar = normalize_name(artist) ti = normalize_name(title) log('I guess it\'s ar: %s ti: %s' % (ar, ti)) self.proxy.lyric_view.keywords_view.set_text(ar + ' ' + ti) self.proxy.lyric_view.curr_ar = ar self.proxy.lyric_view.curr_ti = ti self.proxy.lyric_view.download_links = None self.proxy.lyric_view.show_lyric()