LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Move files modified by Picard out of source folder (https://www.linuxquestions.org/questions/linux-general-1/move-files-modified-by-picard-out-of-source-folder-4175627211/)

anon091 04-07-2018 03:57 PM

Move files modified by Picard out of source folder
 
Let me set this up, I have a massive folder with MP3s (lets call it /MP3) that I'm using Picard to attempt to populate the metadata on. Seems like every time I run it against the folder, it catches a few more files, but it also scans all the previously updated files.
So what I'd like to do is somehow move any file from /MP3 that has been modified in the last 4 hours, then move (not copy) it to /MP3-Identified but in the same subfolder structure that it existed in under /MP3.
What's the best way to do it? Then every time I rescan /MP3 after that, it'll only be scanning the unidentified files.

BW-userx 04-07-2018 04:23 PM

Quote:

Originally Posted by rjo98 (Post 5840476)
Let me set this up, I have a massive folder with MP3s (lets call it /MP3) that I'm using Picard to attempt to populate the metadata on. Seems like every time I run it against the folder, it catches a few more files, but it also scans all the previously updated files.
So what I'd like to do is somehow move any file from /MP3 that has been modified in the last 4 hours, then move (not copy) it to /MP3-Identified but in the same subfolder structure that it existed in under /MP3.
What's the best way to do it? Then every time I rescan /MP3 after that, it'll only be scanning the unidentified files.

its not what you're using but what I use to tag and organize according to my needs, that is why its modded here and there. I just get them situated and wittle them down until I get them where I want them to be. Anyways mod it to your needs. it copies and moves files to a different file structure to get them out of the way when they are done, it's design to make the back ups for safe keeping at the same time.

uses exiftools and mid3v2 — mutagen
but you can just use whats written to move and or copy it and plug in whatever tool you're using, I do suppose.
Code:

#!/bin/bash

working_dir1="/run/media/userx/4TB_esaystore/Music2"

#working_dir2="/run/media/userx/4TB_esaystore/Music/The Motels"
#working_dir3=

copy1=/run/media/userx/ntfs/Music
copy2=/run/media/userx/gptntfs1GB/Music

move1=/run/media/userx/4TB_esaystore/Music3

script=/media/data/scripts

count="$(find "$working_dir1" -iname "*.mp3" | wc -l)"


while read f ;
do
    c=$f
    xpath=${c%/*}
    xbase=${c##*/}
    xfext=${xbase##*.}
    xpref=${xbase%.*}
    path=${xpath}
    pref=${xpref}
    ext=${xfext}
   
    echo
 
    artist="$(exiftool -p '$Artist' "$f")"
    album="$(exiftool -p '$Album' "$f")"
    title="$(exiftool -p '$Title' "$f")"
  # genre="$(exiftool -p '$Genre' "$f")"
 #  echo "tititle: $title"
    title=${title///}
    title="${title/.mp3/}"
  #  echo "TITLE $title"
   
    newName="$artist - $title"

        #try to remove non printable chars
   
    pref=${pref//[^A-Za-z&0-9"'" ]/ }
    artist=${artist//[^A-Za-z&0-9"'" ]/ }
    album=${album//[^A-Za-z&0-9"'" ]/ }
    title=${title//[^A-Za-z&0-9"'" ]/ }
    newName=${newName//[^A-Za-z&0-9"'" ]/ }
   
   
   
    pref="$(echo -e "${pref}" | tr "[A-Z]" "[a-z]" | sed -e "s/\b\(.\)/\u\1/g")"
    artist="$(echo -e "${artist}" | tr "[A-Z]" "[a-z]" | sed -e "s/\b\(.\)/\u\1/g")"
    title="$(echo -e "${title}" | tr "[A-Z]" "[a-z]" | sed -e "s/\b\(.\)/\u\1/g")"
    album="$(echo -e "${album}" | tr "[A-Z]" "[a-z]" | sed -e "s/\b\(.\)/\u\1/g")"
    newName="$(echo -e "${newName}" | tr "[A-Z]" "[a-z]" | sed -e "s/\b\(.\)/\u\1/g")"
   
            #Capitalizes each word
    newName="$(echo -e "${newName}" | tr "[A-Z]" "[a-z]" | sed -e "s/\b\(.\)/\u\1/g")"
    artist="$(echo -e "${artist}" | tr "[A-Z]" "[a-z]" | sed -e "s/\b\(.\)/\u\1/g")"
    title="$(echo -e "${title}" | tr "[A-Z]" "[a-z]" | sed -e "s/\b\(.\)/\u\1/g")"
    album="$(echo -e "${album}" | tr "[A-Z]" "[a-z]" | sed -e "s/\b\(.\)/\u\1/g")"
    pref="$(echo -e "${pref}" | tr "[A-Z]" "[a-z]" | sed -e "s/\b\(.\)/\u\1/g")"
       
        #ensure only one space between each word
    newName="$(echo -e "${newName}" | fmt -u )"
    artist="$(echo -e "${artist}" | fmt -u )"
    title="$(echo -e "${title}" | fmt -u )"
    album="$(echo -e "${album}" | fmt -u )"
    pref="$(echo -e "${pref}" | fmt -u )"
       
        #removes leading white space on both ends of string
    newName="$(echo -e "${newName}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
    artist="$(echo -e "${artist}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
    title="$(echo -e "${title}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
    album="$(echo -e "${album}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
    pref="$(echo -e "${pref}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
 
   
    mid3v2 -a "$artist" "$f"
    mid3v2 -A "$album"  "$f"
    mid3v2 -t "$title"  "$f"
  # mid3v2 -g "$genre" "$script_dir"/"$newFile"
 

if [[ -n "$artist" ]] && [[ -n "$album" ]] ; then
{
   
    #mkdir -p "$copy1"/"$artist"/"$album"
    #mkdir -p "$copy2"/"$artist"/"$album"
    mkdir -p "$move1"/"$artist"/"$album"
    echo "both: "$artist"/"$album" "
    NewName="$newName"."mp3"
    echo "NEWNAME: $NewName"
    #cp "$f" "$copy1"/"$artist"/"$album"/"$NewName"
    #cp "$f" "$copy2"/"$artist"/"$album"/"$NewName"
    mv "$f" "$move1"/"$artist"/"$album"/"$NewName"
   
    echo "$((count--))"
}
elif [[ -n "$artist" ]] && [[ -z "$album" ]] ; then
{

    #mkdir -p "$copy1"/"$artist"/"$album"
    #mkdir -p "$copy2"/"$artist"/"$album"
    mkdir -p "$move1"/"$artist"/"$album"
    echo "one: "$artist"/"$album" "
    NewName="$newName"."mp3"
    echo "NEWNAME: $NewName"
    #cp "$f" "$copy1"/"$artist"/"$album"/"$NewName"
    #cp "$f" "$copy2"/"$artist"/"$album"/"$NewName"
    mv -f "$f" "$move1"/"$artist"/"$album"/"$NewName"

    echo "$((count--))"
}
fi

    done <<<"$(find "$working_dir1" -iname "*.mp3")"

#    done <<<"$(find "$working_dir1" "$working_dir2" -iname "*.mp3")"


anon091 04-07-2018 06:17 PM

wow, that's pretty awesome! I'll have to play around with that.

I'll see if I can figure out some mv or rsync or something to help me clear out this folder of the files i've already got metadata for, then maybe i can try your method on the rest.

BW-userx 04-07-2018 06:21 PM

Quote:

Originally Posted by rjo98 (Post 5840530)
wow, that's pretty awesome! I'll have to play around with that.

I'll see if I can figure out some mv or rsync or something to help me clear out this folder of the files i've already got metadata for, then maybe i can try your method on the rest.

its already set up for that,this part here is checking for these two tags already present on the file, if yes then move them to where you tell them to go
Code:

[[ -n "$artist" ]] && [[ -n "$album" ]] ; then
this next check is for just one to be there and the other not.
Code:

[[ -n "$artist" ]] && [[ -z "$album" ]]
the other stuff is to just clean up the text strings which you might not have to do.

anon091 04-07-2018 07:40 PM

oh ok, thanks


All times are GMT -5. The time now is 09:17 PM.