def main():
    args = get_args()
    ytmusic = YTMusicTransfer()

    if args.all:
        s = Spotify()
        pl = s.getUserPlaylists(args.playlist)
        print(str(len(pl)) + " playlists found. Starting transfer...")
        count = 1
        for p in pl:
            print("Playlist " + str(count) + ": " + p['name'])
            count = count + 1
            try:
                playlist = Spotify().getSpotifyPlaylist(
                    p['external_urls']['spotify'])
                videoIds = ytmusic.search_songs(playlist['tracks'])
                playlist_id = ytmusic.create_playlist(
                    p['name'], p['description'],
                    'PUBLIC' if args.public else 'PRIVATE', videoIds)
                print(playlist_id)
            except Exception as ex:
                print("Could not transfer playlist " + p['name'] +
                      ". Exception" + str(ex))
        return

    if args.remove:
        ytmusic.remove_playlists(args.playlist)
        return

    date = ""
    if args.date:
        date = " " + datetime.today().strftime('%m/%d/%Y')
    try:
        playlist = Spotify().getSpotifyPlaylist(args.playlist)
    except Exception as ex:
        print(
            "Could not get Spotify playlist. Please check the playlist link.\n Error: "
            + repr(ex))
        return

    name = args.name + date if args.name else playlist['name'] + date
    info = playlist['description'] if (args.info is None) else args.info

    if args.update:
        playlistId = ytmusic.get_playlist_id(args.update)
        videoIds = ytmusic.search_songs(playlist['tracks'])
        ytmusic.remove_songs(playlistId)
        ytmusic.add_playlist_items(playlistId, videoIds)

    else:
        videoIds = ytmusic.search_songs(playlist['tracks'])
        playlistId = ytmusic.create_playlist(
            name, info, 'PUBLIC' if args.public else 'PRIVATE')
        ytmusic.add_playlist_items(playlistId, videoIds)

        print("Success: created playlist \"" + name + "\"\n" +
              "https://music.youtube.com/playlist?list=" + playlistId)
Esempio n. 2
0
def main(argv):
    args = get_args()

    gmusic = GoogleMusic()

    if args.all:
        s = Spotify()
        pl = s.getUserPlaylists(args.playlist)
        print(str(len(pl)) + " playlists found. Starting transfer...")
        count = 1
        for p in pl:
            print("Playlist " + str(count) + ": " + p['name'])
            count = count + 1
            try:
                playlist = Spotify().getSpotifyPlaylist(p['external_urls']['spotify'])
                gmusic.createPlaylist(p['name'], playlist['tracks'], args.public)
            except Exception as ex:
                print("Could not transfer playlist")
        return

    if args.remove:
        gmusic.remove_playlists(args.playlist)
        return

    date = ""
    if args.date:
        date = " " + datetime.today().strftime('%m/%d/%Y')

    if os.path.isfile(args.playlist):
        with open(args.playlist, 'r') as f:
            songs = f.readlines()
        if args.name:
            name = args.name + date
        else:
            name = os.path.basename(args.playlist).split('.')[0] + date
        gmusic.createPlaylist(name, songs, args.public)
        return

    try:
        playlist = Spotify().getSpotifyPlaylist(args.playlist)
    except Exception as ex:
        print("Could not get Spotify playlist. Please check the playlist link.\n Error: " + repr(ex))
        return

    if args.update:
        playlistId = gmusic.getPlaylistId(args.update)
        gmusic.removeSongs(playlistId)
        gmusic.addSongs(playlistId, playlist['tracks'])
    else:
        if args.name:
            name = args.name + date
        else:
            name = playlist['name'] + date

        gmusic.createPlaylist(name, playlist['tracks'], args.public)