first of all I have very limited knowledge in Linux but I am always trying my best. I also have already automated a lot of things in my Unraid Server and RPi by using Cronjobs and scripts, but now I am a little bit lost.
Following situation: I am using icloud photo downloader to automatically download all photos and videos from my icloud storage to my local NAS. It uses the subfolder structure /yyyy/mm/ and downloads .jpg and .mov, e.g. a video taken today will be downloaded this night to /2020/12/IMG_0123.mov
In addition, I am using 'handbrake' to then convert the .mov to .mkv as mkv can be played with all my devices and .mov always wants to be converted e.g. in Plex. For Handbrake I managed to have a watch folder (/videowatch/) and an output folder (/videooutput/) which handbrake uses to automatically converts video files which I copy in the watch folder and exports it to output folder by recreating the same folder structure. Example: I copy the video file mentioned above to subfolder /videowatch/2020/12/IMG_0123.mov, handbrake will transcode it to mkv and export the file to /videooutput/2020/12/IMG_0123.mkv. The .mov then will be deleted.
This step is what I am currently doing manually and want to have this automated.
How can I manage this script? The following steps should be performed:
- search for files of type .mov in all subfolders
- move all found .mov files to folder /videowatch/ but recreates the subfolder structure
Example: icloudpd downloads two new .mov (file1.mov and file2.mov) in folder /2020/11/ as well as /2020/12/. These two folders already store a lot of other .jpg as well as .mkv files
- The script recognizes two .mov files /2020/11/file1.mov and /2020/12/file2.mov
- The script moves these two files to folder /videowatch/ and recreates the subfolder structure. We then will have /videowatch/2020/11/file1.mov and /videowatch/2020/12/file2.mov
Is that possible? As a final step, the content of videooutput folder should be moved back to / to move the new mkv files to the destination folder of the former .mov files. As handbrake keeps the subfolder structure, this is easy to handle by a mv entry in crontab.
Hopefully I did not describe it to complicated.
Thank you so much for your help!
I am only struggling with the script to move the .mov files to the watch folder including folder structure.
e.g. I could use find to search for the files:
find . -name "*.MOV" -type f
and this brings:
./2008/08/CIMG0035.MOV
./2010/11/IMG_0212.MOV
These two files should then be moved to the watch folder and at the end be like:
./videowatch/2008/08/CIMG0035.MOV
./videowatch/2010/11/IMG_0212.MOV
I am able to handle all the other stuff (handbrake, icloudpd, cronjob etc.) by my own.
I could use
find . -name "*.MOV" -type f -exec mv '{}' /watchfolder/ \;
This then moves all .MOV identified by the find command in the watchfolder main but without any hierarchy and subfolders.So I don't have all the files in the respective folder by year / month.
./videowatch/CIMG0035.MOV
./videowatch/IMG_0212.MOV
But this is not what I want, I want / need it including the subfolder for year / month as the files are located in the source folder.
Thanks!