mirror of
https://github.com/foo-dogsquared/dotfiles.git
synced 2025-02-12 06:18:59 +00:00
Update 'split-album' script to oil >0.8.9
The `set` variable has been removed. Now, `setvar` is the preferred way to mutate the variable.
This commit is contained in:
parent
c3c29df603
commit
a957efcca5
@ -112,36 +112,36 @@ while test $len(ARGV) -gt 0 {
|
|||||||
exit
|
exit
|
||||||
;;
|
;;
|
||||||
--audio-file)
|
--audio-file)
|
||||||
set audio_file = ARGV[2]
|
setvar audio_file = ARGV[1]
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
--timestamp-file)
|
--timestamp-file)
|
||||||
set timestamp_file = ARGV[2]
|
setvar timestamp_file = ARGV[1]
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
-a|--author)
|
-a|--author)
|
||||||
set author = ARGV[2]
|
setvar author = ARGV[1]
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
-d|--date)
|
-d|--date)
|
||||||
set pub_date = ARGV[2]
|
setvar pub_date = ARGV[1]
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
-t|--title)
|
-t|--title)
|
||||||
set album = ARGV[2]
|
setvar album = ARGV[1]
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
--strict)
|
--strict)
|
||||||
set strict_mode = true
|
setvar strict_mode = true
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--json)
|
--json)
|
||||||
set prints_json = true
|
setvar prints_json = true
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
set audio_file = ARGV[1]
|
setvar audio_file = ARGV[0]
|
||||||
set timestamp_file = ARGV[2]
|
setvar timestamp_file = ARGV[1]
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
}
|
}
|
||||||
@ -151,7 +151,7 @@ proc warnf(msg, @args) {
|
|||||||
>&2 printf "${msg}\\n" @args
|
>&2 printf "${msg}\\n" @args
|
||||||
}
|
}
|
||||||
|
|
||||||
proc errorf(msg, @args, exit_code = 1) {
|
proc errorf(msg, exit_code = 1, @args) {
|
||||||
>&2 printf "${msg}\\n" @args
|
>&2 printf "${msg}\\n" @args
|
||||||
exit ${exit_code}
|
exit ${exit_code}
|
||||||
}
|
}
|
||||||
@ -174,12 +174,12 @@ test $author || prompt "Who is the author of the album?" :author
|
|||||||
test $pub_date || prompt "When is the album published?" :pub_date
|
test $pub_date || prompt "When is the album published?" :pub_date
|
||||||
|
|
||||||
const output_data = {}
|
const output_data = {}
|
||||||
set output_data['file'] = $audio_file
|
setvar output_data['file'] = $audio_file
|
||||||
set output_data['chapters'] = []
|
setvar output_data['chapters'] = []
|
||||||
set output_data['album'] = $album
|
setvar output_data['album'] = $album
|
||||||
set output_data['author'] = $author
|
setvar output_data['author'] = $author
|
||||||
set output_data['date'] = $pub_date
|
setvar output_data['date'] = $pub_date
|
||||||
set output_data['extension'] = $EXTENSION
|
setvar output_data['extension'] = $EXTENSION
|
||||||
|
|
||||||
const timestamp_regex = / %start digit{2,} ':' digit{2} ':' digit{2} <'.' digit+>? %end /
|
const timestamp_regex = / %start digit{2,} ':' digit{2} ':' digit{2} <'.' digit+>? %end /
|
||||||
var has_error = false
|
var has_error = false
|
||||||
@ -187,20 +187,20 @@ var has_error = false
|
|||||||
case $(file --mime-type --brief $timestamp_file) {
|
case $(file --mime-type --brief $timestamp_file) {
|
||||||
"application/json")
|
"application/json")
|
||||||
json read :chapters < $timestamp_file
|
json read :chapters < $timestamp_file
|
||||||
set output_data['chapters'] = chapters
|
setvar output_data['chapters'] = chapters
|
||||||
;;
|
;;
|
||||||
|
|
||||||
# Also cleans up the timestamp file with comments and empty lines.
|
# Also cleans up the timestamp file with comments and empty lines.
|
||||||
# I just want to improve the timestamp format (a little bit).
|
# I just want to improve the timestamp format (a little bit).
|
||||||
"text/plain")
|
"text/plain")
|
||||||
sed --file $timestamp_file --regexp-extended --expression '/^\s*$/d' --expression '/^#/d' | while read --line {
|
sed --regexp-extended --expression '/^\s*$/d' --expression '/^#/d' $timestamp_file | while read --line {
|
||||||
var chapter = {}
|
var chapter = {}
|
||||||
set chapter['title'] = $(write -- $_line | cut -d' ' -f2-)
|
setvar chapter['title'] = $(write -- $_line | cut -d' ' -f2-)
|
||||||
set chapter['timestamp'] = $(write -- $_line | cut -d' ' -f1)
|
setvar chapter['timestamp'] = $(write -- $_line | cut -d' ' -f1)
|
||||||
|
|
||||||
write -- ${chapter['timestamp']} | rg --quiet $timestamp_regex || {
|
write -- ${chapter['timestamp']} | rg --quiet $timestamp_regex || {
|
||||||
warnf "'%s' %s is not a valid timestamp" ${chapter['timestamp']} ${chapter['title']}
|
warnf "'%s' %s is not a valid timestamp" ${chapter['timestamp']} ${chapter['title']}
|
||||||
set has_error = true
|
setvar has_error = true
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,17 +212,17 @@ case $(file --mime-type --brief $timestamp_file) {
|
|||||||
if (strict_mode and has_error) { exit 1 }
|
if (strict_mode and has_error) { exit 1 }
|
||||||
|
|
||||||
const title_slug = $(kebab-case $album)
|
const title_slug = $(kebab-case $album)
|
||||||
set output_data['directory'] = title_slug
|
setvar output_data['directory'] = title_slug
|
||||||
mkdir -p $title_slug
|
mkdir -p $title_slug
|
||||||
|
|
||||||
const chapter_len = len(output_data['chapters'])
|
const chapter_len = len(output_data['chapters'])
|
||||||
|
|
||||||
for index in @(seq $[chapter_len]) {
|
for index in @(seq $[chapter_len]) {
|
||||||
set chapter = output_data['chapters'][Int(index) - 1]
|
setvar chapter = output_data['chapters'][Int(index) - 1]
|
||||||
var start = chapter['timestamp']
|
var start = chapter['timestamp']
|
||||||
var end = output_data['chapters'][Int(index)]['timestamp'] if Int(index) != chapter_len else null
|
var end = output_data['chapters'][Int(index)]['timestamp'] if Int(index) != chapter_len else null
|
||||||
var filename = $(printf "%.2d-%s.%s" $index $(kebab-case ${chapter['title']}) $EXTENSION)
|
var filename = $(printf "%.2d-%s.%s" $index $(kebab-case ${chapter['title']}) $EXTENSION)
|
||||||
set output_data['chapters'][Int(index) - 1]['file'] = filename
|
setvar output_data['chapters'][Int(index) - 1]['file'] = filename
|
||||||
|
|
||||||
warnf "[%d/%d] %s" ${index} ${chapter_len} ${chapter['title']}
|
warnf "[%d/%d] %s" ${index} ${chapter_len} ${chapter['title']}
|
||||||
if (Int(index) != chapter_len) {
|
if (Int(index) != chapter_len) {
|
||||||
|
Loading…
Reference in New Issue
Block a user