From f5852fe9e947f5af2d95ecee1e5ac4078320e277 Mon Sep 17 00:00:00 2001 From: nicolas <821778+novalic@users.noreply.github.com> Date: Mon, 15 Aug 2022 03:22:52 +0300 Subject: [PATCH] task: aesthetical code updatese and adds status to readme --- README.md | 5 ++++- download_library.py | 46 ++++++++++++++++++++++----------------------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 0f57a87..f7e6896 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +Status += +This repo is useless as Google Play Music doesn't exist anymore. I made a final update for the sake of it. + Google Play Music Library Download = @@ -34,4 +38,3 @@ For this program to work you will need to (virtual environment recommended) inst - (pip install) sqlite3 - (pip install) gmusicapi - diff --git a/download_library.py b/download_library.py index e59096f..599ae40 100644 --- a/download_library.py +++ b/download_library.py @@ -1,4 +1,3 @@ -import logging import os import sqlite3 @@ -8,28 +7,26 @@ from os import path def start_db(): try: - sqliteConnection = sqlite3.connect('songs.db') - sqlite_create_table_query = '''CREATE TABLE IF NOT EXISTS song ( - id INTEGER PRIMARY KEY, - google_id TEXT NOT NULL, - downloaded INTEGER);''' + connection = sqlite3.connect('songs.db') + sqlite_create_table_query = ''' + CREATE TABLE IF NOT EXISTS song (id INTEGER PRIMARY KEY, google_id TEXT NOT NULL, downloaded INTEGER); + ''' - cursor = sqliteConnection.cursor() + cursor = connection.cursor() cursor.execute(sqlite_create_table_query) - sqliteConnection.commit() + connection.commit() cursor.close() - except sqlite3.Error as exc: + except sqlite3.Error: return - return sqliteConnection + return connection def insert_song(connection, song_id, failure=False): - sql = ''' INSERT INTO song (google_id, downloaded) - VALUES(?,?) ''' + sql = '''INSERT INTO song (google_id, downloaded) VALUES(?,?)''' cursor = connection.cursor() cursor.execute(sql, (song_id, int(not failure))) @@ -58,7 +55,6 @@ def main(): db_connection = start_db() already_downloaded = get_all_song_ids(db_connection) - for song in songs: song_id = song['id'] @@ -83,7 +79,7 @@ def main(): os.mkdir(level_one) except FileExistsError: pass - except Exception as exc: + except Exception: insert_song(db_connection, song_id, True) continue @@ -91,23 +87,25 @@ def main(): os.mkdir(full_path) except FileExistsError: pass - except Exception as exc: + except Exception: insert_song(db_connection, song_id, True) continue try: downloaded_song = mm.download_song(song_id) - except Exception as exc: + except Exception: insert_song(db_connection, song_id, True) + downloaded_song = None + + if downloaded_song: + full_path += f"/{downloaded_song[0]}" + file_path = path.relpath(full_path) - full_path += f"/{downloaded_song[0]}" - file_path = path.relpath(full_path) - - file_to_write = open(file_path, "wb") - file_to_write.write(downloaded_song[1]) - file_to_write.close() - insert_song(db_connection, song_id) + file_to_write = open(file_path, "wb") + file_to_write.write(downloaded_song[1]) + file_to_write.close() + insert_song(db_connection, song_id) if __name__ == "__main__": - main() + main()