task: aesthetical code updatese and adds status to readme

master
nicolas 3 years ago
parent f155d1d162
commit f5852fe9e9

@ -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 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) sqlite3
- (pip install) gmusicapi - (pip install) gmusicapi

@ -1,4 +1,3 @@
import logging
import os import os
import sqlite3 import sqlite3
@ -8,28 +7,26 @@ from os import path
def start_db(): def start_db():
try: try:
sqliteConnection = sqlite3.connect('songs.db') connection = sqlite3.connect('songs.db')
sqlite_create_table_query = '''CREATE TABLE IF NOT EXISTS song ( sqlite_create_table_query = '''
id INTEGER PRIMARY KEY, CREATE TABLE IF NOT EXISTS song (id INTEGER PRIMARY KEY, google_id TEXT NOT NULL, downloaded INTEGER);
google_id TEXT NOT NULL, '''
downloaded INTEGER);'''
cursor = sqliteConnection.cursor() cursor = connection.cursor()
cursor.execute(sqlite_create_table_query) cursor.execute(sqlite_create_table_query)
sqliteConnection.commit() connection.commit()
cursor.close() cursor.close()
except sqlite3.Error as exc: except sqlite3.Error:
return return
return sqliteConnection return connection
def insert_song(connection, song_id, failure=False): def insert_song(connection, song_id, failure=False):
sql = ''' INSERT INTO song (google_id, downloaded) sql = '''INSERT INTO song (google_id, downloaded) VALUES(?,?)'''
VALUES(?,?) '''
cursor = connection.cursor() cursor = connection.cursor()
cursor.execute(sql, (song_id, int(not failure))) cursor.execute(sql, (song_id, int(not failure)))
@ -58,7 +55,6 @@ def main():
db_connection = start_db() db_connection = start_db()
already_downloaded = get_all_song_ids(db_connection) already_downloaded = get_all_song_ids(db_connection)
for song in songs: for song in songs:
song_id = song['id'] song_id = song['id']
@ -83,7 +79,7 @@ def main():
os.mkdir(level_one) os.mkdir(level_one)
except FileExistsError: except FileExistsError:
pass pass
except Exception as exc: except Exception:
insert_song(db_connection, song_id, True) insert_song(db_connection, song_id, True)
continue continue
@ -91,23 +87,25 @@ def main():
os.mkdir(full_path) os.mkdir(full_path)
except FileExistsError: except FileExistsError:
pass pass
except Exception as exc: except Exception:
insert_song(db_connection, song_id, True) insert_song(db_connection, song_id, True)
continue continue
try: try:
downloaded_song = mm.download_song(song_id) downloaded_song = mm.download_song(song_id)
except Exception as exc: except Exception:
insert_song(db_connection, song_id, True) 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_to_write = open(file_path, "wb")
file_path = path.relpath(full_path) file_to_write.write(downloaded_song[1])
file_to_write.close()
file_to_write = open(file_path, "wb") insert_song(db_connection, song_id)
file_to_write.write(downloaded_song[1])
file_to_write.close()
insert_song(db_connection, song_id)
if __name__ == "__main__": if __name__ == "__main__":
main() main()

Loading…
Cancel
Save