[resolved] Move folder based on tag in nfo file

  • Hi,


    I'm a full on OMV convert. From using a Win7 PC with some external storage the NAS world looked scary as hell. OMV is making the transition amazingly smooth. I've put in about 20+ hours of config so far and got things tweaked satisfactorily for most of the popular services, but I've run up against something I could do with some help on.


    I like to organise my movies by UK age certification as follows:


    /video
    ->/movies
    ->/u
    ->/pg
    ->/12
    ->/15
    ->/18


    e.g. /video/movies/18/Expendables 2/movie.avi, movie.nfo, etc


    This method allows simple access control levels for my kids and their XBMC libraries.
    Couchpotato post-processing gives me perfect folder and file naming along with an XBMC compatible nfo file filled with IMDB data including <certification> tag.
    Currently CouchPotato dumps the processed folder into /video/movies and I manually sort into the correct rating folder. What would completely automate this process is a perl or python script (along with a cron job) that watches for new movies turning up (perhaps a new folder like /video/movies/couchpotatodrop/), parses the nfo file for the certification value and then moves the movie folder to the appropriate rating folder.


    Sadly I don't know Perl or Python and while my PHP experience tells me this isn't a hugely complex script it is still beyond me. Is there any Perl or Python guru on the board who would write a little script to do this job?


    nfo file can be named "movie.nfo" or <folder name>/nfo [e.g. Expendables 2 (2012).nfo] soetimes with both files being present.


    IMDB certification tag values can be:
    "UK:18", "UK:15", "UK:12A", "UK:PG", "UK:U"


    Some nfo files have certification data for lots of countires but the UK rating is always in the format above.


    Any takers?

    "Standing on the shoulders of giants"


    omv 2.1.23 Stoneburner - 64 bit
    plugins - transmission, clamav, usbbackup, mysql, website
    sickbeard, couchpotato, subsonic, extplorer
    HP Proliant N40L Microserver - AMD Turion II - 4Gb DDR3 - 250GB 3.5" system drive
    2 x 2TB WD Green (EZRX) - Mirrored


    Used (so far) as video vault, subsonic music server, home PC backup , personal photo store with autodrop from Android phones.

    Einmal editiert, zuletzt von culprit ()

  • I know PHP so I've started cobbling together bits of Python from around the web.


    Below is my progress so far but I'm coming up against my rough and ready abilities so getting stuck.


    I'm pretty sure my syntax is all to shite and the pyinotify stuff, while very neat and powerful, just looks like Hieroglyphics to me.


    Any help appreciated.


    "Standing on the shoulders of giants"


    omv 2.1.23 Stoneburner - 64 bit
    plugins - transmission, clamav, usbbackup, mysql, website
    sickbeard, couchpotato, subsonic, extplorer
    HP Proliant N40L Microserver - AMD Turion II - 4Gb DDR3 - 250GB 3.5" system drive
    2 x 2TB WD Green (EZRX) - Mirrored


    Used (so far) as video vault, subsonic music server, home PC backup , personal photo store with autodrop from Android phones.

    • Offizieller Beitrag

    Wouldn't it be easier to run a bash script every 15 or 30 minutes on the /video/movies directory? If there were any directories, check each one for .nfo file. If there is an .nfo file, check for rating and move folder to appropriate location. It wouldn't be instant but would be easy.


    This doesn't work but is a good start.


    Code
    for D in `find /video/movies/ -type d`
    do
      if grep "UK:18" $Dmovie.nfo
      then
        mv D /video/18/
      if grep "UK:15" $Dmovie.nfo
      then
        mv D /video/15/
      fi
    done

    omv 7.1.0-1 sandworm | 64 bit | 6.8 proxmox kernel

    plugins :: omvextrasorg 7.0 | kvm 7.0.13 | compose 7.2 | k8s 7.1.0-3 | cputemp 7.0.1 | mergerfs 7.0.5 | scripts 7.0.1


    omv-extras.org plugins source code and issue tracker - github - changelogs


    Please try ctrl-shift-R and read this before posting a question.

    Please put your OMV system details in your signature.
    Please don't PM for support... Too many PMs!

  • Thanks for the help. Really is appreciated.


    I don't know bash scripting syntax at all as yet. I can make out the logic of what you've written though. I'll learn some bash scripting and have another crack with this instead of Python.


    Cheers.

    "Standing on the shoulders of giants"


    omv 2.1.23 Stoneburner - 64 bit
    plugins - transmission, clamav, usbbackup, mysql, website
    sickbeard, couchpotato, subsonic, extplorer
    HP Proliant N40L Microserver - AMD Turion II - 4Gb DDR3 - 250GB 3.5" system drive
    2 x 2TB WD Green (EZRX) - Mirrored


    Used (so far) as video vault, subsonic music server, home PC backup , personal photo store with autodrop from Android phones.

    • Offizieller Beitrag

    The commands I showed are real and work. Just not complete. If I have time tonight or tomorrow, I will finish it up.

    omv 7.1.0-1 sandworm | 64 bit | 6.8 proxmox kernel

    plugins :: omvextrasorg 7.0 | kvm 7.0.13 | compose 7.2 | k8s 7.1.0-3 | cputemp 7.0.1 | mergerfs 7.0.5 | scripts 7.0.1


    omv-extras.org plugins source code and issue tracker - github - changelogs


    Please try ctrl-shift-R and read this before posting a question.

    Please put your OMV system details in your signature.
    Please don't PM for support... Too many PMs!

  • Zitat von "ryecoaaron"

    Wouldn't it be easier to run a bash script every 15 or 30 minutes on the /video/movies directory? If there were any directories, check each one for .nfo file. If there is an .nfo file, check for rating and move folder to appropriate location. It wouldn't be instant but would be easy.


    This doesn't work but is a good start.


    Maybe like this: (untested)
    - inserted variables for easier editing
    - changed backticks to $(...) I find it easier to read ;)
    - some cli output, what is done


    • Offizieller Beitrag

    With Solo0815's additions. Works on my simple test.


    omv 7.1.0-1 sandworm | 64 bit | 6.8 proxmox kernel

    plugins :: omvextrasorg 7.0 | kvm 7.0.13 | compose 7.2 | k8s 7.1.0-3 | cputemp 7.0.1 | mergerfs 7.0.5 | scripts 7.0.1


    omv-extras.org plugins source code and issue tracker - github - changelogs


    Please try ctrl-shift-R and read this before posting a question.

    Please put your OMV system details in your signature.
    Please don't PM for support... Too many PMs!

  • This is perfect. Thank you so much. I've set it up as a cron job and will throw some folders at it over the weekend to see how it gets on.


    Thanks again.

    "Standing on the shoulders of giants"


    omv 2.1.23 Stoneburner - 64 bit
    plugins - transmission, clamav, usbbackup, mysql, website
    sickbeard, couchpotato, subsonic, extplorer
    HP Proliant N40L Microserver - AMD Turion II - 4Gb DDR3 - 250GB 3.5" system drive
    2 x 2TB WD Green (EZRX) - Mirrored


    Used (so far) as video vault, subsonic music server, home PC backup , personal photo store with autodrop from Android phones.

  • Hi,


    Script isn't working for me I'm afraid. Here is the relevant folder structure:


    /videos/movieshifter.sh
    /videos/moviedump/Movie To Shift (2011)/Movie To Shift.avi
    /videos/moviedump/Movie To Shift (2011)/Movie To Shift.nfo
    /videos/moviedump/Movie To Shift (2011)/Movie To Shift.srt
    /videos/moviedump/Movie To Shift (2011)/Movie To Shift.tbn
    /videos/moviedump/Movie To Shift (2011)/folder.jpg
    /videos/movies/u/
    /videos/movies/pg
    /videos/movies/12
    /videos/movies/15
    /videos/movies/18


    movieshifter.sh:


    I've put the find condition in quotes as the script was not handling folder names with spaces. It treated each word as a folder to search.


    My output is always "no rating found, skipping file".
    If I echo out $D I get "moviedump moviedump/Movie To Shift (2011)".
    If I change grep to recursive then it finds the string "<certification>UK:12</certification>" correctly but nothing gets moved.


    Still tinkering.

    "Standing on the shoulders of giants"


    omv 2.1.23 Stoneburner - 64 bit
    plugins - transmission, clamav, usbbackup, mysql, website
    sickbeard, couchpotato, subsonic, extplorer
    HP Proliant N40L Microserver - AMD Turion II - 4Gb DDR3 - 250GB 3.5" system drive
    2 x 2TB WD Green (EZRX) - Mirrored


    Used (so far) as video vault, subsonic music server, home PC backup , personal photo store with autodrop from Android phones.

  • Make sure you insert the full-path to your folders!
    Another issue can be the "spaces" in the file- and foldernames. This should not bother you in the new attached script.


    Edit: Tekkbebe was faster :twisted: ;)

  • I've tried running that. Added in full paths but still no luck.


    I've dropped the "-s" option form grep and that outputs "/media/unique-storage-string/video/moviedump/Name Of Folder (2011)/*.nfo: no such file or directory" but I am 100% sure the file it's looking for exists. I am running the script from /scripts at the OS root.


    If I navigate to the moviedump folder via CLI and run (as root):


    Code
    grep "UK:12" "Name Of Folder (2011)"/*.nfo


    I get the correct output of <certification>UK:12</certification>. It looks like grep in the script is not using the wildcard for some reason.

    "Standing on the shoulders of giants"


    omv 2.1.23 Stoneburner - 64 bit
    plugins - transmission, clamav, usbbackup, mysql, website
    sickbeard, couchpotato, subsonic, extplorer
    HP Proliant N40L Microserver - AMD Turion II - 4Gb DDR3 - 250GB 3.5" system drive
    2 x 2TB WD Green (EZRX) - Mirrored


    Used (so far) as video vault, subsonic music server, home PC backup , personal photo store with autodrop from Android phones.

  • Can you please post the output of:

    Code
    FOLDER="/your/fullpath/to/movies"
    for D in "$(find . -type f -name "$FOLDER/*/*.nfo")"; do echo "Working on '$D' --- Folder = '${D%/*}' "; done
  • Here you go Solo0815:


    Code
    find: warning: Unix filenames usually don't contain slashes (though pathnames do).  That means that '-name `/media/unqiue-storage-identifier/video/moviedump/*/*.nfo'' will probably evaluate to false all the time on this system.  You might find the '-wholename' test more useful, or perhaps '-samefile'.  Alternatively, if you are using GNU grep, you could use 'find ... -print0 | grep -FzZ `/media/bb09e796-5566-4eb2-8fc1-043a156233c4/video/moviedump/*/*.nfo''.
    Working on '' --- Folder = ''

    "Standing on the shoulders of giants"


    omv 2.1.23 Stoneburner - 64 bit
    plugins - transmission, clamav, usbbackup, mysql, website
    sickbeard, couchpotato, subsonic, extplorer
    HP Proliant N40L Microserver - AMD Turion II - 4Gb DDR3 - 250GB 3.5" system drive
    2 x 2TB WD Green (EZRX) - Mirrored


    Used (so far) as video vault, subsonic music server, home PC backup , personal photo store with autodrop from Android phones.

    • Offizieller Beitrag

    Here is a new version that works on directories with spaces :) File attached as well.


  • That's it!
    Absolutely perfect.
    Thank you so much for this ryecoaaron and Solo0815. My media server is now completely automated and I can be sure my kids are only viewing age appropriate movies.

    "Standing on the shoulders of giants"


    omv 2.1.23 Stoneburner - 64 bit
    plugins - transmission, clamav, usbbackup, mysql, website
    sickbeard, couchpotato, subsonic, extplorer
    HP Proliant N40L Microserver - AMD Turion II - 4Gb DDR3 - 250GB 3.5" system drive
    2 x 2TB WD Green (EZRX) - Mirrored


    Used (so far) as video vault, subsonic music server, home PC backup , personal photo store with autodrop from Android phones.

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!