变量未从此脚本中转移

时间:2017-08-13 00:01:37

标签: batch-file video batch-processing batch-rename

此脚本将视频文件作为输入,并在初步重命名后推断for .. intitleyear等值以及搜索字符串episode,以查找重复的视频和strict用于查找系列的所有剧集。然后它为文件重命名一个受控文件。

loose

没有任何变量被转移到调用它们的脚本。我不能为我的生活找出原因,除非它必须与set "filename=%~n1" set "parentdir=%~2" :: ============================================================================================================================= :: 1. FILENAME VALIDATOR :: ============================================================================================================================= set "original=%filename%" set "filename=%filename:!=%" set "filename=%filename:&=and%" setlocal enabledelayedexpansion set "filename=!filename:%%=_percent!" for /l %%s in (0,1,9) do set "filename=!filename:series.%%s=S0%%s!" for /l %%e in (0,1,9) do set "filename=!filename:%%eof2=E0%%e!" for /l %%e in (0,1,9) do set "filename=!filename:%%eof3=E0%%e!" for /l %%e in (0,1,9) do set "filename=!filename:%%eof4=E0%%e!" for /l %%e in (0,1,9) do set "filename=!filename:%%eof5=E0%%e!" for /l %%e in (0,1,9) do set "filename=!filename:%%eof6=E0%%e!" for /l %%e in (0,1,9) do set "filename=!filename:%%eof7=E0%%e!" for /l %%e in (0,1,9) do set "filename=!filename:%%eof8=E0%%e!" for /l %%e in (0,1,9) do set "filename=!filename:%%eof9=E0%%e!" setlocal disabledelayedexpansion if not "%filename%"=="%original%" ren "%~1" "%filename%%~x1" && echo validated "%original%" :: ============================================================================================================================= :: 2. EXTRAS RENAMER :: ============================================================================================================================= echo "%~p1" | find /i "extras" >nul || goto skip_extras echo "%~p1" | find /i "featurettes" >nul || goto skip_extras if not defined parentdir echo detected featurette but parentdir was not delivered && exit /b call :extrapolate "%parentdir%" ren "%filename%%~x1" "%name% extras - %filename%%~x1" && echo renamed extra "%name% extras - %filename%%~x1" && exit /b :skip_extras :: ============================================================================================================================= :: 3. EXTRAPOLATOR :: ============================================================================================================================= :extrapolate set "type=" & set "year=" & set "ss=" & set "ep=" & set "episode=" set "name=%filename%" echo "%name%"| find " " >nul || set "name=%name:.= %" & rem if no spaces then then safer to replace dots :: episode number: last tag first SETLOCAL enabledelayedexpansion FOR /L %%e IN (100,1,199) DO ( SET "modname=!name:E%%e=!" IF "!modname!" neq "%name%" ( SET "setcmd=set name=!name:E%%e=& set ep=E%%e& set type=show& rem !" GOTO gotep ) ) FOR /L %%e IN (10,1,99) DO ( SET "modname=!name:E%%e=!" IF "!modname!" neq "%name%" ( SET "setcmd=set name=!name:E%%e=& set ep=E%%e& set type=show& rem !" GOTO gotep ) SET "modname=!name:E0%%e=!" IF "!modname!" neq "%name%" ( SET "setcmd=set name=!name:E0%%e=& set ep=E0%%e& set type=show& rem !" GOTO gotep ) ) FOR /L %%e IN (0,1,9) DO ( SET "modname=!name:E0%%e=!" IF "!modname!" neq "%name%" ( SET "setcmd=set name=!name:E0%%e=& set ep=E0%%e& set type=show& rem !" GOTO gotep ) SET "modname=!name:E00%%e=!" IF "!modname!" neq "%name%" ( SET "setcmd=set name=!name:E00%%e=& set ep=E00%%e& set type=show& rem !" GOTO gotep ) SET "modname=!name:%%eof=!" IF "!modname!" neq "%name%" ( SET "setcmd=set name=!name:%%eof=& set ep=E0%%e& set type=show& rem !" GOTO gotep ) SET "modname=!name:x0%%e=!" IF "!modname!" neq "%name%" ( SET "setcmd=set name=!name:x0%%e=& set ep=E0%%e& set type=show& rem !" GOTO gotep ) ) ENDLOCAL GOTO skipep :gotep %setcmd% ENDLOCAL & SET "type=%type%" & SET "ep=%ep%" & SET name=%name% :skipep :: season number: second to last tag second SETLOCAL enabledelayedexpansion FOR /L %%e IN (0,1,9) DO ( SET "modname=!name:S0%%e=!" IF "!modname!" neq "%name%" ( SET "setcmd=set name=!name:S0%%e=& set ss=S0%%e& set type=show& rem !" GOTO gotss ) ) FOR /L %%e IN (10,1,99) DO ( SET "modname=!name:S%%e=!" IF "!modname!" neq "%name%" ( SET "setcmd=set name=!name:S%%e=& set ss=S%%e& set type=show& rem !" GOTO gotss ) ) FOR /L %%e IN (0,1,9) DO ( SET "modname=!name:series.%%e=!" IF "!modname!" neq "%name%" ( SET "setcmd=set name=!name:series.%%e=& set ss=S0%%e& set type=show& rem !" GOTO gotss ) ) ENDLOCAL GOTO skipss :gotss %setcmd% ENDLOCAL & SET "type=%type%" & SET "ss=%ss%" & SET name=%name% :skipss if defined ep if not defined ss set ss=S01 SET "episode=%ss%%ep%" :: year number: first tag last SETLOCAL enabledelayedexpansion FOR /L %%e IN (1957,1,2057) DO ( SET "modname=!name:%%e=!" IF "!modname!" neq "%name%" ( SET "setcmd=set name=!name:%%e=& set year=%%e& if not defined type set type=film& rem !" GOTO gotyear ) ) ENDLOCAL GOTO skipyear :gotyear %setcmd% ENDLOCAL & SET "year=%year%" & SET "type=%type%" & SET name=%name% :skipyear :: finalize :: changes for general use set name=%name: - = % :: trim last useless letter from name set "name=%name%endtrimmer" set "name=%name:(endtrimmer=endtrimmer%" set "name=%name:[endtrimmer=endtrimmer%" set "name=%name: endtrimmer=endtrimmer%" set "name=%name: endtrimmer=%" set "name=%name:_endtrimmer=%" set "name=%name:endtrimmer=%" :: set strings if "%type%"=="film" set "strict=%name: =?%?(%year%)" if "%type%"=="show" if defined year set "strict=%name: =?%?(%year%)?%episode%" if "%type%"=="show" if not defined year set "strict=%name: =?%?%episode%" if "%type%"=="show" if defined year set "loose=%name: =?%?(%year%)?s" if "%type%"=="show" if not defined year set "loose=%name: =?%?s" SETLOCAL enabledelayedexpansion FOR %%a IN (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO SET "name=!name:%%a=%%a!" endlocal & SET "name=%name%" :: declare (disable never delete) if "%type%"=="film" echo extrapolated film %strict:?= % if "%type%"=="show" echo extrapolated episode %strict:?= % :: ============================================================================================================================= :: 4. FILEBOT MODERATOR :: ============================================================================================================================= if not defined type exit /b :: prep fake temp file set tempdir=%temp%\%date:~3,2%%date:~6,2%%date:~11,2%%time:~1,1%%time:~3,2%%time:~6,2%%time:~9,2% mkdir "%tempdir%" && copy /y nul "%tempdir%\%filename%.mkv" >nul :: variables (to shorten lines) if "%type%"=="film" set cf=--db TheMovieDb --format "{n} ({y}) {director} {genres} r{rating} {vf} {vc} {ac} {imdbid}" if "%type%"=="show" set cf=--db TheTVDb --format "{n} {s00e00} {t} {vf} {vc} {ac} {imdbid}" :: rename fake temp file filebot -rename "%tempdir%\%filename%%~x1" --q "%name% %year%" %cf% >nul 2>nul :: new name into variable for /r "%tempdir%" %%i in (*) do set "new=%%~ni" :: declare failure if "%filename%"=="%new%" echo filebot refused to rename "%~n1" && exit /b :: if what expected rename 4real echo %%new:^&=^^^&%% | findstr /i /b /c:"%strict:?= %" >nul && goto 4real :: if not reformat and try again set "new=%new:'=%" set "new=%new:,=%" echo %%new:^&=^^^&%% | findstr /i /b /c:"%strict:?= %" >nul && goto 4real :: declare failure and confirm override echo "%new%" does not match "%string%" choice /t 20 /c yn /n /d n /m "override and approve rename? [Y]es or [N]o: " if "%errorlevel%"=="1" goto 4real exit /b :4real filebot -rename "%~dp1%filename%%~x1" --q "%name% %year%" %cf% >nul 2>nul if not exist "%filename%" echo successfully renamed "%filename%" exit /b endlocal有关,就我所知,这对我来说很好。

0 个答案:

没有答案