implemented the file and folder paths in the db
This commit is contained in:
parent
6f2ecded4c
commit
f16033b584
@ -1,6 +1,5 @@
|
||||
import json
|
||||
import os.path
|
||||
import pandas as pd
|
||||
import requests
|
||||
import logging
|
||||
|
||||
|
@ -148,11 +148,12 @@ SELECT DISTINCT
|
||||
)
|
||||
)
|
||||
),
|
||||
'id', track.id,
|
||||
'musicbrainz_releasetrackid', track.id,
|
||||
'musicbrainz_albumid', release_.id,
|
||||
'track', track.track,
|
||||
'title', track.track,
|
||||
'isrc', track.isrc,
|
||||
'title', release_.title,
|
||||
'album', release_.title,
|
||||
'copyright', release_.copyright,
|
||||
'album_status', release_.album_status,
|
||||
'language', release_.language,
|
||||
@ -164,7 +165,12 @@ SELECT DISTINCT
|
||||
'albumsort', release_group.albumsort,
|
||||
'musicbrainz_albumtype', release_group.musicbrainz_albumtype,
|
||||
'compilation', release_group.compilation,
|
||||
'album_artist_id', release_group.album_artist_id
|
||||
'album_artist_id', release_group.album_artist_id,
|
||||
'path', track.path,
|
||||
'file', track.file,
|
||||
'genre', track.genre,
|
||||
'url', track.url,
|
||||
'src', track.src
|
||||
)
|
||||
FROM track, release_, release_group,artist, artist_track
|
||||
WHERE
|
||||
@ -196,14 +202,41 @@ def get_tracks_without_isrc():
|
||||
return get_custom_track(["track.isrc IS NULL"])
|
||||
|
||||
|
||||
def get_tracks_without_filepath():
|
||||
return get_custom_track(["(track.file IS NULL OR track.path IS NULL OR track.genre IS NULL)"])
|
||||
|
||||
|
||||
def update_download_status(track_id: str):
|
||||
pass
|
||||
|
||||
|
||||
def set_download_data(track_id: str, url: str, src: str):
|
||||
query = f"""
|
||||
UPDATE track
|
||||
SET url = ?,
|
||||
src = ?
|
||||
WHERE '{track_id}' == id;
|
||||
"""
|
||||
cursor.execute(query, (url, src))
|
||||
connection.commit()
|
||||
|
||||
|
||||
def set_filepath(track_id: str, file: str, path: str, genre: str):
|
||||
query = f"""
|
||||
UPDATE track
|
||||
SET file = ?,
|
||||
path = ?,
|
||||
genre = ?
|
||||
WHERE '{track_id}' == id;
|
||||
"""
|
||||
cursor.execute(query, (file, path, genre))
|
||||
connection.commit()
|
||||
|
||||
|
||||
init_db(cursor=cursor, connection=connection, reset_anyways=False)
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
# get_track(["track.downloaded == 0", "track.isrc IS NOT NULL"])
|
||||
#
|
||||
for track in get_tracks_without_isrc():
|
||||
print(track['track'], [artist['name'] for artist in track['artists']])
|
||||
|
||||
# print(get_track_metadata("a85d5ed5-20e5-4f95-8034-d204d81a36dd"))
|
||||
|
@ -47,7 +47,9 @@ CREATE TABLE track (
|
||||
release_id TEXT NOT NULL,
|
||||
track TEXT,
|
||||
isrc TEXT,
|
||||
filepath TEXT,
|
||||
genre TEXT,
|
||||
path TEXT,
|
||||
file TEXT,
|
||||
url TEXT,
|
||||
src TEXT
|
||||
);
|
||||
|
@ -1,29 +1,19 @@
|
||||
import os.path
|
||||
import shlex
|
||||
import pandas as pd
|
||||
import json
|
||||
|
||||
from metadata import database
|
||||
|
||||
|
||||
class UrlPath:
|
||||
def __init__(self, genre: str, temp: str = "temp", file: str = ".cache3.csv", step_two_file: str = ".cache2.csv"):
|
||||
self.temp = temp
|
||||
self.file = file
|
||||
self.metadata = pd.read_csv(os.path.join(self.temp, step_two_file), index_col=0)
|
||||
|
||||
self.genre = genre
|
||||
|
||||
new_metadata = []
|
||||
|
||||
for idx, row in self.metadata.iterrows():
|
||||
for row in database.get_tracks_without_filepath():
|
||||
file, path = self.get_path_from_row(row)
|
||||
new_row = dict(row)
|
||||
new_row['path'] = path
|
||||
new_row['file'] = file
|
||||
new_row['genre'] = self.genre
|
||||
new_metadata.append(new_row)
|
||||
|
||||
new_df = pd.DataFrame(new_metadata)
|
||||
new_df.to_csv(os.path.join(self.temp, self.file))
|
||||
database.set_filepath(row['id'], file, path, genre)
|
||||
|
||||
|
||||
def get_path_from_row(self, row):
|
||||
@ -45,7 +35,7 @@ class UrlPath:
|
||||
return self.escape_part(row['album'])
|
||||
|
||||
def get_artist(self, row):
|
||||
artists = json.loads(row['artist'].replace("'", '"'))
|
||||
artists = [artist['name'] for artist in row['artists']]
|
||||
return self.escape_part(artists[0])
|
||||
|
||||
def get_song(self, row):
|
||||
|
Loading…
Reference in New Issue
Block a user