Ejemplo n.º 1
0
    def fetch_current_song(self, room_id):
        try:
            response = self.get(["room", room_id, "playlist", "active"])
        except HTTPError as e:
            if e.response.status_code == 404:
                # No songs in active queue.
                return None
            else:
                raise e

        song_id = response["data"]["song"]["songid"]
        song_name = html.unescape(response["data"]["songInfo"]["name"])
        requester_id = response["data"]["song"]["userid"]
        played_at = utils.datetime_from_utc_milliseconds(
            response["data"]["song"]["played"])
        length = datetime.timedelta(
            milliseconds=response["data"]["song"]["songLength"])

        return QueUpQueueSong(
            song_id=song_id,
            song_name=song_name,
            requester_id=requester_id,
            requester_name=None,
            played_at=played_at,
            length=length,
        )
Ejemplo n.º 2
0
        def parse_song(song_json: Dict[str, Any]) -> QueUpQueueSong:
            song_id = song_json["songid"]
            requester_id = song_json["_user"]["_id"]
            requester_name = song_json["_user"]["username"]
            played_at = utils.datetime_from_utc_milliseconds(
                song_json["played"])
            length = datetime.timedelta(milliseconds=song_json["songLength"])

            return QueUpQueueSong(
                song_id=song_id,
                song_name=None,
                requester_id=requester_id,
                requester_name=requester_name,
                played_at=played_at,
                length=length,
            )
Ejemplo n.º 3
0
    def from_json(json_data):
        song_id = json_data["song_id"]
        song_name = json_data["song_name"]
        requester_id = json_data["requester_id"]
        requester_name = json_data["requester_name"]
        played_at = utils.datetime_from_utc_milliseconds(
            json_data["played_at"])
        length = datetime.timedelta(milliseconds=json_data["length"])

        return QueUpQueueSong(
            song_id=song_id,
            song_name=song_name,
            requester_id=requester_id,
            requester_name=requester_name,
            played_at=played_at,
            length=length,
        )
Ejemplo n.º 4
0
        def parse_song(song_json):
            song_id = song_json["_song"]["_id"]
            song_name = html.unescape(song_json["_song"]["name"])
            requester_id = song_json["_user"]["_id"]
            requester_name = song_json["_user"]["username"]
            played_at = utils.datetime_from_utc_milliseconds(
                song_json["played"])
            length = datetime.timedelta(
                milliseconds=song_json["_song"]["songLength"])

            return QueUpQueueSong(
                song_id=song_id,
                song_name=song_name,
                requester_id=requester_id,
                requester_name=requester_name,
                played_at=played_at,
                length=length,
            )
Ejemplo n.º 5
0
 def safe_deserialize(self, cache_result):
     return utils.datetime_from_utc_milliseconds(cache_result)