Compare commits
	
		
			No commits in common. "47e8b0d11adc9286ed400eac62230d334657802f" and "3bf2ad38c21b0f0ead083776d5083f39cbfea4b8" have entirely different histories.
		
	
	
		
			47e8b0d11a
			...
			3bf2ad38c2
		
	
		
							
								
								
									
										1
									
								
								src/music/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								src/music/__init__.py
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1 @@
 | 
				
			||||||
 | 
					from .track import Track
 | 
				
			||||||
| 
						 | 
					@ -5,9 +5,6 @@ class Track:
 | 
				
			||||||
    def __init__(self, location: Path):
 | 
					    def __init__(self, location: Path):
 | 
				
			||||||
        self.path = location
 | 
					        self.path = location
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __str__(self):
 | 
					 | 
				
			||||||
        return str(self.path)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @property
 | 
					    @property
 | 
				
			||||||
    def filename(self) -> str:
 | 
					    def filename(self) -> str:
 | 
				
			||||||
        return self.path.name
 | 
					        return self.path.name
 | 
				
			||||||
| 
						 | 
					@ -1,2 +1 @@
 | 
				
			||||||
from .track import Track
 | 
					 | 
				
			||||||
from .transcoder import Transcoder
 | 
					from .transcoder import Transcoder
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,7 +2,6 @@ from pathlib import Path
 | 
				
			||||||
import shutil
 | 
					import shutil
 | 
				
			||||||
import subprocess
 | 
					import subprocess
 | 
				
			||||||
from multiprocessing import Pool
 | 
					from multiprocessing import Pool
 | 
				
			||||||
from . import Track
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Transcoder:
 | 
					class Transcoder:
 | 
				
			||||||
| 
						 | 
					@ -30,18 +29,17 @@ class Transcoder:
 | 
				
			||||||
                            self.copy_album_art(album, album_out)
 | 
					                            self.copy_album_art(album, album_out)
 | 
				
			||||||
                            for file in album.iterdir():
 | 
					                            for file in album.iterdir():
 | 
				
			||||||
                                if file.is_file() and file.suffix.lower() == '.flac':
 | 
					                                if file.is_file() and file.suffix.lower() == '.flac':
 | 
				
			||||||
                                    transcode_list.append(Track(file))
 | 
					                                    transcode_list.append((str(file), str(album_out / f"{file.stem}.{self.extension}")))
 | 
				
			||||||
                    else:
 | 
					                    else:
 | 
				
			||||||
                        print(f"Warning, skipping non-dir '{album}' found in artist '{artist.parts[-1]}'")
 | 
					                        print(f"Warning, skipping non-dir '{album}' found in artist '{artist.parts[-1]}'")
 | 
				
			||||||
                        continue
 | 
					                        continue
 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
                print(f"Warning, skipping non-dir '{artist}' found in root")
 | 
					                print(f"Warning, skipping non-dir '{artist}' found in root")
 | 
				
			||||||
                continue
 | 
					                continue
 | 
				
			||||||
        self._transcode_single_thread(transcode_list, self.encoder)
 | 
					        self._transcode(transcode_list, self.encoder)
 | 
				
			||||||
        #self._transcode(transcode_list, self.encoder)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _transcode(self, transcode_list: list, encoder: Path, workers=16):
 | 
					    def _transcode(self, transcode_list: list, encoder: Path, workers=16):
 | 
				
			||||||
        worker_args = [(track, encoder) for track in transcode_list]
 | 
					        worker_args = [(row[0], row[1], encoder) for row in transcode_list]
 | 
				
			||||||
        with Pool(workers) as p:
 | 
					        with Pool(workers) as p:
 | 
				
			||||||
            results = p.starmap_async(self.transcode_worker, worker_args)
 | 
					            results = p.starmap_async(self.transcode_worker, worker_args)
 | 
				
			||||||
            p.close()
 | 
					            p.close()
 | 
				
			||||||
| 
						 | 
					@ -50,26 +48,25 @@ class Transcoder:
 | 
				
			||||||
                print(result)
 | 
					                print(result)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _transcode_single_thread(self, transcode_list: list, encoder: Path):
 | 
					    def _transcode_single_thread(self, transcode_list: list, encoder: Path):
 | 
				
			||||||
        worker_args = [(track, encoder) for track in transcode_list]
 | 
					        worker_args = [(row[0], row[1], encoder) for row in transcode_list]
 | 
				
			||||||
        for args in worker_args:
 | 
					        for args in worker_args:
 | 
				
			||||||
            print(f"{args[0]}")
 | 
					            print(f"{args[0]}")
 | 
				
			||||||
            self.transcode_worker(*args)
 | 
					            self.transcode_worker(*args)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def transcode_worker(self, track, encoder):
 | 
					    def transcode_worker(self, in_track, out_track, encoder):
 | 
				
			||||||
        enc_filename = encoder.parts[-1]
 | 
					        enc_filename = encoder.parts[-1]
 | 
				
			||||||
        track_output = track.output_file(self.output_root, self.extension)
 | 
					 | 
				
			||||||
        if enc_filename == "opusenc.exe":
 | 
					        if enc_filename == "opusenc.exe":
 | 
				
			||||||
            additional_args = ('--bitrate', '128', '--music')
 | 
					            additional_args = ('--bitrate', '128', '--music')
 | 
				
			||||||
            subprocess_args = (str(encoder),) + additional_args + (str(track.path), str(track_output))
 | 
					            subprocess_args = (str(encoder),) + additional_args + (in_track, out_track)
 | 
				
			||||||
        elif enc_filename == "qaac64.exe":
 | 
					        elif enc_filename == "qaac64.exe":
 | 
				
			||||||
            additional_args = (str(track), '-o', str(track_output), '--threading')
 | 
					            additional_args = (in_track, '-o', out_track, '--threading')
 | 
				
			||||||
            subprocess_args = (str(encoder),) + additional_args
 | 
					            subprocess_args = (str(encoder),) + additional_args
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            subprocess.run(subprocess_args, capture_output=True, text=True, check=True)
 | 
					            subprocess.run(subprocess_args, capture_output=True, text=True, check=True)
 | 
				
			||||||
            return f"Transcoded '{track}' successfully."
 | 
					            return f"Transcoded '{in_track}' successfully."
 | 
				
			||||||
        except Exception:
 | 
					        except Exception:
 | 
				
			||||||
            return f"ERROR: Transcoding of '{track}' failed."
 | 
					            return f"ERROR: Transcoding of '{in_track}' failed."
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @staticmethod
 | 
					    @staticmethod
 | 
				
			||||||
    def copy_album_art(in_dir: Path, out_dir: Path, file_whitelist: list = None):
 | 
					    def copy_album_art(in_dir: Path, out_dir: Path, file_whitelist: list = None):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user