commit bba59c14c5fbbcd24788d5376207b87b95205b6a
parent eb09074d145a092ed3fd5450ecc45d3bdac938c6
Author: gearsix <gearsix@tuta.io>
Date: Thu, 3 Nov 2022 17:48:44 +0000
Minor adjustments: missing '-k' actually removes the downloaded file
- updated 'Be patient' message on GUI
- Moved some code about.
Diffstat:
M | sya-pyqt.py | | | 5 | ++--- |
M | sya.py | | | 59 | ++++++++++++++++++++++++++++++++--------------------------- |
2 files changed, 34 insertions(+), 30 deletions(-)
diff --git a/sya-pyqt.py b/sya-pyqt.py
@@ -24,8 +24,7 @@ def centerWidget(widget):
wg = widget.geometry()
return qtcore.QPoint(
round(sg.width() / 2) - round(wg.width() / 2),
- round(sg.height() / 2) - round(wg.height() / 2)
- )
+ round(sg.height() / 2) - round(wg.height() / 2))
class LogStream(qtcore.QObject):
txt = qtcore.pyqtSignal(str)
@@ -118,7 +117,7 @@ class SyaGui(qtwidg.QMainWindow):
cancel_btn.clicked.connect(self.cancel)
layout.addWidget(cancel_btn, 2, 0)
# warning
- warning = qtwidg.QLabel('Be patient, this might take a while.')
+ warning = qtwidg.QLabel('Be patient, this might take a while. Click "Done" when finished.')
layout.addWidget(warning, 2, 1, 1, 2)
# done
self._done_btn = qtwidg.QPushButton('Done')
diff --git a/sya.py b/sya.py
@@ -14,46 +14,22 @@ class TracklistItem:
self.timestamp = timestamp
self.title = title
+# utilities
def log(msg):
- msg = 'sya: ' + msg
print(msg)
def error_exit(msg):
log('exit failure "{}"'.format(msg))
sys.exit()
-def parse_args():
- parser = argparse.ArgumentParser(
- description='download & split audio tracks long youtube videos')
- # arguments
- parser.add_argument('tracklist', metavar='TRACKLIST', nargs='?',
- help='tracklist to split audio by')
- # options
- parser.add_argument('-o', '--output', metavar='PATH', type=str, nargs='?',
- help='specify the directory to write output files to (default: ./out)')
- parser.add_argument('-f', '--format', type=str, nargs='?', default='mp3',
- help='specify the --audio-format argument to pass to yt-dlp (default: mp3)')
- parser.add_argument('-q', '--quality', type=str, nargs='?', default='320K',
- help='specify the --audio-quality argument to pass to yt-dlp (default: 320K)')
- parser.add_argument('--yt-dlp', metavar='PATH', type=str, nargs='?',
- default='yt-dlp', dest='youtubedl',
- help='path of the "yt-dlp" binary to use')
- parser.add_argument('--ffmpeg', metavar='PATH', type=str, nargs='?',
- default='ffmpeg', dest='ffmpeg',
- help='path of the "ffmpeg" binary to use')
- parser.add_argument('-k', '--keep', action='store_false',
- help='keep any files removed during processing (full video/audio file)')
- return parser.parse_args()
-
def check_bin(*binaries):
for b in binaries:
try:
subprocess.call([b], stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL)
except:
error_exit('failed to execute {}'.format(b))
- opy
-
+# functions
def get_audio(youtubedl, url, outdir, format='mp3', quality='320K', keep=True, ffmpeg='ffmpeg'):
log('{} getting {}, {} ({})'.format(youtubedl, format, quality, url))
fname = '{}/{}'.format(outdir, os.path.basename(outdir), format)
@@ -131,8 +107,32 @@ def split_tracks(ffmpeg, audio_fpath, tracks, format='mp3', outpath='out'):
log(line.decode('utf-8').rstrip('\n'))
return
+# runtime
+def parse_args():
+ parser = argparse.ArgumentParser(
+ description='download & split audio tracks long youtube videos')
+ # arguments
+ parser.add_argument('tracklist', metavar='TRACKLIST', nargs='?',
+ help='tracklist to split audio by')
+ # options
+ parser.add_argument('-o', '--output', metavar='PATH', type=str, nargs='?',
+ help='specify the directory to write output files to (default: ./out)')
+ parser.add_argument('-f', '--format', type=str, nargs='?', default='mp3',
+ help='specify the --audio-format argument to pass to yt-dlp (default: mp3)')
+ parser.add_argument('-q', '--quality', type=str, nargs='?', default='320K',
+ help='specify the --audio-quality argument to pass to yt-dlp (default: 320K)')
+ parser.add_argument('--yt-dlp', metavar='PATH', type=str, nargs='?',
+ default='yt-dlp', dest='youtubedl',
+ help='path of the "yt-dlp" binary to use')
+ parser.add_argument('--ffmpeg', metavar='PATH', type=str, nargs='?',
+ default='ffmpeg', dest='ffmpeg',
+ help='path of the "ffmpeg" binary to use')
+ parser.add_argument('-k', '--keep', action='store_true',
+ default=False,
+ help='keep any files removed during processing (full video/audio file)')
+ return parser.parse_args()
+
def sya(args):
- # validate args
if check_bin(args.youtubedl, args.ffmpeg) == False:
error_exit('required binaries are missing')
if args.tracklist == None or os.path.exists(args.tracklist) == False:
@@ -141,8 +141,10 @@ def sya(args):
args.output = os.path.splitext(args.tracklist)[0]
tracklist = load_tracklist(args.tracklist)
+
audio_fpath = get_audio(args.youtubedl, tracklist[0], args.output,
args.format, args.quality, args.keep, args.ffmpeg)
+
tracks = parse_tracks(tracklist[1:])
missing = missing_times(tracks)
@@ -152,5 +154,8 @@ def sya(args):
os.makedirs(args.output, exist_ok=True)
split_tracks(args.ffmpeg, audio_fpath, tracks, args.format, args.output)
+ if args.keep is False:
+ os.remove(audio_fpath)
+
if __name__ == '__main__':
sya(parse_args())