Add script: get_album_length
This commit is contained in:
22
get_album_length
Executable file
22
get_album_length
Executable file
@@ -0,0 +1,22 @@
|
|||||||
|
#!/usr/bin/bash
|
||||||
|
|
||||||
|
if [[ -z $1 ]]; then
|
||||||
|
url=$(xclip -selection c -o)
|
||||||
|
>&2 echo "Reading url from clipboard: ${url}"
|
||||||
|
else
|
||||||
|
url=$1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! grep -qF 'bandcamp.com/album' <<<"$url"; then
|
||||||
|
>&2 echo "Input does not look like a bandcamp album URL"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
track_durations=$(curl "$url" 2>/dev/null | tidy 2>/dev/null | sed -n -E 's/^.*"time secondaryText">(.*)<\/span.*$/\1/p')
|
||||||
|
total_seconds=$( { printf '('; cut -d: -f1 <<<"$track_durations" | paste -d+ -s | tr -d '\n'; printf ') * 60 +'; cut -d: -f2 <<<"$track_durations" | paste -d+ -s; } | bc )
|
||||||
|
|
||||||
|
date -u -d @${total_seconds} +%T
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user