From a957efcca5a223efc597f55007e631aeb7c8854e Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Fri, 4 Jun 2021 16:27:03 +0800 Subject: [PATCH] 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. --- bin/split-album | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/bin/split-album b/bin/split-album index b361c19..6616784 100755 --- a/bin/split-album +++ b/bin/split-album @@ -112,36 +112,36 @@ while test $len(ARGV) -gt 0 { exit ;; --audio-file) - set audio_file = ARGV[2] + setvar audio_file = ARGV[1] shift 2 ;; --timestamp-file) - set timestamp_file = ARGV[2] + setvar timestamp_file = ARGV[1] shift 2 ;; -a|--author) - set author = ARGV[2] + setvar author = ARGV[1] shift 2 ;; -d|--date) - set pub_date = ARGV[2] + setvar pub_date = ARGV[1] shift 2 ;; -t|--title) - set album = ARGV[2] + setvar album = ARGV[1] shift 2 ;; --strict) - set strict_mode = true + setvar strict_mode = true shift ;; --json) - set prints_json = true + setvar prints_json = true shift ;; *) - set audio_file = ARGV[1] - set timestamp_file = ARGV[2] + setvar audio_file = ARGV[0] + setvar timestamp_file = ARGV[1] shift 2 ;; } @@ -151,7 +151,7 @@ proc warnf(msg, @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 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 const output_data = {} -set output_data['file'] = $audio_file -set output_data['chapters'] = [] -set output_data['album'] = $album -set output_data['author'] = $author -set output_data['date'] = $pub_date -set output_data['extension'] = $EXTENSION +setvar output_data['file'] = $audio_file +setvar output_data['chapters'] = [] +setvar output_data['album'] = $album +setvar output_data['author'] = $author +setvar output_data['date'] = $pub_date +setvar output_data['extension'] = $EXTENSION const timestamp_regex = / %start digit{2,} ':' digit{2} ':' digit{2} <'.' digit+>? %end / var has_error = false @@ -187,20 +187,20 @@ var has_error = false case $(file --mime-type --brief $timestamp_file) { "application/json") 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. # I just want to improve the timestamp format (a little bit). "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 = {} - set chapter['title'] = $(write -- $_line | cut -d' ' -f2-) - set chapter['timestamp'] = $(write -- $_line | cut -d' ' -f1) + setvar chapter['title'] = $(write -- $_line | cut -d' ' -f2-) + setvar chapter['timestamp'] = $(write -- $_line | cut -d' ' -f1) write -- ${chapter['timestamp']} | rg --quiet $timestamp_regex || { warnf "'%s' %s is not a valid timestamp" ${chapter['timestamp']} ${chapter['title']} - set has_error = true + setvar has_error = true continue } @@ -212,17 +212,17 @@ case $(file --mime-type --brief $timestamp_file) { if (strict_mode and has_error) { exit 1 } const title_slug = $(kebab-case $album) -set output_data['directory'] = title_slug +setvar output_data['directory'] = title_slug mkdir -p $title_slug const chapter_len = len(output_data['chapters']) 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 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) - 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']} if (Int(index) != chapter_len) {