rewrite search functions as classes

This commit is contained in:
geoffrey45
2022-05-18 18:04:01 +03:00
parent 8405efede0
commit 4040b99518
9 changed files with 170 additions and 32 deletions
+25 -6
View File
@@ -1,6 +1,7 @@
from concurrent.futures import ThreadPoolExecutor
from multiprocessing import Pool
from copy import deepcopy
import os
from os import path
import time
from typing import List
@@ -46,7 +47,7 @@ class Populate:
def run(self):
self.check_untagged()
self.tag_all_files()
self.get_all_tags()
if len(self.tagged_tracks) == 0:
return
@@ -76,6 +77,17 @@ class Populate:
Log(f"Found {len(self.files)} untagged tracks")
def process_tags(self, tags: dict):
for t in tags:
if t is None:
continue
t["albumhash"] = create_album_hash(t["album"], t["albumartist"])
self.tagged_tracks.append(t)
api.DB_TRACKS.append(t)
self.folders.add(t["folder"])
def get_tags(self, file: str):
tags = get_tags(file)
@@ -87,15 +99,22 @@ class Populate:
self.tagged_tracks.append(tags)
api.DB_TRACKS.append(tags)
def tag_all_files(self):
def get_all_tags(self):
"""
Loops through all the untagged files and tags them.
"""
s = time.time()
print(f"Started tagging files")
with ThreadPoolExecutor() as executor:
executor.map(self.get_tags, self.files)
# print(f"Started tagging files")
# with ThreadPoolExecutor() as executor:
# executor.map(self.get_tags, self.files)
with Pool(maxtasksperchild=10) as p:
tags = p.map(get_tags, tqdm(self.files))
self.process_tags(tags)
# for t in tqdm(self.files):
# self.get_tags(t)
d = time.time() - s
Log(f"Tagged {len(self.tagged_tracks)} files in {d} seconds")