Пример #1
0
def dj_alex():
    with open('bunch_of_albums.txt', 'r') as f:
        x = f.readlines()
    albumlist = []
    for i in x:
        try:
            print(i)
            j = i.split(' - ')
            artist = j[0].strip()
            album = j[1].strip()
            print(f'album: {album} artist: {artist}')
            album = delete_label(album)
            print('\n\n\n\n')
            albumlist.append([artist, album])
        except:
            pass
    print(albumlist)
    sp, u = splog_on()
    track_id_all = []
    for k in albumlist:
        print(k)
        track_ids = get_spotify_ids_for_album(sp, k)
        track_id_all = track_id_all + track_ids
    print(f'length of track id all: {len(track_id_all)}')
    print(track_id_all)
    do_a_playlist(track_id_all, 'DJ Alex Year End')
Пример #2
0
def paste_list():
    import re

    site = 'https://www.pastemagazine.com/music/best-albums/best-albums-of-2020/#49-ganser-just-look-at-that-sky'
    hdr = {'User-Agent': 'Mozilla/5.0'}
    req = urllib.request.Request(site, headers=hdr)
    page = urllib.request.urlopen(req)
    bs = BeautifulSoup(page, "html.parser")

    a = bs.findAll('h2')
    all_tracks = []
    sp, username = splog_on()
    for i in a:
        j = i.text[3:]
        k = re.sub(r'\W+', '', j[:2])
        j = k + j[2:]
        j = j.strip().split(':')
        artist = j[0]
        album = j[1].strip()
        print(j)
        track_ids = get_spotify_ids_for_album(sp, [artist, album])
        for t in track_ids:
            all_tracks.append(t)
        print(f'found {len(track_ids)} tracks. Total: {len(all_tracks)}')
    print(f'pushing {len(all_tracks)} tracks...')
    do_a_playlist(all_tracks, 'Paste top 50')
Пример #3
0
def make_spotify_playlists(Session, choices, recency):
    session = Session()
    errors = []
    for i in choices:
        a = session.query(band).filter(band.source==i).filter(band.spotify_id != None)
        b = []
        a = [x for x in a if len(x.spotify_id) == 22]  # check proper spotify id, length ==22
        too_old = []
        for j in a:
            try:
                if j.spotify_release_date != None and j.spotify_release_date != '':
                    if int(j.spotify_release_date[:4]) >= int(recency):
                        b.append(j)
                    elif int(j.spotify_release_date[:4]) < int(recency):
                        too_old.append(j)

                else:
                    if j.release_year != None and j.spotify_release_date != '':
                        if int(j.release_year[:4]) >= int(recency):
                            b.append(j)
                        else:
                            too_old.append(j)

            except Exception as e:
                print (f'no go error: {str(e)}', j.release_year, j.spotify_id)

        print ('Creating {} playlist. {} tracks found. {} tracks too old'.format(i, len(b), len(too_old)))
        ids_to_add = [c.spotify_id for c in b]
        ids_to_add = [x for x in ids_to_add if len(x) == 22]
        playlist_name = 'Scout ' + i
        try:
            do_a_playlist(ids_to_add, playlist_name)
        except Exception as e:
            errors.append([i, str(e)])
    return errors
Пример #4
0
def list_from_list():
    fname = 'tracklist.txt'
    with open(fname, 'r') as f:
        tracks = f.readlines()
    track_names = clean_tracks(tracks)
    print(track_names)
    for i in track_names:
        print(i)
    playlist_name = input('enter playlist name\n:')
    id_list = find_spotify_ids_no_db(track_names)
    do_a_playlist(id_list, playlist_name)
Пример #5
0
def make_kexp_countdown_playlists():
    albums = kexp_countdown_make_playlists()
    fname = 'albums_df.csv'
    if os.path.isfile(fname):
        albums_df = pd.read_csv(fname, compression='gzip')
    else:
        albums_df = pd.DataFrame([])
        for i in albums:
            albums_df = albums_df.append({
                'artist': i[0],
                'album': i[1]
            },
                                         ignore_index=True)
        albums_df['track_id'] = pd.Series([])
        albums_df.to_csv('albums_df.csv', compression='gzip', index=False)

    pd.set_option('display.max_rows', 1000)
    print(albums_df)
    input('enter')
    sp, username = splog_on()
    x = albums_df[albums_df['track_id'].isnull()]
    print(x)
    for index, row in x.iterrows():
        artist = row['artist']
        album = row['album']
        print(artist)
        track_ids = get_spotify_ids_for_album(sp, [artist, album])
        delete_row = albums_df[albums_df['artist'] == artist].index
        albums_df = albums_df.drop(delete_row)
        for i in track_ids:
            albums_df = albums_df.append(
                {
                    'artist': artist,
                    'album': album,
                    'track_id': i
                },
                ignore_index=True)
    print(albums_df)
    albums_df.to_csv('albums_df.csv', compression='gzip', index=False)
    albums_df = albums_df[albums_df['track_id'].notnull()]
    track_ids = albums_df['track_id'].unique()
    print(track_ids)
    do_a_playlist(track_ids, 'KEXP 2020 countdown')
Пример #6
0
def dj_alex_year_end():
    c = []
    playlist_name = 'Scout DJ Alex Year End'
    base_site = 'https://kexp.org/read/2019/12/19/2019-top-ten-spotlight-dj-alex/'
    hdr = {'User-Agent': 'Mozilla/5.0'}
    req = urllib.request.Request(base_site, headers=hdr)
    page = urllib.request.urlopen(req)
    soup = BeautifulSoup(page, "html.parser")
    a = soup.findAll('b')

    j = []
    for i in a:
        if 'SINGLES' in i.text:
            print(i)
            x = i
            while x is not None:
                x = x.findNext('br')
                if x is not None:
                    y = x.nextSibling.strip()
                    if y != '':
                        j.append(y)
    print(j)
    print('\n\n\n')
    for k in j:
        # 01. Charli XCX - "Gone (feat. Christine & The Queens)" / "February 2017 (feat. Clairo & Yaeji)" / "Silver
        if is_number(k[:2]):
            k = k[3:]
        b = k.split('-')
        songs = b[1].split('/')
        artist = b[0].strip().replace('”', '').replace('“',
                                                       '').replace('"', '')
        for song in songs:
            song = song.strip().replace('”', '').replace('“',
                                                         '').replace('"', '')
            c.append([artist, song])
            print(f'{artist} - {song}')

    print(c)
    track_list = c
    id_list = find_spotify_ids_no_db(track_list)
    do_a_playlist(id_list, playlist_name)
Пример #7
0
def stereogum_year_end_staff_picks():

    c = []
    playlist_name = 'Stereogum Staff Picks 2020'
    base_site = 'https://www.stereogum.com/2109305/2020-best-songs-list/lists/year-in-review/2020-in-review/'
    hdr = {'User-Agent': 'Mozilla/5.0'}
    req = urllib.request.Request(base_site, headers=hdr)
    page = urllib.request.urlopen(req)
    soup = BeautifulSoup(page, "html.parser")
    a = soup.findAll('strong')
    for i in a:
        j = i.text.split('\n')
        for k in j:
            if is_number(k[:2]):
                m = k[3:]
                b = m.split('–')
                artist = b[0].strip().replace('”', '').replace('“', '')
                song = b[1].strip().replace('”', '').replace('“', '')
                print(artist, song)
                c.append(b)

    track_list = c
    id_list = find_spotify_ids_no_db(track_list)
    do_a_playlist(id_list, playlist_name)
Пример #8
0
def pfork_year_end_tracks():

    playlist_name = 'Pitchfork 2021 Review Songs'
    c = []
    allbands = []
    base_site = 'https://pitchfork.com/features/lists-and-guides/best-songs-2021/'
    hdr = {'User-Agent': 'Mozilla/5.0'}
    req = urllib.request.Request(base_site, headers=hdr)
    page = urllib.request.urlopen(req)
    soup = BeautifulSoup(page, "html.parser")
    a = soup.findAll("div", {"class": "heading-h3"})
    a = soup.findAll('h2')
    for i in a:
        b = i.text.split(':')
        artist = b[0].strip().replace('”', '').replace('“', '')
        song = b[1].strip().replace('”', '').replace('“', '')
        print(artist, song)
        c.append(b)

    track_list = c
    id_list = find_spotify_ids_no_db(track_list)
    do_a_playlist(id_list, playlist_name)

    return