diff options
| author | Akshay Nair <phenax5@gmail.com> | 2020-12-24 00:06:27 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2020-12-24 00:06:27 +0530 |
| commit | 865728068c965e066d0f8971c5b5ba26e12e7dce (patch) | |
| tree | c16195f0a04cf7d004fe5b396255734f4d60bb00 /scripts/music | |
| parent | 649ef5f225039e498358c3d056dfd7fcbc56f014 (diff) | |
| download | nixos-config-865728068c965e066d0f8971c5b5ba26e12e7dce.tar.gz nixos-config-865728068c965e066d0f8971c5b5ba26e12e7dce.zip | |
Adds scripts and links scripts and wallpapers
Diffstat (limited to 'scripts/music')
| -rwxr-xr-x | scripts/music/player.sh | 56 | ||||
| -rwxr-xr-x | scripts/music/split-album.sh | 72 | ||||
| -rwxr-xr-x | scripts/music/tag-bulk.sh | 26 | ||||
| -rwxr-xr-x | scripts/music/tag.sh | 59 |
4 files changed, 213 insertions, 0 deletions
diff --git a/scripts/music/player.sh b/scripts/music/player.sh new file mode 100755 index 0000000..76f4988 --- /dev/null +++ b/scripts/music/player.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +player() { playerctl --player=mopidy "$@"; } + +# Get player state +#get_play_state() { player metadata --format '{{status}}' || echo 'Stopped'; } +get_play_state() { + local state=$(mpc status | awk '/\[\w*\]/ {print $1}'); + case "$state" in + '[playing]') echo "Playing" ;; + '[paused]') echo "Paused" ;; + *) echo "Stopped" ;; + esac; +} + +# Get title - artist (song label) +#get_label() { player metadata --format '{{title}} - {{artist}}' || echo '...'; } +get_label() { + echo -n "$(mpc current | cut -c1-20)"; + echo "..."; +} + +# Play/Pause toggle: +play_pause() { + #player play-pause; + mpc toggle; + update-dwmblock music; +} + +# Next/Prev +next() { + #player next; + mpc next; + update-dwmblock music; +} +prev() { + #player previous; + mpc prev; + update-dwmblock music; +} + +notify() { + update-dwmblock music; +} + +case "$1" in + play_pause|pp) play_pause ;; + next|n) next ;; + prev|p) prev ;; + dump_metadata) get_metadata ;; + get_label) get_label ;; + get_play_state) get_play_state ;; + notify) notify ;; + *) echo "Learn how to use shit before you use them" ;; +esac + diff --git a/scripts/music/split-album.sh b/scripts/music/split-album.sh new file mode 100755 index 0000000..d7a23a4 --- /dev/null +++ b/scripts/music/split-album.sh @@ -0,0 +1,72 @@ +#!/usr/bin/env bash + +MUSIC_DIR="$HOME/Downloads/music"; +EXT=opus; + +AUDIO_FILE="$1"; +TIMESTAMPS_FILE="$2"; + +ALBUM_ARTIST=$(echo "$TIMESTAMPS_FILE" | sed -e 's/^.*\///g' -e 's/\.splits$//'); + +ARTIST="$(echo $ALBUM_ARTIST | awk -F' - ' '{print $1}')"; +ALBUM="$(echo $ALBUM_ARTIST | awk -F' - ' '{print $2}')"; + +OUT_DIR="$MUSIC_DIR/$ARTIST/$ALBUM"; +[[ ! -d "$OUT_DIR" ]] && mkdir -p "$OUT_DIR"; + +AUDIOINFO=$(mediainfo "$AUDIO_FILE" --Output=JSON); +DURATION=$(echo -e "$AUDIOINFO" | jq -r '.media.track[0].Duration'); + +TOTAL_TRACKS=$(cat "$TIMESTAMPS_FILE" | wc -l); + +add_tags() { ~/scripts/music/tag.sh "$@"; } + +padd() { printf "%0${2:-2}d" $(echo $1 | cut -d'.' -f1); } + +to_timestamp() { + local duration=$1; + local hours=$(echo "$duration / 3600" | bc); + duration=$(echo "$duration % 3600" | bc); + local mins=$(echo "$duration / 60" | bc); + local secs=$(echo "$duration % 60" | bc); + echo "$(padd $hours):$(padd $mins):$(padd $secs)"; +} + +starttime=""; +music=""; +index=0; + +(cat "$TIMESTAMPS_FILE"; echo "<<END") | while read split; do + if [[ ! -z "$split" ]]; then + if [[ "$split" == "<<END" ]]; then + endtime=$(to_timestamp $DURATION); + else + endtime="$(echo $split | cut -d' ' -f1)"; + nextmusic="$(echo $split | cut -d' ' -f 2-)"; + fi; + + if [[ ! -z "$music" ]]; then + output="$OUT_DIR/$(padd $index) - $music.$EXT"; + echo "$starttime - $endtime ($output)"; + ffmpeg \ + -nostdin -y \ + -loglevel -8 \ + -i "$AUDIO_FILE" \ + -ss "$starttime" \ + -to "$endtime" \ + -vn "$output" && \ + add_tags \ + -a "$ARTIST" \ + -A "$ALBUM" \ + -t "$music" \ + -n "$music" \ + -N "$TOTAL_TRACKS" \ + "$output" \ + ; + fi; + + music=$nextmusic; + starttime=$endtime; + index=$((index + 1)); + fi; +done; diff --git a/scripts/music/tag-bulk.sh b/scripts/music/tag-bulk.sh new file mode 100755 index 0000000..bd93205 --- /dev/null +++ b/scripts/music/tag-bulk.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +artist=$1; +album=$2; + +ext=${3:-'opus'}; + +file=${4:-'taginfo'}; + +total=$(cat $file | wc -l); + +cat $file | while read n song; do + song_file="$song.$ext"; + if [[ -f "$song_file" ]]; then + ~/scripts/music/tag.sh \ + -a "$artist" \ + -A "$album" \ + -t "$song" \ + -n "$n" \ + -N "$total" \ + "$song_file"; + else + echo "File $song_file not found"; + fi; +done; + diff --git a/scripts/music/tag.sh b/scripts/music/tag.sh new file mode 100755 index 0000000..325dec3 --- /dev/null +++ b/scripts/music/tag.sh @@ -0,0 +1,59 @@ +#!/bin/sh + +err() { echo "Usage: + tag [OPTIONS] file +Options: + -a: artist + -t: song + -A: album + -n: track + -N: total number of tracks + -d: year of publication + -g: genre + -c: comment +You will be prompted for title, artist, album and track if not given." && exit 1 ;} + +while getopts "a:t:A:n:N:d:g:c:f:" o; do case "${o}" in + a) artist="${OPTARG}" ;; + t) title="${OPTARG}" ;; + A) album="${OPTARG}" ;; + n) track="${OPTARG}" ;; + N) total="${OPTARG}" ;; + d) date="${OPTARG}" ;; + g) genre="${OPTARG}" ;; + c) comment="${OPTARG}" ;; + f) file="${OPTARG}" ;; + *) printf "Invalid option: -%s\\n" "$OPTARG" && err ;; +esac; done; + +shift $((OPTIND - 1)); + +file="$1" + +[ ! -f "$file" ] && echo "Provide file to tag." && err + +[ -z "$title" ] && echo "Enter a title." && read -r title +[ -z "$artist" ] && echo "Enter an artist." && read -r artist +[ -z "$album" ] && echo "Enter an album." && read -r album +[ -z "$track" ] && echo "Enter a track number." && read -r track + +case "$file" in + *.ogg) echo "Title=$title +Artist=$artist +Album=$album +Track=$track +Total=$total +Date=$date +Genre=$genre +Comment=$comment" | vorbiscomment -w "$file" ;; + *.opus) echo "Title=$title +Artist=$artist +Album=$album +Track=$track +Total=$total +Date=$date +Genre=$genre +Comment=$comment" | opustags -i -S "$file" ;; + *.mp3) eyeD3 -Q --remove-all -a "$artist" -A "$album" -t "$title" -n "$track" -N "$total" -Y "$date" "$file" ;; + *) echo "File type not implemented yet." ;; +esac |
