Beispiel #1
0
    def __parse_playlist(self, url):
        """
        Parses the playlist at the given URL and returns a list of URLs.
        """
    
        uris = []
        try:
            stopwatch = logging.stopwatch()
            fd = urllib.urlopen(url)
            logging.profile(stopwatch, "[mediaplayer] retrieved playlist")
        except:
            return uris
            
        data = fd.read()
        fd.close()

        filelines = [ l for l in data.splitlines()
                      if l.startswith("File") ]
        httplines = [ l for l in data.splitlines()
                      if l.startswith("http") ]
        for line in filelines:
            idx = line.find("=")
            uri = line[idx + 1:].strip()
            uris.append(uri)
        #end for

        for line in httplines:
            uri = line.strip()
            uris.append(uri)
        #end for

        return uris
Beispiel #2
0
    def __load(self, uri):  #, ctx_id = -1):
        """
        Loads and plays the given file.
        
        @param uri: URI of the file
        @param ctx_id: context ID to use; for internal use only
        @return: context ID
        """

        if (uri.startswith("http") and not uri.startswith("http://127.0.0.1")):
            stopwatch = logging.stopwatch()
            s_type = self.__stream_analyzer.analyze(uri)
            logging.profile(stopwatch, "[mediaplayer] analyzed stream type")
        else:
            s_type = StreamAnalyzer.STREAM

        if (s_type == StreamAnalyzer.PLAYLIST):
            uris = self.__parse_playlist(uri)
            if (uris):
                uri = uris[0]
            else:
                uri = ""

        # new context id is needed
        self.__state_machine.set_property("context id", self._new_context_id())

        self.__state_machine.set_property("suspension point", None)
        self.__state_machine.set_property("uri", uri)
        self.__state_machine.set_property("load time", time.time())
        gobject.idle_add(self.__state_machine.send_input, _INPUT_LOAD)

        return self.__state_machine.get_property("context id")
Beispiel #3
0
    def __load_file(self, f, is_manual):
        """
        Loads the given file.
        """

        #if (f.mimetype == "application/x-applet"):
        #    applet_id = f.resource
        #    self.call_service(msgs.CORE_SVC_LAUNCH_APPLET, applet_id)

        stopwatch = logging.stopwatch()

        if (f.mimetype == f.CONFIGURATOR):
            cfg_name = f.resource
            self.emit_message(msgs.UI_ACT_SHOW_DIALOG, cfg_name)

        else:
            if (is_manual):
                self.__show_dialog("player.PlayerWindow")

            #if (not f.mimetype in mimetypes.get_image_types()):
            self.emit_message(msgs.MEDIA_ACT_STOP)
            self.emit_message(msgs.MEDIA_ACT_LOAD, f)

            # update set of play files
            self.__current_file = f

            folder = self.__browser.get_current_folder()
            if (is_manual and folder != self.__play_folder):
                self.__play_folder = folder
                self.__random_files = []
                self.__invalidate_play_files()

        logging.profile(stopwatch, "[navigator] loaded file")
Beispiel #4
0
    def __load_track_info(self, item):
    
        stopwatch = logging.stopwatch()
        tags = tagreader.get_tags(item)
        logging.profile(stopwatch, "[audioplayer] retrieved audio tags")

        gobject.timeout_add(0, self.__on_track_info, item, tags)
Beispiel #5
0
    def load(self, f):

        self.__lyrics = ""
        self.__have_cover = False
        
        stopwatch = logging.stopwatch()
        self.__player = self.call_service(msgs.MEDIA_SVC_GET_OUTPUT)
        self.__player.connect_status_changed(self.__on_change_player_status)
        self.__player.connect_volume_changed(self.__on_change_player_volume)
        self.__player.connect_position_changed(self.__on_update_position)
        self.__player.connect_tag_discovered(self.__on_discovered_tags)
        self.__player.connect_error(self.__on_error)
        logging.profile(stopwatch, "[audioplayer] connected audio output")
        
        try:
            stopwatch = logging.stopwatch()
            self.__context_id = self.__player.load_audio(f)
            logging.profile(stopwatch, "[audioplayer] loaded media file: %s", f)
        except:
            logging.error("error loading media file: %s\n%s",
                          f, logging.stacktrace())

        stopwatch = logging.stopwatch()
        self.__current_file = f
        logging.profile(stopwatch, "[audioplayer] loaded track info")

        # load bookmarks
        self.__progress.set_bookmarks(media_bookmarks.get_bookmarks(f))

        self.emit_message(msgs.MEDIA_EV_LOADED, self, f)

        t = threading.Thread(target = self.__load_track_info, args = [f])
        t.setDaemon(True)
        gobject.idle_add(lambda *x:t.start() and False)
        
        if (self.__offscreen_buffer):
            self.render_buffered(self.__offscreen_buffer)
Beispiel #6
0
    def __on_track_info(self, item, tags):

        logging.debug("[audioplayer] processing track info")
        title = tags.get("TITLE") or item.name
        artist = tags.get("ARTIST") or "-"
        album = tags.get("ALBUM") or "-"

        self.__trackinfo.set_title(title)
        self.__trackinfo.set_album(album)
        self.__trackinfo.set_artist(artist)
        
        if (self.__offscreen_buffer):
            self.render_buffered(self.__offscreen_buffer)

        # load cover art
        self.call_service(msgs.COVERSTORE_SVC_GET_COVER,
                          item, self.__on_loaded_cover, self.__context_id,
                          logging.stopwatch())

        stopwatch = logging.stopwatch()
        self.emit_message(msgs.MEDIA_EV_TAG, "TITLE", title)
        self.emit_message(msgs.MEDIA_EV_TAG, "ARTIST", artist)
        self.emit_message(msgs.MEDIA_EV_TAG, "ALBUM", album)
        logging.profile(stopwatch, "[audioplayer] propagated audio tags")
Beispiel #7
0
    def query(self, qs, *query_args):
        """
        Parses and performs a given query. The query uses prefix notation to
        avoid brackets. Returns a set of value-tuples.
        """

        if (self.__is_dirty):
            self.__save_index()

        stopwatch = logging.stopwatch()

        # normalize argument strings (replace unsafe chars)
        qas = []
        for q in query_args:
            if (type(q) == type("")):
                qas.append(q.replace("'", "\\'"))
            else:
                qas.append(q)
        #end for
        qas = tuple(qas)
        if (qas):
            qs = qs % qas

        logging.debug("[fileindex] query: %s", qs)

        wrapped_qs = [qs]
        filter_props = self.__parse_filter(wrapped_qs)
        all_eids = set(self.__entries.keys())
        entry_ids = self.__parse_condition(wrapped_qs, all_eids)

        out = set()
        for eid in entry_ids:
            entry = self.__entries[eid]
            values = (entry.get(key, "") for key in filter_props)
            out.add(tuple(values))
        #end for

        if (len(out) < 100):
            logging.debug("[fileindex] result: %d items\n%s", len(out), out)
        else:
            logging.debug("[fileindex] result: %d items", len(out))
        logging.profile(stopwatch, "[fileindex] query: %s (yields %d items)",
                        str(qs), len(out))

        return out
Beispiel #8
0
    def __go_next(self):

        stopwatch = logging.stopwatch()
        if (not self.__play_files):
            self.__invalidate_play_files()

        repeat_mode = mb_config.repeat_mode()
        shuffle_mode = mb_config.shuffle_mode()

        if (repeat_mode == mb_config.REPEAT_MODE_NONE):
            if (shuffle_mode == mb_config.SHUFFLE_MODE_NONE):
                self.__play_next(False)

            elif (shuffle_mode == mb_config.SHUFFLE_MODE_ONE):
                self.__play_shuffled(False)

            elif (shuffle_mode == mb_config.SHUFFLE_MODE_ALL):
                self.__play_shuffled(True)

        elif (repeat_mode == mb_config.REPEAT_MODE_ONE):
            if (self.__current_file):
                self.__play_same()
            else:
                self.__play_next(True)

        elif (repeat_mode == mb_config.REPEAT_MODE_ALL):
            if (shuffle_mode == mb_config.SHUFFLE_MODE_NONE):
                self.__play_next(True)

            elif (shuffle_mode == mb_config.SHUFFLE_MODE_ONE):
                self.__play_shuffled(False)

            elif (shuffle_mode == mb_config.SHUFFLE_MODE_ALL):
                self.__play_shuffled(True)

        logging.profile(stopwatch, "[navigator] loaded next item")