From 9123e50276ac73c4b127377559dc2181a1fd7081 Mon Sep 17 00:00:00 2001 From: Micyp Date: Sun, 18 Jul 2021 20:36:33 +0200 Subject: [PATCH] Add script: get_album_length --- get_album_length | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 get_album_length diff --git a/get_album_length b/get_album_length new file mode 100755 index 0000000..8dc7af1 --- /dev/null +++ b/get_album_length @@ -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 + + + +