R
R
Roman Bolshukhin2022-04-18 13:24:00
bash
Roman Bolshukhin, 2022-04-18 13:24:00

How to solve the problem with Find?

Hi all. Idea: find the files and rename them based on the template. However, after some time the script was running, I came across one variation that baffled me.

#ищем файлы с расширением .mkv, .m4v
for run in {1..10}; do
Seach_serials=$(find /volume1/Geroev_Avenue_18/Shared_Videos/Serials/ -type f \( -iname "*.mkv" -or -iname "*.m4v" -or -iname "*.mp4" -or -iname "*.ts" -or -iname "*.avi" \) -and -mmin +30 | shuf -n 1 | sed -n '1p' | head -n 1 ); 
#извлекаем название найденного файла
Serials_file=$(basename $Seach_serials)
#извлекаем папку найденного файла
Serials_folder=$(dirname $Seach_serials)
#проверяем в сериалах файлы с расширением .mkv, .m4v,соответствующего названия

if [ -n "$Seach_serials" ]; then 
Serials_destination=$(find /volume1/Geroev_Avenue_18/Shared_Videos/Serials/ -type f -iname "$Serials_file" | sed -n '1p' ); 
fi
#извлекаем название найденного файла в сериалах
Serials_file_destination=$(basename $Serials_destination)
#извлекаем папку найденного файла в сериалах
Serials_folder_destination=$(dirname $Serials_destination)
#Media Renaimer 
#File
if [ -n "$Serials_file" ]; then	
TRS=$( echo "$Serials_file" |
sed -f /volume1/Geroev_Avenue_18/Software/Synology/Shell/rename.txt )
mv -nfv $Serials_folder/$Serials_file $Serials_folder/"$TRS"
fi
done


In a situation where a variant of a file of this type was found, the script fell into a coma
Expropriator (16 series) - web-dl1080p.mkv*


basename: extra operand ‘сер.)’
Try 'basename --help' for more information.
basename: missing operand
Try 'basename --help' for more information.
dirname: missing operand


* the output should have been
Ekspropriator.16.ser.mkv


rename.txt file looks like this
s/(//g;
s/)//g;
s/А/A/g;
s/а/a/g;
s/Б/B/g;
s/б/b/g;
s/В/V/g;
s/в/v/g;
s/Г/G/g;
s/г/g/g;
s/Д/D/g;
s/д/d/g;
s/Е/E/g;
s/е/e/g;
s/Ё/Yo/g;
s/ё/yo/g;
s/Ж/Zh/g;
s/ж/zh/g;
s/З/Z/g;
s/з/z/g;
s/И/I/g;
s/и/i/g;
s/Й/J/g;
s/й/j/g;
s/К/K/g;
s/к/k/g;
s/Л/L/g;
s/л/l/g;
s/М/M/g;
s/м/m/g;
s/Н/N/g;
s/н/n/g;
s/О/O/g;
s/о/o/g;
s/П/P/g;
s/п/p/g;
s/Р/R/g;
s/р/r/g;
s/С/S/g;
s/с/s/g;
s/Т/T/g;
s/т/t/g;
s/У/U/g;
s/у/u/g;
s/Ф/F/g;
s/ф/f/g;
s/Х/Kh/g;
s/х/kh/g;
s/Ц/TS/g;
s/ц/ts/g;
s/Ч/Ch/g;
s/ч/ch/g;
s/Ш/Sh/g;
s/ш/sh/g;
s/Щ/Sch/g;
s/щ/sch/g;
s/Ъ/'/;
s/ъ/'/;
s/Ь/'/;
s/ь/'/;
s/Ы/Y/g;
s/ы/y/g;
s/Э/E/g;
s/э/e/g;
s/Ю/Yu/g;
s/ю/yu/g;
s/Я/Ya/g;
s/я/ya/g;
s/Sbr//g;
s/SbR//g;
s/PREMIER//g;
s/MVO//g;
s/ViruseProject//g;
s/Lokalizovannyj//g;
s/videoryad//g;
s/HELLYWOOD//g;
s/AP//g;
s/LQ//g;
s/shevanlk//g;
s/nnm//g;
s/club//g;
s/ylnian//g;
s/10bit//g;
s/Nikolspup//g;
s/10.bit//g;
s/a06g49//g;
s/TVShows//g;
s/lunkin//g;
s/OlLanDGroup//g;
s/LostFilm//g;
s/Kerob//g;
s/Files.x//g;
s/Files-x//g;
s/AVC//g;
s/HDCLUB//g;
s/TDS//g;
s/25Kuzmich//g;
s/AAC//g;
s/aac//g;
s/tds//g;
s/NNMCLUB//g;
s/NNMClub//g;
s/tds//g;
s/DTS//g;
s/Dts//g;
s/dts//g; 
s/1080[pPiI]//g;
s/1080//g; 
s/720[pPiI]//g;
s/720//g; 
s/2160[pPiI]//g;
s/2160//g; 
s/BLURAY//g; 
s/BluRay//g;
s/Bluray//g;
s/Blu-Ray//g;
s/BDRip//g;
s/BDRIP//g;
s/BDrip//g;
s/BD.Rip//g;
s/Rip//g;
s/rip//g;
s/RIP//g;
s/UNRATED//g;
s/iTunes//g;
s/Eng//g;
s/ENG//g;
s/Rus//g;
s/RUS//g;
s/Web-dl//g;
s/WEB-DL//g;
s/web-dl//g;
s/Web.dl//g;
s/WEB.DL//g;
s/web.dl//g;
s/WEBDL//g;
s/WEB//g;
s/Web//g;
s/web//g;
s/GETTY//g;
s/Getty//g;
s/getty//g;
s/AMZN//g;
s/amzn//g;
s/WEBRIP//g;
s/WEBRip//g;
s/webrip//g;
s/NEWSTUDIO//g;
s/newstudio//g;
s/Newstudio//g;
s/HD//g;
s/Hd//g;
s/HDR//g;
s/Hdr//g;
s/hdr//g;
s/X264//g;
s/x264//g;
s/IMAX//g;
s/AC3//g;
s/ac3//g;
s/EXKINORAY//g;
s/ExKinoRay//g;
s/DD2.0//g;
s/dd2.0//g;
s/DD5.1//g;
s/DDP5.1//g;
s/dd5.1//g;
s/ddp5.1//g;
s/MEGAPEER//g;
s/MegaPeer//g;
s/SELEZEN//g;
s/seleZen//g;
s/LOKALIZ-SOFCJ//g;
s/KINOZAL//g;
s/Kinozal//g;
s/kinozal//g;
s/TV//g;
s/tv//g;
s/HDTV//g;
s/UKR//g;
s/Ukr//g;
s/ukr//g;
s/H.264//g;
s/h.264//g;
s/H264//g;
s/h264//g;
s/ENIAHD//g;
s/EniaHD//g;
s/ENIA//g;
s/Enia//g;
s/MaNiAcS//g;
s/UNIONGANG//g;
s/Uniongang//g;
s/ELEKTRI4KA//g;
s/Elektri4ka//g;
s/RUTRACKER.ORG//g;
s/rutracker.org//g;
s/HEVC//g;
s/Hevc//g;
s/hevc//g;
s/STALKEROK//g;
s/stalkerok//g;
s/MediaClub//g;
s/BLUEBIRD//g;
s/Bluebird//g;
s/AAC2.0//g;
s/AaC2.0//g;
s/aaC2.0//g;
s/KION//g;
s/Kion//g;
s/kion//g;
s/lq//g;
s/NewStudio//g;
s/DDP2.0//g;
s/NTb//g;
s/8x//g;
s/4x//g;
s/SRT//g;
s/AKTEP//g;
s/-/./g;
s/_/./g;
s/_/./g;
s/ /./g;
s/\]//g;
s/\[//g;
s/\.\+/./g;
s/_\+/_/g;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2022-04-18
@skyspirit

In a situation where a variant of a file of this type was found, the script fell into a coma
. Expropriator (16 ser.) - web-dl1080p.mkv*

Take arguments in quotes:
Serials_file_destination=$(basename $Serials_destination)
replaced by
Serials_file_destination=$(basename "$Serials_destination")
and by analogy in other places: dirname, mv.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question