def getstationsandsavetodb(tablename):
    stations_library = gmapi.get_all_stations()
    for stationitem in stations_library:
        station_items = []
        station_name = stationitem['name'].lower().translate(removepunct)
        station_id = stationitem['id']
        station_items.append(station_name)
        station_items.append(station_id)
        query = "insert into {0} (name, id) values (?{1})"
        query = query.format(tablename, ",?")
        insert_db_table(tablename, query, station_items)
def getgenresandsavetodb(tablename):
    genres_library = gmapi.get_genres()
    for genresitem in genres_library:
        genres_items = []
        genres_name = genresitem['name'].lower().translate(removepunct)
        genres_id = genresitem['id']
        genres_items.append(genres_name)
        genres_items.append(genres_id)
        query = "insert into {0} (name, id) values (?{1})"
        query = query.format(tablename, ",?")
        insert_db_table(tablename, query, genres_items)
def getpodcastsandsavetodb(tablename):
    podcast_library = gmapi.get_all_podcast_episodes(incremental=False,
                                                     include_deleted=None,
                                                     updated_after=None)
    for i in range(0, len(podcast_library)):
        podcast_items = []
        podcast_name = podcast_library[i]['seriesTitle']
        podcast_episode = podcast_library[i]['episodeId']
        podcast_time = podcast_library[i]['publicationTimestampMillis']
        podcast_items = [podcast_name, podcast_episode, podcast_time]
        query = "insert into {0} (name, id, time) values (?{1})"
        query = query.format(tablename, ",?,?")
        insert_db_table(tablename, query, podcast_items)
def getsongsfromlibraryandsavetodb(tablename):
    songs_library = gmapi.get_all_songs()
    for i in range(0, len(songs_library)):
        song_items = []
        columns = sorted(songs_library[i].keys())
        requiredcolumns = ('album', 'albumArtist', 'id', 'title')
        dbcolumns = list(filter(lambda x: x in requiredcolumns, columns))
        for j in dbcolumns:
            song_row = songs_library[i][j]
            if (j == 'id'):
                song_items.append(song_row)
            else:
                song_items.append(song_row.lower().translate(removepunct))
        query = "insert into {0} (album, albumArtist, id, title) values (?{1})"
        query = query.format(tablename, ",?" * (len(requiredcolumns) - 1))
        insert_db_table(tablename, query, song_items)
def getsongsfromplaylistandsavetodb(tablename):
    playlists_library = gmapi.get_all_user_playlist_contents()
    for playlistitem in playlists_library:
        playlistname = playlistitem['name'].lower()
        tracks_library = playlistitem['tracks']
        for i in range(0, len(tracks_library)):
            songs_library = tracks_library[i]['track']
            song_id = tracks_library[i]['trackId']
            song_items = []
            song_items.append(playlistname.lower().translate(removepunct))
            song_items.append(song_id)
            columns = sorted(songs_library.keys())
            requiredcolumns = ('name', 'trackId', 'album', 'albumArtist',
                               'title')
            dbcolumns = list(filter(lambda x: x in requiredcolumns, columns))
            for j in dbcolumns:
                song_row = songs_library[j]
                song_items.append(song_row.lower().translate(removepunct))
            query = "insert into {0} (name, id, album, albumArtist, title) values (?{1})"
            query = query.format(tablename, ",?" * (len(requiredcolumns) - 1))
            insert_db_table(tablename, query, song_items)