mirror of
https://github.com/rwinkhart/flac2pod.git
synced 2026-09-02 07:07:20 -04:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7db318b561 | ||
|
|
dee1c3158f | ||
|
|
d973a3f659 | ||
|
|
d00e516e6c | ||
|
|
ea485480c4 | ||
|
|
b56dd7e5f5 |
Executable → Regular
+36
-12
@@ -2,8 +2,11 @@
|
|||||||
|
|
||||||
# external modules
|
# external modules
|
||||||
|
|
||||||
from os import path, system, walk
|
from os import cpu_count, path, walk
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from sys import argv, exit as s_exit
|
||||||
|
from time import sleep
|
||||||
|
from subprocess import check_output, Popen
|
||||||
|
|
||||||
|
|
||||||
# utility functions
|
# utility functions
|
||||||
@@ -35,21 +38,42 @@ def create_destination():
|
|||||||
|
|
||||||
|
|
||||||
def scan_destination_convert_mp3():
|
def scan_destination_convert_mp3():
|
||||||
|
_i, _total_files = 0, len(source_directories)
|
||||||
for _file in source_directories[1]:
|
for _file in source_directories[1]:
|
||||||
if not Path(f"{_file.replace(path.expanduser(source), path.expanduser(destination))}.mp3").is_file():
|
if not Path(f"{_file.replace(path.expanduser(source), path.expanduser(destination))}.mp3").is_file():
|
||||||
_file_s = _file.replace(' ', '\\ ').replace("'", "\\'") + '.flac'
|
_file_s = _file.replace(' ', '\\ ').replace("'", "\\'").replace(')', '\\)').replace('(', '\\(').replace\
|
||||||
_file_d = _file.replace(path.expanduser(source),
|
('&', '\\&').replace('`', '\\`').replace('$', '\\$') + '.flac'
|
||||||
path.expanduser(destination)).replace(' ', '\\ ').replace("'", "\\'") + '.mp3'
|
_file_d = _file.replace(path.expanduser(source), path.expanduser(destination)).replace(' ', '\\ ')\
|
||||||
print(f"\n\u001b[38;5;0;48;5;15mConverting {_file_s} to {_file_d}...\u001b[0m\n")
|
.replace("'", "\\'").replace(')', '\\)').replace('(', '\\(').replace('&', '\\&')\
|
||||||
system(f"ffmpeg -i {_file_s} -c:v copy -ab 320k -map_metadata 0 -id3v2_version 3 {_file_d}")
|
.replace('`', '\\`').replace('$', '\\$') + '.mp3'
|
||||||
rg2sc(_file_d)
|
_active_processes = int(check_output('ps -C ffmpeg | wc -l', shell=True)) - 1
|
||||||
|
if _active_processes >= cpu_count():
|
||||||
|
while _active_processes >= cpu_count():
|
||||||
|
print(f"\nThere are already {cpu_count()} processes running...\n")
|
||||||
|
sleep(1)
|
||||||
|
_active_processes = int(check_output('ps -C ffmpeg | wc -l', shell=True)) - 1
|
||||||
|
_i += 1
|
||||||
|
_progress = _i / _total_files
|
||||||
|
print(f"\n{_progress}% | \u001b[38;5;0;48;5;15mConverting {_file_s} to {_file_d}...\u001b[0m\n")
|
||||||
|
if '-s' in arguments:
|
||||||
|
_cmd = f"screen -DmS flac2pod{_i} ffmpeg -i {_file_s} -map 0:a -ab 320k -map_metadata 0" \
|
||||||
|
f" -id3v2_version 3 {_file_d} </dev/null; rg2sc -f -s {_file_d}"
|
||||||
|
else:
|
||||||
|
_cmd = f"screen -DmS flac2pod{_i} ffmpeg -i {_file_s} -c:v copy -ab 320k -map_metadata 0" \
|
||||||
|
f" -id3v2_version 3 {_file_d} </dev/null; rg2sc -f {_file_d}"
|
||||||
|
Popen(_cmd, shell=True)
|
||||||
|
_active_processes = int(check_output('ps -C ffmpeg | wc -l', shell=True)) - 1
|
||||||
|
while _active_processes != 0:
|
||||||
|
print('\nPlease wait for the remaining conversions to complete...\n')
|
||||||
|
sleep(1)
|
||||||
|
_active_processes = int(check_output('ps -C ffmpeg | wc -l', shell=True)) - 1
|
||||||
|
sleep(1)
|
||||||
|
print('\niPod conversion complete!\n')
|
||||||
|
s_exit()
|
||||||
|
|
||||||
|
|
||||||
def rg2sc(_file):
|
# retrieve typed argument
|
||||||
system(f"rg2sc -f {_file}")
|
arguments = argv
|
||||||
|
|
||||||
|
|
||||||
# program start sequence
|
|
||||||
|
|
||||||
source = input('Source parent directory: ')
|
source = input('Source parent directory: ')
|
||||||
if source.endswith('/'):
|
if source.endswith('/'):
|
||||||
|
|||||||
Reference in New Issue
Block a user