Esempio n. 1
0
def get_lastfmTag_playlist(genre):

    artists_mbid = []
    song = []
    tracks = []

    lastfm_playlist = get_lastfmGenre_playlist(genre)

    song = get_genre_playlist(genre)
    if song is not None:

        test = check_playlist(lastfm_playlist, song)
        return song

    for i in lastfm_playlist["toptracks"]["track"]:

        track_mbid = i["mbid"]

        if track_mbid != "":

            track_name = i["name"]
            artist_name = i["artist"]["name"]
            artist_mbid = i["artist"]["mbid"]

            artist_data = Class.Artists(artist_name=artist_name, artist_mbid=artist_mbid)

            t_data = Class.Tracks().query(Class.Tracks.track_mbid == track_mbid).get()
            if t_data is None:

                artist_key = Class.Artists().query(Class.Artists.artist_mbid == artist_mbid).get(keys_only=True)
                if artist_key is not None:

                    t_data = Class.Tracks().query(Class.Tracks.track_name == track_name, ancestor=artist_key).get()
                    if t_data is None:

                        t_data = Class.Tracks(
                            track_name=track_name,
                            track_video=track.get_video(artist_name, track_name),
                            track_mbid=track_mbid,
                        )

                if artist_mbid != "":

                    if artist_mbid not in artists_mbid:
                        artists_mbid.append(artist_mbid)
                        taskqueue.add(
                            url="/worker",
                            params={
                                "f": '[track.get_tracks(w.album_mbid) for w in  artist.get_artist_albums("%s")[1]]'
                                % artist_mbid
                            },
                        )
                    pass

            song.append((artist_data, t_data))
            tracks.append(t_data)
    playlist = Class.Playlists(playlist_name=genre, playlist_tracks=tracks, key=ndb.Key(Class.Playlists, genre))
    # playlist.put()

    return song
Esempio n. 2
0
def get_playlist_from_url(playlist_name):

    playlist = {"data": []}

    if "frontpage" in playlist_name:
        logging.error("front")
        url = tools.get_url("lastfm", "toptracks", " ")
        logging.error(url)
        j = tools.get_json(url)

        for i in j["tracks"]["track"]:
            if len(playlist["data"]) < 11:
                mbid = i["mbid"]
                track_name = i["name"]
                artist_name = i["artist"]["name"]
                ancestor_key = Class.Artists().query(Class.Artists.artist_name == artist_name).get(keys_only=True)
                if ancestor_key is not None:
                    tracks = Class.Tracks().query(Class.Tracks.track_name == track_name, ancestor=ancestor_key).get()
                else:
                    tracks = None
                if tracks is None:
                    track_video = track.get_video(artist_name, track_name)
                else:
                    track_video = tracks.track_video

                video = {
                    "video_artist": artist_name,
                    "video_track": track_name,
                    "playlist_videos": track_video,
                    "mbid": mbid,
                }

                playlist["data"].append(video)

                p = Class.Playlists(
                    playlist_name=playlist_name,
                    playlist_json=j,
                    playlist_videos=playlist,
                    key=ndb.Key(Class.Playlists, playlist_name),
                )
                # p.put()
        memcache.set(playlist_name, playlist)
        return playlist

    logging.error("radio")
    if "radio" in playlist_name:
        if "artist" in playlist_name:
            params = playlist_name.split()
            mbid = params[1]
            url = tools.get_url("echonest", "playlist", mbid)
        else:
            genre = playlist_name[0 : playlist_name.find("radio")]
            url = tools.get_url("echonest", "genre", genre).replace(" ", "%20")

        logging.error(url)

        j = tools.get_json(url)

        for i in j["response"]["songs"]:
            track_name = i["title"]
            artist_name = i["artist_name"]
            ancestor_key = Class.Artists().query(Class.Artists.artist_name == artist_name).get(keys_only=True)
            if ancestor_key is not None:
                tracks = Class.Tracks().query(Class.Tracks.track_name == track_name, ancestor=ancestor_key).get()
            else:
                tracks = None
            if tracks is None:
                track_video = track.get_video(artist_name, track_name)
            else:
                track_video = tracks.track_video

            video = {"video_artist": artist_name, "video_track": track_name, "playlist_videos": track_video}

            playlist["data"].append(video)

        p = Class.Playlists(
            playlist_name=playlist_name,
            playlist_json=j,
            playlist_videos=playlist,
            key=ndb.Key(Class.Playlists, playlist_name),
        )
        p.put()
        memcache.set(playlist_name, playlist)
        logging.error(playlist)
        return playlist