mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-03 20:13:02 +00:00
major changes:
- resize images to 150x150 - convert them to webp - use $set to update database - remove comments in py code - a whole lot more
This commit is contained in:
Generated
+1
-1
@@ -308,7 +308,7 @@
|
||||
"sha256:f785375ca2b4e2192786f1e0d2a94c66900d12e780ebae1eccbbab85eb9a7054"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==4.0.1"
|
||||
"version": "== 4.0.1"
|
||||
},
|
||||
"requests": {
|
||||
"hashes": [
|
||||
|
||||
+20
-47
@@ -57,22 +57,31 @@ def search_by_title():
|
||||
songs_by_artists = all_songs_instance.find_songs_by_artist(query)
|
||||
all_songs.append(convert_to_json(songs_by_artists))
|
||||
|
||||
# songs = remove_duplicates(all_songs)
|
||||
|
||||
return {'songs': all_songs}
|
||||
|
||||
|
||||
@bp.route('/populate')
|
||||
def populate():
|
||||
sub_dirs, files = run_fast_scandir(home_dir, [".flac", ".mp3"])
|
||||
'''
|
||||
Populate the database with all songs in the music directory
|
||||
|
||||
checks if the song is in the database, if not, it adds it
|
||||
also checks if the album art exists in the image path, if not tries to
|
||||
extract it.
|
||||
'''
|
||||
files = run_fast_scandir(home_dir, [".flac", ".mp3"])[1]
|
||||
|
||||
bar = Bar('Processing', max=len(files))
|
||||
|
||||
for file in files:
|
||||
file_in_db_obj = all_songs_instance.find_song_by_path(file)
|
||||
song_obj = convert_one_to_json(file_in_db_obj)
|
||||
|
||||
try:
|
||||
image = song_obj['image']
|
||||
|
||||
if not os.path.exists(os.path.join(app_dir, 'images', 'thumbnails', image)):
|
||||
extract_thumb(file)
|
||||
except:
|
||||
image = None
|
||||
|
||||
@@ -82,48 +91,10 @@ def populate():
|
||||
except MutagenError:
|
||||
pass
|
||||
|
||||
if image is not None and not os.path.exists(image):
|
||||
|
||||
extract_thumb(file)
|
||||
|
||||
bar.next()
|
||||
|
||||
bar.finish()
|
||||
|
||||
# dirs = []
|
||||
# files = []
|
||||
|
||||
# for dir in sub_dirs:
|
||||
|
||||
# files_in_dir = run_fast_scandir(dir, [".flac", ".mp3"])[1]
|
||||
|
||||
# if len(files_in_dir) != 0:
|
||||
# dir_content = os.scandir(dir)
|
||||
|
||||
# for entry in dir_content:
|
||||
# dirs = []
|
||||
# files = []
|
||||
|
||||
# if entry.is_dir() and not entry.name.startswith('.'):
|
||||
# print(dir)
|
||||
# files_in_dir = run_fast_scandir(entry.path, [".flac", ".mp3"])[1]
|
||||
|
||||
# if len(files_in_dir) != 0:
|
||||
# dir_data = {
|
||||
# "name": entry.name,
|
||||
# "count": len(files_in_dir),
|
||||
# "path": entry.path.replace(home_dir, "")
|
||||
# }
|
||||
|
||||
# dirs.append(dir_data)
|
||||
|
||||
# if entry.is_file():
|
||||
# if isValidFile(entry.name) == True:
|
||||
# files.append(entry.path)
|
||||
|
||||
# print(dirs)
|
||||
|
||||
# return {"info": ''}
|
||||
return {'msg': 'updated everything'}
|
||||
|
||||
|
||||
@bp.route('/file/<file_id>')
|
||||
@@ -151,7 +122,7 @@ def get_folder_artists():
|
||||
this_artists = song['artists'].split(', ')
|
||||
|
||||
for artist in this_artists:
|
||||
|
||||
|
||||
if artist not in artists:
|
||||
artists.append(artist)
|
||||
|
||||
@@ -277,7 +248,8 @@ def getFolderTree():
|
||||
last_id = request.args.get('last_id')
|
||||
|
||||
if req_dir is not None:
|
||||
requested_dir = home_dir + req_dir
|
||||
requested_dir = os.path.join(home_dir, req_dir)
|
||||
print(requested_dir)
|
||||
else:
|
||||
requested_dir = home_dir
|
||||
|
||||
@@ -289,7 +261,7 @@ def getFolderTree():
|
||||
for entry in dir_content:
|
||||
if entry.is_dir() and not entry.name.startswith('.'):
|
||||
files_in_dir = run_fast_scandir(entry.path, [".flac", ".mp3"])[1]
|
||||
|
||||
|
||||
if len(files_in_dir) != 0:
|
||||
dir = {
|
||||
"name": entry.name,
|
||||
@@ -301,7 +273,8 @@ def getFolderTree():
|
||||
|
||||
if entry.is_file():
|
||||
if isValidFile(entry.name) == True:
|
||||
songs_array = all_songs_instance.find_songs_by_folder(req_dir, last_id)
|
||||
songs_array = all_songs_instance.find_songs_by_folder(
|
||||
req_dir, last_id)
|
||||
songs = convert_to_json(songs_array)
|
||||
for song in songs:
|
||||
song['artists'] = song['artists'].split(', ')
|
||||
@@ -309,7 +282,7 @@ def getFolderTree():
|
||||
files = songs
|
||||
|
||||
for file in files:
|
||||
del file['filepath']
|
||||
file['filepath'] = file['filepath'].replace(home_dir, '')
|
||||
|
||||
dir_content.close()
|
||||
end = time.time()
|
||||
|
||||
+20
-10
@@ -20,8 +20,8 @@ all_songs_instance = AllSongs()
|
||||
music_dir = os.environ.get("music_dir")
|
||||
music_dirs = os.environ.get("music_dirs")
|
||||
|
||||
home_dir = os.path.expanduser('~')
|
||||
app_dir = home_dir + '/.shit'
|
||||
home_dir = os.path.expanduser('~') + "/"
|
||||
app_dir = home_dir + '/.musicx'
|
||||
|
||||
|
||||
PORT = os.environ.get("PORT")
|
||||
@@ -47,10 +47,11 @@ def run_fast_scandir(dir, ext):
|
||||
|
||||
|
||||
def extract_thumb(path):
|
||||
img_path = app_dir + "/images/thumbnails/" + path.split('/')[-1] + '.jpg'
|
||||
webp_path = path.split('/')[-1] + '.webp'
|
||||
img_path = app_dir + "/images/thumbnails/" + webp_path
|
||||
|
||||
if os.path.exists(img_path):
|
||||
return path.split('/')[-1] + '.jpg'
|
||||
return webp_path
|
||||
|
||||
if path.endswith('.flac'):
|
||||
audio = FLAC(path)
|
||||
@@ -65,18 +66,27 @@ def extract_thumb(path):
|
||||
except IndexError:
|
||||
album_art = None
|
||||
|
||||
if album_art is not None:
|
||||
|
||||
if album_art is None:
|
||||
return "null.webp"
|
||||
else:
|
||||
img = Image.open(BytesIO(album_art))
|
||||
|
||||
try:
|
||||
img.save(img_path, 'JPEG')
|
||||
small_img = img.resize((150, 150), Image.ANTIALIAS)
|
||||
small_img.save(img_path, format="webp")
|
||||
except OSError:
|
||||
try:
|
||||
img.convert('RGB'.save(img_path, 'JPEG'))
|
||||
png = img.convert('RGB')
|
||||
small_img = png.resize((150, 150), Image.ANTIALIAS)
|
||||
small_img.save(img_path, format="webp")
|
||||
print('{} :: was png'.format(
|
||||
img_path
|
||||
))
|
||||
|
||||
except:
|
||||
img_path = None
|
||||
return path.split('/')[-1] + '.jpg'
|
||||
|
||||
return webp_path
|
||||
|
||||
|
||||
def getTags(full_path):
|
||||
@@ -253,7 +263,7 @@ def getFolderContents(filepath, folder):
|
||||
|
||||
def create_config_dir():
|
||||
home_dir = os.path.expanduser('~')
|
||||
config_folder = home_dir + "/.shit"
|
||||
config_folder = home_dir + app_dir
|
||||
|
||||
dirs = ["", "/images", "/images/artists", "/images/thumbnails"]
|
||||
|
||||
|
||||
@@ -50,8 +50,9 @@ class AllSongs(Mongo):
|
||||
return self.collection.find_one({'_id': ObjectId(file_id)})
|
||||
|
||||
def insert_song(self, song_obj):
|
||||
self.collection.update(
|
||||
{'filepath': song_obj['filepath']}, song_obj, upsert=True)
|
||||
self.collection.update_one(
|
||||
{'filepath': song_obj['filepath']}, { "$set": song_obj}, upsert=True)
|
||||
# self.collection.insert_one(song_obj)
|
||||
|
||||
def find_song_by_title(self, query):
|
||||
self.collection.create_index([('title', pymongo.TEXT)])
|
||||
|
||||
Reference in New Issue
Block a user