update music import
This commit is contained in:
7
private_dot_config/mpd/mpd.conf
Normal file
7
private_dot_config/mpd/mpd.conf
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
database {
|
||||||
|
plugin "simple"
|
||||||
|
path "$HOME/.local/share/mpd/db"
|
||||||
|
}
|
||||||
|
|
||||||
|
playlist_directory "$HOME/Music/Playlists"
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
DATA="$(cat "$1")"
|
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
DATA="$(cat "$1")"
|
||||||
|
|
||||||
. "$HOME/.local/share/music/common.sh"
|
. "$HOME/.local/share/music/common.sh"
|
||||||
|
|
||||||
function get_songs_from_playlists() {
|
function get_songs_from_playlists() {
|
||||||
@@ -63,6 +63,46 @@ function search_album_index() {
|
|||||||
echo "{\"title\":$name,\"artist\":$artist,\"index\":-1}"
|
echo "{\"title\":$name,\"artist\":$artist,\"index\":-1}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function apply_changes() {
|
||||||
|
local song="$1"
|
||||||
|
|
||||||
|
local genre="$(echo "$song" | jq -r '.genre')"
|
||||||
|
local pls="$(echo "$song" | jq -r '.playlist')"
|
||||||
|
pls="${pls^^}" # make uppercase
|
||||||
|
local like="$(echo "$song" | jq -r '.likeLevel')"
|
||||||
|
genre="$genre $pls L$like"
|
||||||
|
local block="$(echo "$song" | jq -r '.blockLevel')"
|
||||||
|
if [[ "$block" != "0" ]]
|
||||||
|
then
|
||||||
|
genre="$genre B$block"
|
||||||
|
fi
|
||||||
|
genre="$(echo "$genre" | sed -e 's/^ *//' -e 's/ *$//' -e 's/ / /g')"
|
||||||
|
|
||||||
|
echo "genre: '$genre'"
|
||||||
|
|
||||||
|
echo -n 'continue [y/N]: '
|
||||||
|
answer=""
|
||||||
|
read answer
|
||||||
|
if [[ "$answer" = "y" ]]
|
||||||
|
then
|
||||||
|
local format="$(echo "$song" | jq -r '.path.file' | sed 's/^.*\.\([^.]*\)$/\1/')"
|
||||||
|
case "$format" in
|
||||||
|
flac)
|
||||||
|
metaflac --remove-tag="GENRE" "$(echo "$song" | jq -r '.path.file')"
|
||||||
|
metaflac --set-tag="GENRE=$genre" "$(echo "$song" | jq -r '.path.file')"
|
||||||
|
;;
|
||||||
|
mp3)
|
||||||
|
id3v2 --genre "$genre" "$(echo "$song" | jq -r '.path.file')"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "ERROR: unsuported format $format"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
else
|
||||||
|
echo "change aborted"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
song_db_old=""
|
song_db_old=""
|
||||||
song_db_new=""
|
song_db_new=""
|
||||||
|
|
||||||
@@ -112,16 +152,15 @@ do
|
|||||||
song_db_new="$song_db_new,$(echo "$new_info" | jq '.path.mpd' || error_here):$new_info"
|
song_db_new="$song_db_new,$(echo "$new_info" | jq '.path.mpd' || error_here):$new_info"
|
||||||
|
|
||||||
tmp_old="$(mktemp)"
|
tmp_old="$(mktemp)"
|
||||||
# echo "song_info: '$song_info'"
|
|
||||||
echo "$song_info" | jq >"$tmp_old" || error_here
|
echo "$song_info" | jq >"$tmp_old" || error_here
|
||||||
tmp_new="$(mktemp)"
|
tmp_new="$(mktemp)"
|
||||||
# echo "new_info: '$new_info'"
|
|
||||||
echo "$new_info" | jq >"$tmp_new" || error_here
|
echo "$new_info" | jq >"$tmp_new" || error_here
|
||||||
|
|
||||||
echo "$song_path"
|
|
||||||
diff "$tmp_old" "$tmp_new" &>/dev/null || {
|
diff "$tmp_old" "$tmp_new" &>/dev/null || {
|
||||||
|
echo "$song_path"
|
||||||
diff "$tmp_old" "$tmp_new" || echo
|
diff "$tmp_old" "$tmp_new" || echo
|
||||||
echo
|
|
||||||
|
apply_changes "$new_info"
|
||||||
}
|
}
|
||||||
rm "$tmp_old" "$tmp_new"
|
rm "$tmp_old" "$tmp_new"
|
||||||
done
|
done
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ COUNT="$2"
|
|||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
PLAYLIST_DIR="$HOME/Music/Playlists"
|
. "$HOME/.local/share/music/common.sh"
|
||||||
|
|
||||||
|
PLAYLIST_DIR="$MUSIC_DIR/Playlists"
|
||||||
|
|
||||||
function rand_num() {
|
function rand_num() {
|
||||||
cat /dev/urandom | tr -dc '0-9' | head -c 10 | sed -e 's/^0*//'
|
cat /dev/urandom | tr -dc '0-9' | head -c 10 | sed -e 's/^0*//'
|
||||||
@@ -25,48 +27,25 @@ function pick_song() {
|
|||||||
|
|
||||||
num=$(( 1 + $(rand_num) % $(echo "$songs" | wc -l) ))
|
num=$(( 1 + $(rand_num) % $(echo "$songs" | wc -l) ))
|
||||||
song="$(echo "$songs" | sed "${num}q;d")"
|
song="$(echo "$songs" | sed "${num}q;d")"
|
||||||
echo "$(dirname "$PLAYLIST_DIR")/$song"
|
echo "$MUSIC_DIR/$song"
|
||||||
}
|
|
||||||
|
|
||||||
function get_flags() {
|
|
||||||
path="$1"
|
|
||||||
meuadata="flac"
|
|
||||||
genre="$(ffmpeg -i "${path}" 2>&1 | grep GENRE | sed -e 's/^.*: //')"
|
|
||||||
if [[ "$(echo "${path}" | sed -e 's/^.*\.\([^\.]*\)$/\1/')" == "mp3" ]]
|
|
||||||
then
|
|
||||||
metadata="mp3"
|
|
||||||
genre="$(id3v2 -l "${path}" | grep '^TCON' | sed -e 's/^.*: //')"
|
|
||||||
fi
|
|
||||||
echo $genre
|
|
||||||
}
|
|
||||||
|
|
||||||
function get_like_level() {
|
|
||||||
flags="$1"
|
|
||||||
|
|
||||||
level="$(echo "$flags" | sed -e 's/^.*L\([0-3]\).*$/\1/')"
|
|
||||||
if [[ "$level" == "$(echo "$level" | tr -dc '0-3')" ]]
|
|
||||||
then
|
|
||||||
echo $level
|
|
||||||
else
|
|
||||||
echo 2 # default like level
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function shuffle() {
|
function shuffle() {
|
||||||
playlist="$1"
|
playlist="$1"
|
||||||
|
|
||||||
song="$(pick_song "$playlist")"
|
song="$(pick_song "$playlist")"
|
||||||
flags="$(get_flags "$song")"
|
song="$(music_get_song_info_from_file "$song")"
|
||||||
like=$(get_like_level "$flags")
|
song="$(music_process_genre "$song")"
|
||||||
like_min=$(( 1 + $(rand_num) % 3 ))
|
like=$(echo "$song" | jq '.likeLevel')
|
||||||
|
mpd_path="$(echo "$song" | jq -rc '.path.mpd')"
|
||||||
|
like_min=$(( -1 + $(rand_num) % 3 ))
|
||||||
|
|
||||||
if [[ "$in_list" == "false" || "$like" -lt "$like_min" ]]
|
if [[ $like > $like_min ]]
|
||||||
then
|
then
|
||||||
shuffle "$playlist"
|
echo "$like $mpd_path"
|
||||||
|
mpc add "$mpd_path"
|
||||||
else
|
else
|
||||||
mpd_song="$(echo "$song" | sed -e 's|.*/Music/||')"
|
shuffle "$playlist"
|
||||||
echo "$mpd_song"
|
|
||||||
mpc add "$mpd_song"
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,8 +54,6 @@ then
|
|||||||
PLAYLIST=all
|
PLAYLIST=all
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# pick_song "$PLAYLIST"
|
|
||||||
|
|
||||||
if [[ -z "$COUNT" ]]
|
if [[ -z "$COUNT" ]]
|
||||||
then
|
then
|
||||||
echo "add one song to que from $PLAYLIST"
|
echo "add one song to que from $PLAYLIST"
|
||||||
|
|||||||
@@ -80,5 +80,3 @@ function music_process_genre() {
|
|||||||
echo "$song {\"genre\":$genre,\"blockLevel\":$blockLevel,\"likeLevel\":$likeLevel,\"playlist\":\"$playlist\"}" \
|
echo "$song {\"genre\":$genre,\"blockLevel\":$blockLevel,\"likeLevel\":$likeLevel,\"playlist\":\"$playlist\"}" \
|
||||||
| jq -c -s add || error_here
|
| jq -c -s add || error_here
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user