Merge pull request #17 from DragonGhost7/master

added capability to write missing song tags
This commit is contained in:
Siddharth Dushantha 2019-06-01 21:51:50 +02:00 committed by GitHub
commit 965500aa5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 14 deletions

View File

@ -15,6 +15,8 @@
- ```ffmpeg```
- ```mpc```
- ```jq```
- ```eyeD3```
## Installation
### Install using ```make```

29
kunst
View File

@ -99,8 +99,8 @@ get_cover_online() {
API_URL="http://api.deezer.com/search/autocomplete?q=$(mpc current)" && API_URL=${API_URL//' '/'%20'}
# Extract the albumcover from the json returned
IMG_URL=$(curl -s "$API_URL" | jq -r '.playlists.data[0] | .picture_big')
#IMG_URL=$(curl -s "$API_URL" | jq -r '.playlists.data[0] | .picture_big')
IMG_URL=$( curl -s "$API_URL" | jq -r '.tracks.data[0].album.cover_big')
if [ "$IMG_URL" = '' ] || [ "$IMG_URL" = 'null' ];then
if [ ! $SILENT ];then
echo "error: cover not found online"
@ -111,11 +111,30 @@ get_cover_online() {
echo "kunst: cover found online"
fi
curl -o $COVER -s $IMG_URL
eyeD3 --add-image $COVER:FRONT_COVER $MUSIC_DIR$(mpc current -f %file%)
ARTLESS=false
fi
}
write_tag(){
#writes down song data if absent
#uses eyeD3
eyeD3 -v ~/Music/$(mpc current -f %file%) | egrep "None|null" && tags="0" || tags="1"
if [ $tags -eq "0" ] ;then
echo "Some tags missing"
API_URL="http://api.deezer.com/search/autocomplete?q=$(mpc current)" && API_URL=${API_URL//' '/'%20'}
#album
echo "writing down album name"
eyeD3 -A "$( curl -s "$API_URL" | jq -r '.tracks.data[0].album.title')" $MUSIC_DIR$(mpc current -f %file%)
#album artist
echo "writing down album artist"
eyeD3 -b "$( curl -s "$API_URL" | jq -r '.tracks.data[0].artist.name')" $MUSIC_DIR$(mpc current -f %file%)
else
echo "All tags are present"
fi
}
update_cover() {
# Extract the album art from the mp3 file and dont show the messsy
@ -182,15 +201,13 @@ main() {
# Flag to run some commands only once in the loop
FIRST_RUN=true
while true; do
update_cover
write_tag
if [ $ARTLESS == true ];then
# Dhange the path to COVER because the music note
# image is a png not jpg
COVER=/tmp/kunst.png
COVER=/tmp/kunst.jpg
# Decode the base64 encoded image and save it
# to /tmp/kunst.png