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
=
@ -34,4 +38,3 @@ For this program to work you will need to (virtual environment recommended) inst
- (pip install) sqlite3
- (pip install) gmusicapi

@ -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,15 +87,17 @@ 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)

Loading…
Cancel
Save