ptgdp: Save and resolve file extensions
This should make mpd a lot more jumpy
This commit is contained in:
parent
ee2d882d39
commit
92b5c86d71
17
ptgdp
17
ptgdp
@ -6,10 +6,6 @@
|
|||||||
# Distributed under terms of the MIT license.
|
# 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
|
# Variables
|
||||||
_name="$(basename -- "$0")"
|
_name="$(basename -- "$0")"
|
||||||
_tmpdir="${XDG_CACHE_HOME:-$HOME/.cache}/$_name"
|
_tmpdir="${XDG_CACHE_HOME:-$HOME/.cache}/$_name"
|
||||||
@ -48,6 +44,14 @@ notify() {
|
|||||||
"$1" \
|
"$1" \
|
||||||
"$2" > /dev/null 2>&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() {
|
validatedeps() {
|
||||||
# $@: Dependencies to validate
|
# $@: Dependencies to validate
|
||||||
for prog in "$@"; do
|
for prog in "$@"; do
|
||||||
@ -160,7 +164,7 @@ playlist() {
|
|||||||
sanitize "$line"
|
sanitize "$line"
|
||||||
filename="$_musicdir/$_return"
|
filename="$_musicdir/$_return"
|
||||||
if [ -z "$_optdryrun" ]; then
|
if [ -z "$_optdryrun" ]; then
|
||||||
if ! [ -f "$filename" ]; then
|
if ! checkforsong "$_return"; then
|
||||||
log "Finding a song for \"$line\""
|
log "Finding a song for \"$line\""
|
||||||
youtube-dl \
|
youtube-dl \
|
||||||
--add-metadata \
|
--add-metadata \
|
||||||
@ -173,7 +177,8 @@ playlist() {
|
|||||||
> /dev/null 2>&1 &
|
> /dev/null 2>&1 &
|
||||||
if wait $!; then
|
if wait $!; then
|
||||||
dlsuccess+=1
|
dlsuccess+=1
|
||||||
mv "$_tmpfile"* "$filename"
|
local extension="${_tmpfile##*.}"
|
||||||
|
mv "$_tmpfile"* "$filename.$extension"
|
||||||
else
|
else
|
||||||
dlfailure+=1
|
dlfailure+=1
|
||||||
notify "Could not download song" \
|
notify "Could not download song" \
|
||||||
|
Loading…
Reference in New Issue
Block a user