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
|
||||
|
||||
DATA="$(cat "$1")"
|
||||
|
||||
set -e
|
||||
|
||||
DATA="$(cat "$1")"
|
||||
|
||||
. "$HOME/.local/share/music/common.sh"
|
||||
|
||||
function get_songs_from_playlists() {
|
||||
@@ -63,6 +63,46 @@ function search_album_index() {
|
||||
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_new=""
|
||||
|
||||
@@ -112,16 +152,15 @@ do
|
||||
song_db_new="$song_db_new,$(echo "$new_info" | jq '.path.mpd' || error_here):$new_info"
|
||||
|
||||
tmp_old="$(mktemp)"
|
||||
# echo "song_info: '$song_info'"
|
||||
echo "$song_info" | jq >"$tmp_old" || error_here
|
||||
tmp_new="$(mktemp)"
|
||||
# echo "new_info: '$new_info'"
|
||||
echo "$new_info" | jq >"$tmp_new" || error_here
|
||||
|
||||
echo "$song_path"
|
||||
diff "$tmp_old" "$tmp_new" &>/dev/null || {
|
||||
echo "$song_path"
|
||||
diff "$tmp_old" "$tmp_new" || echo
|
||||
echo
|
||||
|
||||
apply_changes "$new_info"
|
||||
}
|
||||
rm "$tmp_old" "$tmp_new"
|
||||
done
|
||||
|
||||
@@ -5,7 +5,9 @@ COUNT="$2"
|
||||
|
||||
set -e
|
||||
|
||||
PLAYLIST_DIR="$HOME/Music/Playlists"
|
||||
. "$HOME/.local/share/music/common.sh"
|
||||
|
||||
PLAYLIST_DIR="$MUSIC_DIR/Playlists"
|
||||
|
||||
function rand_num() {
|
||||
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) ))
|
||||
song="$(echo "$songs" | sed "${num}q;d")"
|
||||
echo "$(dirname "$PLAYLIST_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
|
||||
echo "$MUSIC_DIR/$song"
|
||||
}
|
||||
|
||||
function shuffle() {
|
||||
playlist="$1"
|
||||
|
||||
song="$(pick_song "$playlist")"
|
||||
flags="$(get_flags "$song")"
|
||||
like=$(get_like_level "$flags")
|
||||
like_min=$(( 1 + $(rand_num) % 3 ))
|
||||
song="$(music_get_song_info_from_file "$song")"
|
||||
song="$(music_process_genre "$song")"
|
||||
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
|
||||
shuffle "$playlist"
|
||||
echo "$like $mpd_path"
|
||||
mpc add "$mpd_path"
|
||||
else
|
||||
mpd_song="$(echo "$song" | sed -e 's|.*/Music/||')"
|
||||
echo "$mpd_song"
|
||||
mpc add "$mpd_song"
|
||||
shuffle "$playlist"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -75,8 +54,6 @@ then
|
||||
PLAYLIST=all
|
||||
fi
|
||||
|
||||
# pick_song "$PLAYLIST"
|
||||
|
||||
if [[ -z "$COUNT" ]]
|
||||
then
|
||||
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\"}" \
|
||||
| jq -c -s add || error_here
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user