Exemplo n.º 1
0
    async def process_metadata(self, item):
        if item["type"] == "ssnc":
            if item["code"] == "mdst":  # beginning of metadata
                ### Start with fresh metadata, does not matter if we already had some
                self.current_metadata = Metadata(self.aiohttp_session, app)
                ### Add the mdst timing info as the first item in our metadata list
                self.current_metadata.set_field(item["name"], item["value"])
                #self.sync_rtsp(item["value"])

            elif item["code"] == "mden":  # end of metadata
                ### Add the mden as the last item to our metadata list
                self.current_metadata.set_field(item["name"], item["value"])
                persistent_id = self.current_metadata.get_field("persistentid")
                log.debug("Ended metadata {} for persistent_id {}".format(
                    item["value"], persistent_id))
                if self.next_item is None or self.next_item.recording.get_persistent_id(
                ) != persistent_id:
                    if self.next_item is None:
                        log.debug("No next item queued, looking up")
                    else:
                        log.debug(
                            "Next item id changed from {} to {}, looking up".
                            format(
                                self.next_item.recording.get_persistent_id(),
                                persistent_id))
                    ### Set up our recording object
                    recording = Recording(
                        self.current_metadata.get_field("persistentid"))

                    ### Get the recording ID, if possible. Load the recording info
                    ### from either Acousticbrainz or just the metadata we were sent
                    try:
                        recordingId = await self.current_metadata.get_recordingId(
                        )
                        ab_info = await self.acoustic_brainz.lookup_recording(
                            recordingId)
                        recording.load_acousticbrainz(ab_info)
                    except (Metadata.RecordingLookupError, TypeError,
                            FailedRequest):
                        recordingId = 0
                        recording.load_metadata(self.current_metadata)

                    ### Enqueue the item, to start at the frame specified in the mden message
                    await self.queue_item(recording)
                self.current_metadata = None

            elif item["code"] == "prgr":  # progress info
                await self.handle_progress(item)

            elif item["code"] == "pbeg":  # start playing
                pass

            elif item["code"] == "prsm":  # resume playing
                pass

            elif item["code"] == "pend":  # stop playing
                self.playback_state = PlaybackState.STOPPED
                if (self.current_item):
                    self.current_item.cancel()
                if (self.next_item):
                    self.next_item.cancel()

                pass

            elif item["code"] == "pfls":  # flush (pause?)
                pass

            elif item["code"] == "pvol":  # volume
                await handle_volume(item)

        elif item["type"] == "core":
            self.current_metadata.set_field(item["name"], item["value"])