Exemple #1
0
    def from_dict(cls, data: Dict):
        try:
            correction = data.pop("correction")
            data = correction.pop("track")
        except KeyError:
            pass

        if isinstance(data["artist"], str):
            data["artist"] = dict(name=data["artist"])

        data.update(
            dict(name=str(data["name"]),
                 artist=Artist.from_dict(data["artist"])))

        if "image" in data:
            data["image"] = list(map(Image.from_dict, data["image"]))
        if "top_tags" in data:
            data["top_tags"] = list(map(Tag.from_dict,
                                        data["top_tags"]["tag"]))
        if "wiki" in data:
            data["wiki"] = Wiki.from_dict(data["wiki"])
        if "album" in data:
            data["album"] = Album.from_dict(data["album"])
        if "attr" in data:
            data.update(data.pop("attr"))
        if "date" in data:
            date = data.pop("date")
            if isinstance(date, dict) and "timestamp" not in data:
                date.pop("text")
                data.update(date)

        return super(Track, cls).from_dict(data)
Exemple #2
0
 def setUp(self):
     self.artist = Artist.from_dict(
         dict(
             name="Guns N' Roses",
             mbid="eeb1195b-f213-4ce1-b28c-8565211f8e43",
         ))
     super(ArtistTests, self).setUp()
Exemple #3
0
    def from_dict(cls, data: Dict):
        if isinstance(data.get("artist"), str):
            data["artist"] = {"name": data["artist"]}

        if "name" not in data and "text" in data:
            data["name"] = data.pop("text")
        if "artist" in data:
            data["artist"] = Artist.from_dict(data["artist"])
        if "image" in data:
            data["image"] = list(map(Image.from_dict, data["image"]))
        if "tags" in data:
            data["tags"] = list(map(Tag.from_dict, data["tags"]["tag"]))
        if "tracks" in data:
            from pydrag.models.track import Track

            data["tracks"] = list(map(Track.from_dict,
                                      data["tracks"]["track"]))
        if "wiki" in data:
            data["wiki"] = Wiki.from_dict(data["wiki"])
        if "attr" in data:
            data.update(data.pop("attr"))

        return super().from_dict(data)
Exemple #4
0
 def setUp(self):
     self.artist = Artist.from_dict(
         {"name": "Guns N' Roses", "mbid": "eeb1195b-f213-4ce1-b28c-8565211f8e43"}
     )
     super().setUp()