ptgdp: Save and resolve file extensions

This should make mpd a lot more jumpy
This commit is contained in:
Salt 2019-08-13 04:00:52 -05:00
parent ee2d882d39
commit 92b5c86d71

17
ptgdp
View File

@ -6,10 +6,6 @@
# Distributed under terms of the MIT license.
#
# TODO:
# * Provide integration with other players, like mpd
# * Add a quick way to append to a playlist
# Variables
_name="$(basename -- "$0")"
_tmpdir="${XDG_CACHE_HOME:-$HOME/.cache}/$_name"
@ -48,6 +44,14 @@ notify() {
"$1" \
"$2" > /dev/null 2>&1
}
checkforsong() {
# $1: A song name to validate
[ -z "$1" ] && return 1
# Very rudimentary implementation
# TODO: Make this a lot more thorough, maybe ensure MIME is good
[ -f "$_musicdir/$1.*" ] && return 0
[ -f "$_musicdir/$1" ]
}
validatedeps() {
# $@: Dependencies to validate
for prog in "$@"; do
@ -160,7 +164,7 @@ playlist() {
sanitize "$line"
filename="$_musicdir/$_return"
if [ -z "$_optdryrun" ]; then
if ! [ -f "$filename" ]; then
if ! checkforsong "$_return"; then
log "Finding a song for \"$line\""
youtube-dl \
--add-metadata \
@ -173,7 +177,8 @@ playlist() {
> /dev/null 2>&1 &
if wait $!; then
dlsuccess+=1
mv "$_tmpfile"* "$filename"
local extension="${_tmpfile##*.}"
mv "$_tmpfile"* "$filename.$extension"
else
dlfailure+=1
notify "Could not download song" \