Exemple #1
0
 def filechooser_callback(self, action, value, mode):
     value = value.encode('utf-8')
     if action == "open":
         if os.path.isdir(os.path.expanduser(value)):
             self.config.set("options", "default_folder", value)
             self.view.rootObject().property("root").openFilechooser(self.get_filechooser_items(value, mode), value.decode('utf-8'), False, mode)
     elif action == "up":
         value = value.rsplit("/", 1)[0]
         self.config.set("options", "default_folder", value)
         self.view.rootObject().property("root").openFilechooser(self.get_filechooser_items(value, mode), value.decode('utf-8'), False, mode)
     elif action == "add":
         if os.path.exists(os.path.expanduser(value)):
             self.playlist.load(os.path.abspath(os.path.expanduser(value)))
             self.view.rootObject().property("root").openPlaylist(False, self.get_playlist_items())
     elif action == "save":
         ext = util.detect_filetype(os.path.expanduser(value))
         if not self.playlist.save_to_new_playlist(os.path.expanduser(value), ext):
             # FIX ME!
             #self.notify(_('Error saving playlist...'))
             print _('Error saving playlist...')
     elif action == "play_one":
         if os.path.exists(os.path.expanduser(value)):
             self.clear_playlist_callback()
             self.playlist.load(os.path.abspath(os.path.expanduser(value)))
     elif action == "image":
         if os.path.isfile(os.path.expanduser(value)) and util.detect_filetype(value) in panucci.IMAGES:
             self.view.rootObject().property("root").setCoverPath(os.path.expanduser(value))
Exemple #2
0
    def save_to_playlist_callback(self, widget=None):
        filename = gtkutil.get_file_from_filechooser(self,
                                                     save_file=True,
                                                     save_to='playlist.m3u')

        if filename is None:
            return False

        if os.path.isfile(filename):
            response = gtkutil.dialog(
                self.main_window,
                _('File already exists'),
                _('File already exists'),
                _('The file %s already exists. You can choose another name or '
                  'overwrite the existing file.') % os.path.basename(filename),
                affirmative_button=gtk.STOCK_SAVE,
                negative_button=_('Rename file'))

            if response is None:
                return None

            elif response:
                pass
            elif not response:
                return self.save_to_playlist_callback()

        ext = util.detect_filetype(filename)
        if not self.playlist.save_to_new_playlist(filename, ext):
            self.notify(_('Error saving playlist...'))
            return False

        return True
Exemple #3
0
    def extract_metadata(self):
        self.__log.debug('Extracting metadata for %s', self.__filepath)

        if self._ask_gpodder_for_metadata():
            if self.coverart is None:
                self.coverart = self.__find_coverart()
            return

        filetype = util.detect_filetype(self.__filepath)

        if filetype == 'mp3':
            import mutagen.mp3 as meta_parser
        elif filetype == 'ogg':
            import mutagen.oggvorbis as meta_parser
        elif filetype == 'flac':
            import mutagen.flac as meta_parser
        elif filetype in ['mp4', 'm4a']:
            import mutagen.mp4 as meta_parser
        else:
            self.__log.info(
                'Extracting metadata not supported for %s files.', filetype )
            return False

        try:
            metadata = meta_parser.Open(self.__filepath)
            self.__metadata_extracted = True
        except Exception, e:
            self.title = util.pretty_filename(self.__filepath)
            self.__log.exception('Error running metadata parser...')
            self.__metadata_extracted = False
            return False
Exemple #4
0
    def save_to_playlist_callback(self, widget=None):
        filename = gtkutil.get_file_from_filechooser(
            self, save_file=True, save_to='playlist.m3u' )

        if filename is None:
            return False

        if os.path.isfile(filename):
            response = gtkutil.dialog( self.main_window, _('File already exists'),
                _('File already exists'),
                _('The file %s already exists. You can choose another name or '
                  'overwrite the existing file.') % os.path.basename(filename),
                affirmative_button=gtk.STOCK_SAVE,
                negative_button=_('Rename file'))

            if response is None:
                return None

            elif response:
                pass
            elif not response:
                return self.save_to_playlist_callback()

        ext = util.detect_filetype(filename)
        if not self.playlist.save_to_new_playlist(filename, ext):
            self.notify(_('Error saving playlist...'))
            return False

        return True
Exemple #5
0
    def save_playlist_callback(self):
        filenames = qtutil.get_file_from_filechooser(self,
                                                     save_file=True,
                                                     save_to=True)
        if not filenames:
            return False

        filename = filenames[0]
        if os.path.isfile(filename):
            response = qtutil.dialog(
                self.main_window, _('File already exists!'),
                _('The file %s already exists. You can choose another name or '
                  'overwrite the existing file.') % os.path.basename(filename),
                False, True, True, True)

            if response == QtGui.QMessageBox.Cancel:
                return None
            elif response == QtGui.QMessageBox.Discard:
                return self.save_playlist_callback()

        ext = util.detect_filetype(filename)
        if not self.playlist.save_to_new_playlist(filename, ext):
            self.notify(_('Error saving playlist...'))
            return False

        return True
Exemple #6
0
 def filechooser_callback(self, action, value):
     value = value.encode('utf-8')
     if action == "open":
         if os.path.isdir(os.path.expanduser(value)):
             self.config.set("options", "default_folder", value)
             self.view.rootObject().property("root").openFilechooser(
                 self.get_filechooser_items(value), value.decode('utf-8'),
                 False)
     elif action == "up":
         value = value.rsplit("/", 1)[0]
         self.config.set("options", "default_folder", value)
         self.view.rootObject().property("root").openFilechooser(
             self.get_filechooser_items(value), value.decode('utf-8'),
             False)
     elif action == "add":
         if os.path.exists(os.path.expanduser(value)):
             self.playlist.load(os.path.abspath(os.path.expanduser(value)))
             self.view.rootObject().property("root").openPlaylist(
                 False, self.get_playlist_items())
     elif action == "save":
         ext = util.detect_filetype(os.path.expanduser(value))
         if not self.playlist.save_to_new_playlist(
                 os.path.expanduser(value), ext):
             # FIX ME!
             #self.notify(_('Error saving playlist...'))
             print _('Error saving playlist...')
     elif action == "play_one":
         if os.path.exists(os.path.expanduser(value)):
             self.clear_playlist_callback()
             self.playlist.load(os.path.abspath(os.path.expanduser(value)))
Exemple #7
0
    def extract_metadata(self):
        self.__log.debug('Extracting metadata for %s', self.__filepath)

        if self._ask_gpodder_for_metadata():
            if self.coverart is None:
                self.coverart = self.__find_coverart()
            return

        filetype = util.detect_filetype(self.__filepath)

        if filetype == 'mp3':
            import mutagen.mp3 as meta_parser
        elif filetype == 'ogg':
            import mutagen.oggvorbis as meta_parser
        elif filetype == 'flac':
            import mutagen.flac as meta_parser
        elif filetype in ['mp4', 'm4a']:
            import mutagen.mp4 as meta_parser
        else:
            self.__log.info('Extracting metadata not supported for %s files.',
                            filetype)
            return False

        try:
            metadata = meta_parser.Open(self.__filepath)
            self.__metadata_extracted = True
        except Exception, e:
            self.title = util.pretty_filename(self.__filepath)
            self.__log.exception('Error running metadata parser...')
            self.__metadata_extracted = False
            return False
Exemple #8
0
    def load_media(self, uri):
        filetype = util.detect_filetype(uri)

        if filetype != self._current_filetype or self._player is None:
            self.__setup_player()

        if self._player is not None:
            self._filesrc.set_property(self._filesrc_property, uri)

        self._current_filetype = filetype
Exemple #9
0
    def load_media( self, uri ):
        filetype = util.detect_filetype(uri)

        if filetype != self._current_filetype or self._player is None:
            self.__setup_player()

        if self._player is not None:
            self._filesrc.set_property( self._filesrc_property, uri )

        self._current_filetype = filetype
Exemple #10
0
    def load(self, filepath, play=True):
        """ Detects filepath's filetype then loads it using
            the appropriate loader function """
        self.__log.debug('Attempting to load %s', filepath)
        _play = self.is_empty or (self.end_of_playlist()
                                  and not self.get_position_duration()[0])
        if self.is_empty:
            _position = 0
        else:
            _position = len(self.__queue)
        error = False

        if os.path.isdir(filepath):
            self.load_directory(filepath, True)
        else:
            parsers = {
                'm3u': playlistformat.M3U_Playlist,
                'pls': playlistformat.PLS_Playlist
            }
            extension = util.detect_filetype(filepath)
            if parsers.has_key(extension):  # importing a playlist
                self.__log.info('Loading playlist file (%s)', extension)
                parser = parsers[extension](filepath, self.__queue)
                self.filepath = filepath
                self._id = None
                self.__queue.playlist_id = self.id
                if parser.parse(filepath):
                    self.__queue = parser.get_queue()
                    self.__file_queued(filepath, True, False)
                else:
                    return False
            else:  # importing a single file
                error = not self.append(filepath, notify=False)

        # if we let the queue emit a current_item_changed signal (which will
        # happen if load_from_bookmark changes the current track), the player
        # will start playing and ingore the resume point
        self.__queue.modified = True
        if _play and not self.is_empty:
            if not self.null:
                self.stop(False, False)
            if _position == 0:
                self.__queue.disable_notifications = True
                self.load_from_resume_bookmark()
                self.__queue.disable_notifications = False
            else:
                self.__queue.set_current_item_position(_position)
            #self.notify( 'stop-requested', caller=self.load )
            self.new_track_loaded()
            if play:
                self.play()
            #self.notify( 'new-track-loaded', caller=self.load )
            #self.notify( 'new-metadata-available', caller=self.load )

        return not error
Exemple #11
0
    def __init__(self, filepath):
        self.__log = logging.getLogger('panucci.playlist.FileMetadata')
        self.__filepath = filepath
        self.filetype = util.detect_filetype(self.__filepath)

        self.title = ''
        self.artist = ''
        self.album = ''
        self.length = 0
        self.coverart = None

        self.__metadata_extracted = False
Exemple #12
0
    def load(self, filepath, play=True):
        """ Detects filepath's filetype then loads it using
            the appropriate loader function """
        self.__log.debug('Attempting to load %s', filepath)
        _play = self.is_empty or (self.end_of_playlist() and not self.get_position_duration()[0])
        if self.is_empty:
            _position = 0
        else:
            _position = len(self.__queue)
        error = False

        if os.path.isdir(filepath):
            self.load_directory(filepath, True)
        else:
            parsers = {'m3u': playlistformat.M3U_Playlist, 'pls': playlistformat.PLS_Playlist}
            extension = util.detect_filetype(filepath)
            if parsers.has_key(extension): # importing a playlist
                self.__log.info('Loading playlist file (%s)', extension)
                parser = parsers[extension](filepath, self.__queue)
                self.filepath = filepath
                self._id = None
                self.__queue.playlist_id = self.id
                if parser.parse(filepath):
                    self.__queue = parser.get_queue()
                    self.__file_queued( filepath, True, False )
                else:
                   return False
            else:                          # importing a single file
                error = not self.append(filepath, notify=False)

        # if we let the queue emit a current_item_changed signal (which will
        # happen if load_from_bookmark changes the current track), the player
        # will start playing and ingore the resume point
        self.__queue.modified = True
        if _play and not self.is_empty:
            if not self.null:
                self.stop(False, False)
            if _position == 0:
                self.__queue.disable_notifications = True
                self.load_from_resume_bookmark()
                self.__queue.disable_notifications = False
            else:
                self.__queue.set_current_item_position(_position)
            #self.notify( 'stop-requested', caller=self.load )
            self.new_track_loaded()
            if play:
                self.play()
            #self.notify( 'new-track-loaded', caller=self.load )
            #self.notify( 'new-metadata-available', caller=self.load )

        return not error
Exemple #13
0
    def save_playlist_callback(self):
        filenames = qtutil.get_file_from_filechooser(self, save_file=True, save_to=True)
        if not filenames:
            return False

        filename = filenames[0]
        if os.path.isfile(filename):
            response = qtutil.dialog(self.main_window,  _('File already exists!'),
                _('The file %s already exists. You can choose another name or '
                  'overwrite the existing file.') % os.path.basename(filename), False, True, True, True)

            if response == QtGui.QMessageBox.Cancel:
                return None
            elif response == QtGui.QMessageBox.Discard:
                return self.save_playlist_callback()

        ext = util.detect_filetype(filename)
        if not self.playlist.save_to_new_playlist(filename, ext):
            self.notify(_('Error saving playlist...'))
            return False

        return True
Exemple #14
0
 def filetype(self):
     return util.detect_filetype(self.filepath)
Exemple #15
0
 def filetype(self):
     return util.detect_filetype(self.filepath)