sya

split youtube audio tracks, with an optional pyqt gui
git clone git://src.gearsix.net/sya
Log | Files | Refs | Atom | README

commit 59a6d1db9e0439c5ae396fc999807827c65e92a1
parent 469cfc80b647f86b2acfa17ccf5804d113f6bc17
Author: gearsix <gearsix@tuta.io>
Date:   Wed,  5 May 2021 17:27:21 +0100

improved timestamp regex; entire line is searched for timestamp

Diffstat:
MTODO | 2+-
Msya.py | 18+++++++++++-------
2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/TODO b/TODO @@ -13,7 +13,7 @@ [ ] user install - installs ffmpeg/youtube-dl if not found ? - just use corresponding python libaries -[ ] detect timestamp anywhere in line (not just at start) +[*] detect timestamp anywhere in line (not just at start) [x] detect tracks from missing timestamps - Could be done using: _ffmpeg -i audio.mp3 -af silencedetect=d=0.5 -f null -_ but finding the right parameters for the silencedetect filter (see _man ffmpeg-filters) diff --git a/sya.py b/sya.py @@ -5,7 +5,7 @@ import subprocess import re import os -Timestamp = re.compile(':?\d\d') +Timestamp = re.compile('(:?\d{1,2}){3}') class TracklistItem: def __init__(self, timestamp, title): @@ -64,9 +64,15 @@ def load_tracklist(path): def parse_tracks(tracklist): tracks = [] for lcount, line in enumerate(tracklist): - sline = line.split(' ', maxsplit=1) - if Timestamp.match(sline[0]): - tracks.append(TracklistItem(sline[0], sline[1].strip())) + sline = line.split(' ') + timestamp = sline[0] + for l in sline: # check line in case timestamp is in another element + if Timestamp.match(l): + timestamp = l + sline.remove(l) + title = ' '.join(sline).strip() + if Timestamp.match(timestamp): + tracks.append(TracklistItem(timestamp, title)) else: print('missing timestamp: ', line) return tracks @@ -82,10 +88,8 @@ def split_tracks(ffmpeg, audio_fpath, tracks, outpath): cmd = ['ffmpeg', '-v', 'quiet', '-stats', '-i', 'audio.mp3', '-f', 'null', '-'] ret = subprocess.run(cmd, stderr=subprocess.PIPE) - # do some nasty string manip. to extract length printed to stderr length = str(ret.stderr).split('\\r') - print(len(length)) - print(length[len(length)-1]) + # some nasty string manip. to extract length (printed to stderr) length = length[len(length)-1].split(' ')[1].split('=')[1][:-3] for i, t in enumerate(tracks):