Compare commits
No commits in common. "master" and "v0.2.0" have entirely different histories.
3 changed files with 8 additions and 42 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +0,0 @@
|
||||||
__pycache__
|
|
43
unmix.py
43
unmix.py
|
@ -2,7 +2,6 @@
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
import json
|
|
||||||
import os
|
import os
|
||||||
import over
|
import over
|
||||||
import re
|
import re
|
||||||
|
@ -46,19 +45,6 @@ def detect_silence(path, min_length_s=2, level_dB=-32):
|
||||||
|
|
||||||
return starts
|
return starts
|
||||||
|
|
||||||
def get_duration(path):
|
|
||||||
"""
|
|
||||||
Returns the duration of the media file pointed to by path.
|
|
||||||
"""
|
|
||||||
|
|
||||||
cmd = over.cmd.Command("ffprobe", "-v", "quiet", "-print_format", "json", "-show_format", "INFILE")
|
|
||||||
cmd.INFILE = "file:" + path
|
|
||||||
cmd.run()
|
|
||||||
raw = cmd.get_all_output().decode("utf-8")
|
|
||||||
dic = json.loads(raw)
|
|
||||||
|
|
||||||
return float(dic["format"]["duration"])
|
|
||||||
|
|
||||||
def floats(*args):
|
def floats(*args):
|
||||||
for arg in args:
|
for arg in args:
|
||||||
yield float(arg)
|
yield float(arg)
|
||||||
|
@ -146,7 +132,7 @@ if __name__ == "__main__":
|
||||||
main.add_option("track-name", "Track name format.", str, ["%n %a - %t.opus"], abbr="t")
|
main.add_option("track-name", "Track name format.", str, ["%n %a - %t.opus"], abbr="t")
|
||||||
main.add_option("verbose", "Print playlist lines as they are being parsed to stderr.", bool, [False], abbr="v")
|
main.add_option("verbose", "Print playlist lines as they are being parsed to stderr.", bool, [False], abbr="v")
|
||||||
main.add_doc("Description", ["Takes a playlist and turns it into a shell script that splits a large mix into individual audio files."])
|
main.add_doc("Description", ["Takes a playlist and turns it into a shell script that splits a large mix into individual audio files."])
|
||||||
main.add_doc("Playlist", ["Empty lines and those starting with # are ignored. Each line represents a track. The format is: START [DURATION] ARTIST TITLE. Fields are tab-separated."])
|
main.add_doc("Playlist", ["Empty lines and those starting with # are ignored. Each line represents a track. The format is: START DURATION ARTIST TITLE. Fields are tab-separated."])
|
||||||
main.setup()
|
main.setup()
|
||||||
|
|
||||||
## Sanity checks
|
## Sanity checks
|
||||||
|
@ -180,8 +166,6 @@ if __name__ == "__main__":
|
||||||
n += 1
|
n += 1
|
||||||
|
|
||||||
elif main.cfg.playlist:
|
elif main.cfg.playlist:
|
||||||
previous_track = None
|
|
||||||
|
|
||||||
with open(main.cfg.playlist) as f:
|
with open(main.cfg.playlist) as f:
|
||||||
n = 1
|
n = 1
|
||||||
|
|
||||||
|
@ -191,37 +175,20 @@ if __name__ == "__main__":
|
||||||
if not line or line[0] == "#":
|
if not line or line[0] == "#":
|
||||||
continue
|
continue
|
||||||
|
|
||||||
cols = line.split("\t")
|
start_s, duration_s, artist, title = line.split("\t")
|
||||||
|
start = sanitize_timestamp(start_s)
|
||||||
if len(cols) == 3:
|
|
||||||
start_s, artist, title = cols
|
|
||||||
duration = None
|
|
||||||
else:
|
|
||||||
start_s, duration_s, artist, title = cols
|
|
||||||
duration = sanitize_timestamp(duration_s)
|
duration = sanitize_timestamp(duration_s)
|
||||||
|
|
||||||
start = sanitize_timestamp(start_s)
|
tracks.append(Track(
|
||||||
|
|
||||||
track = Track(
|
|
||||||
start = start,
|
start = start,
|
||||||
duration = duration,
|
duration = duration,
|
||||||
number = n,
|
number = n,
|
||||||
artist = artist.strip(),
|
artist = artist.strip(),
|
||||||
title = title.strip()
|
title = title.strip()
|
||||||
)
|
))
|
||||||
|
|
||||||
tracks.append(track)
|
|
||||||
|
|
||||||
if previous_track and previous_track.duration is None:
|
|
||||||
previous_track.duration = track.start - previous_track.start
|
|
||||||
|
|
||||||
previous_track = track
|
|
||||||
n += 1
|
n += 1
|
||||||
|
|
||||||
# if unset, set the last track's duration to the end of file
|
|
||||||
if tracks[-1].duration is None:
|
|
||||||
tracks[-1].duration = get_duration(main.cfg.path) - tracks[-1].start
|
|
||||||
|
|
||||||
## apply global overrides
|
## apply global overrides
|
||||||
##
|
##
|
||||||
if main.cfg.artist:
|
if main.cfg.artist:
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
|
|
||||||
major = 0 # VERSION_MAJOR_IDENTIFIER
|
major = 0 # VERSION_MAJOR_IDENTIFIER
|
||||||
minor = 3 # VERSION_MINOR_IDENTIFIER
|
minor = 2 # VERSION_MINOR_IDENTIFIER
|
||||||
# VERSION_LAST_MM 0.3
|
# VERSION_LAST_MM 0.2
|
||||||
patch = 0 # VERSION_PATCH_IDENTIFIER
|
patch = 0 # VERSION_PATCH_IDENTIFIER
|
||||||
str = "0.3.0" # VERSION_STRING_IDENTIFIER
|
str = "0.2.0" # VERSION_STRING_IDENTIFIER
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue