Revise personal scripts again

This commit is contained in:
Gabriel Arazas 2021-04-30 22:21:11 +08:00
parent f3c4e2082d
commit 4d898c9116
2 changed files with 19 additions and 17 deletions

View File

@ -17,11 +17,11 @@ shopt -s strict:all
var FILENAME = $1 var FILENAME = $1
# Testing if the given file is a zip file. # Testing if the given file is a zip file.
file $FILENAME | rg "Zip archive data" --quiet || exit 1 file --mime $FILENAME | rg "application/zip" --quiet || exit 1
var channel_id_eggex = / 'https://www.youtube.com/channel/' (word) /
var NEWPIPE_DB = "newpipe.db" var NEWPIPE_DB = "newpipe.db"
var TEMP_FOLDER_NAME = "newpipe" var TEMP_FOLDER_NAME = "newpipe"
var channel_id_eggex = / 'https://www.youtube.com/channel/' (word) /
var NEWPIPE_DB_QUERY = "SELECT name, url, service_id, group_concat(tag, ',') AS tags FROM (SELECT subscriptions.name, subscriptions.url, subscriptions.service_id, '/' || feed_group.name AS tag var NEWPIPE_DB_QUERY = "SELECT name, url, service_id, group_concat(tag, ',') AS tags FROM (SELECT subscriptions.name, subscriptions.url, subscriptions.service_id, '/' || feed_group.name AS tag
FROM subscriptions FROM subscriptions
LEFT JOIN feed_group_subscription_join AS subs_join LEFT JOIN feed_group_subscription_join AS subs_join
@ -43,7 +43,7 @@ OPML
# Simply prints an `<outline>` element formatted approriately for the resulting output. # Simply prints an `<outline>` element formatted approriately for the resulting output.
# Don't mind how it is printed right now. :) # Don't mind how it is printed right now. :)
proc print-outline(title, xml_url, html_url, tags = "") { proc print-outline(title, xml_url, html_url, tags = "") {
printf ' <outline type="rss" xmlUrl="%s" htmlUrl="%s" title="%s"' $xml_url $html_url $title printf ' <outline type="rss" xmlUrl="%s" htmlUrl="%s" title="%s" text="%s"' $xml_url $html_url $title $title
if test -n $tags { if test -n $tags {
printf ' category="%s"' $tags printf ' category="%s"' $tags
@ -56,6 +56,7 @@ proc print-outline(title, xml_url, html_url, tags = "") {
# This only occurs if the given file does have a Newpipe database. # This only occurs if the given file does have a Newpipe database.
if unzip -l $FILENAME | rg --quiet $NEWPIPE_DB { if unzip -l $FILENAME | rg --quiet $NEWPIPE_DB {
mkdir $TEMP_FOLDER_NAME && unzip -q -u $FILENAME -d $TEMP_FOLDER_NAME mkdir $TEMP_FOLDER_NAME && unzip -q -u $FILENAME -d $TEMP_FOLDER_NAME
file --mime "${TEMP_FOLDER_NAME}/${NEWPIPE_DB}" | rg --quiet "application/x-sqlite3" || exit 1
trap "rm --recursive $TEMP_FOLDER_NAME" EXIT trap "rm --recursive $TEMP_FOLDER_NAME" EXIT
sqlite3 "${TEMP_FOLDER_NAME}/${NEWPIPE_DB}" "${NEWPIPE_DB_QUERY}" --csv --header \ sqlite3 "${TEMP_FOLDER_NAME}/${NEWPIPE_DB}" "${NEWPIPE_DB_QUERY}" --csv --header \
| dasel select --parser csv --multiple --selector '.[*]' --compact --write json \ | dasel select --parser csv --multiple --selector '.[*]' --compact --write json \

View File

@ -12,7 +12,7 @@ shopt --set strict:all
const show_help = "A small script for splitting files into tracks, perfect for full album releases and audiobooks. const show_help = "A small script for splitting files into tracks, perfect for full album releases and audiobooks.
split-album [options...] -tf \$TIMESTAMP_FILE -af \$ALBUM_FILE split-album [options...] [\$ALBUM_FILE \$TIMESTAMP_FILE]
Options: Options:
-h, --help Show the help section. -h, --help Show the help section.
@ -35,12 +35,11 @@ When any of the required metadata is missing (i.e., title, date, author), it wil
const show_descriptive_help = "This script splits an album with a timestamp file. const show_descriptive_help = "This script splits an album with a timestamp file.
You're always going to see using this script like the following: You're always going to see using this script like the following:
split-album -af \$AUDIO_FILE -tf \$TIMESTAMP_FILE split-album \$AUDIO_FILE \$TIMESTAMP_FILE
The timestamp file contains a starting timestamp (in HH:MM:SS[.MS]) and the title of the chapter/track. The timestamp file contains a starting timestamp (in HH:MM:SS[.MS]) and the title of the chapter/track.
For more information, see https://trac.ffmpeg.org/wiki/Seeking. For more information, see https://trac.ffmpeg.org/wiki/Seeking.
Lines starting with '#' and empty lines will be ignored. Lines starting with '#' and empty lines will be ignored.
It's for the best and you don't want some future migraines. :)
The following is an example of the content of a timestamp file. The following is an example of the content of a timestamp file.
@ -112,24 +111,24 @@ while test $len(ARGV) -gt 0 {
write -- $show_descriptive_help write -- $show_descriptive_help
exit exit
;; ;;
-af|--audio-file) --audio-file)
set audio_file = $2 set audio_file = ARGV[2]
shift 2 shift 2
;; ;;
-tf|--timestamp-file) --timestamp-file)
set timestamp_file = $2 set timestamp_file = ARGV[2]
shift 2 shift 2
;; ;;
-a|--author) -a|--author)
set author = $2 set author = ARGV[2]
shift 2 shift 2
;; ;;
-d|--date) -d|--date)
set pub_date = $2 set pub_date = ARGV[2]
shift 2 shift 2
;; ;;
-t|--title) -t|--title)
set album = $2 set album = ARGV[2]
shift 2 shift 2
;; ;;
--strict) --strict)
@ -141,7 +140,9 @@ while test $len(ARGV) -gt 0 {
shift shift
;; ;;
*) *)
shift set audio_file = ARGV[1]
set timestamp_file = ARGV[2]
shift 2
;; ;;
} }
} }
@ -150,9 +151,9 @@ proc warnf(msg, @args) {
>&2 printf "${msg}\\n" @args >&2 printf "${msg}\\n" @args
} }
proc errorf(msg, @args) { proc errorf(msg, @args, exit_code = 1) {
>&2 printf "${msg}\\n" @args >&2 printf "${msg}\\n" @args
exit 1 exit ${exit_code}
} }
proc prompt(msg, :out, prefix = ">> ") { proc prompt(msg, :out, prefix = ">> ") {
@ -192,7 +193,7 @@ case $(file --mime-type --brief $timestamp_file) {
# 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")
cat $timestamp_file | sed --regexp-extended --expression '/^\s*$/d' --expression '/^#/d' | while read --line { sed --file $timestamp_file --regexp-extended --expression '/^\s*$/d' --expression '/^#/d' | while read --line {
var chapter = {} var chapter = {}
set chapter['title'] = $(write -- $_line | cut -d' ' -f2-) set chapter['title'] = $(write -- $_line | cut -d' ' -f2-)
set chapter['timestamp'] = $(write -- $_line | cut -d' ' -f1) set chapter['timestamp'] = $(write -- $_line | cut -d' ' -f1)