LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-07-2018, 03:57 PM   #1
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Rep: Reputation: 49
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.
 
Old 04-07-2018, 04:23 PM   #2
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by rjo98 View Post
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")"

Last edited by BW-userx; 04-07-2018 at 04:34 PM.
 
1 members found this post helpful.
Old 04-07-2018, 06:17 PM   #3
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
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.
 
Old 04-07-2018, 06:21 PM   #4
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by rjo98 View Post
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.
 
1 members found this post helpful.
Old 04-07-2018, 07:40 PM   #5
anon091
Senior Member
 
Registered: Jun 2009
Posts: 1,795

Original Poster
Rep: Reputation: 49
oh ok, thanks
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need a command to find the files modified after a date with recursive with folder musammil123 Linux - General 2 01-12-2012 12:12 AM
[SOLVED] how to display the last 10 modified files of a folder? nrbasavaraja Linux - Newbie 8 07-23-2010 12:13 PM
cannot modified files in etc folder..... saqibsh Linux - Software 1 03-26-2010 09:24 AM
Sorting all files of home folder modified after a specific date for backup fc6_user Linux - General 2 03-30-2007 02:24 AM
How to automatically move files from one folder into another folder? xmrkite Linux - Software 6 11-05-2006 10:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration