我有这个脚本可以将文件排序到名为series
的文件夹树中,该文件夹由一个简单的" SERIES NAME"填充。包含文件的子目录。如果只有一个文件放入文件夹,它将被还原,或者我喜欢调用" unnested"。它还包含一个特殊文件夹PILOT EPISODES
,其中大多数孤儿都去了(其他人可以留下)。这是代码:
:: precautions
@cd /d d:\videos\series
@if /i not "%cd%"=="d:\videos\series" echo invalid series dir. && exit /b
@if not exist "pilot episodes" echo pilot episodes dir missing. && exit /b
@if not exist "d:\other\scripts\lootname.cmd" echo lootname missing. && exit /b
:: re-sort pilots every now and then
@if "%time:7,4%"=="7,77" move "pilot episodes\*01?01*" . >nul && echo pilot episodes unnested
:: sort by name into dedicated folders
@for %%g in (*.mp4 *.mkv *.m4v *.avi *.flv *.mpg *.mpeg *.mpe *.wmv *.mov *.ts *.m2ts *.vob *.3gp *.rm) do @call :nest "%%g"
:: revert folders with single episode
@for /f "delims=" %%g in ('dir /s /b /ad') do @dir "%%g" | findstr /c:" 1 File" >nul && @move "%%g\*" . >nul
@for /f "delims=" %%d in ('dir /s /b /ad ^| sort /r') do @rd "%%d" 2>nul
:: single pilots to dedicated folder
@if exist "pilot episodes" for %%g in (*01e01* *01e00* *01x01*) do @move "%%g" "pilot episodes"
@exit /b
:nest
:: this call extrapolates show name from filename
@call d:\other\scripts\lootname.cmd %1 data
@if not exist "%name%" mkdir "%name%"
@move %1 "%name%"
@if exist %1 echo moving "%~n1" to "%name%" failed. maybe a duplicate exists or file is being used?"
大问题是这是一个繁重的过程,特别是当我有时必须将所有飞行员移回系列根进行重新排序时(如果节目中出现了更多剧集)。它必须嵌套每一个然后还原每一个并将它们移回飞行员只是为了看看是否有任何新的"配对"已经完成。我想知道是否有办法跳过所有这些不必要的工作并仍然保持相对简单?
编辑:
这是脚本中引用的lootname.cmd
文件。它不仅仅是推断系列排序的名称。它还会检测用于对filebot
重命名进行进一步限制的年份,季节和剧集(在真正重命名之前进行虚假重命名并与原始进行比较)。我可能在这里偏执,但我不太信任filebot。作为附加功能,如果文件位于名为making of
或extras
的文件夹中,它还会将文件重命名为featurettes
。无论如何使用data
循环它绕过除了上面我的系列分类器唯一使用的外推之外的所有内容。
if "%~2"=="data" call :data "%~n1" data & exit /b
cd /d "%~dp1"
if not "%cd%\"=="%~dp1" echo dir %~dp1 not found && exit /b
:: detect extras (from path) and rename to include movie name from parent folder
:: bug: this puts double "making of " to beginning of the first file for some reason.
echo %1 | find /i "extras" >nul && call :data %2
echo %1 | find /i "featurettes" >nul && call :data %2
echo %1 | find /i "extras" >nul && ren %1 "Making of %name% - %~nx1" && exit /b
echo %1 | find /i "featurettes" >nul && ren %1 "Making of %name% - %~nx1" && exit /b
:: regular job start (show and film only)
call :data "%~n1"
if "%type%"=="misc" echo unable to rename without tags "%~n1" && 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%
md "%tempdir%" && copy /y nul "%tempdir%\%~nx1" >nul
:: variables (to shorten lines)
set fb=c:\progra~1\filebot\filebot
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
%fb% -rename "%tempdir%\%~nx1" --q "%name% %year%" %cf% >nul 2>nul
for /r "%tempdir%" %%i in (*) do set "new=%%~ni"
if "%~n1"=="%new%" echo rename manually "%~n1" && exit /b
:: if as expected rename for real
if "%type%"=="film" echo %%new:^&=^^^&%% | findstr /i /b /c:"%name% (%year%)" >nul && goto 4real
if "%type%"=="show" if not "%year%"=="" echo %%new:^&=^^^&%% | findstr /i /b /c:"%name% (%year%) %ss%%ep%" >nul && goto 4real
if "%type%"=="show" if "%year%"=="" echo %%new:^&=^^^&%% | findstr /i /b /c:"%name% %ss%%ep%" >nul && goto 4real
echo rename "%~n1" failed && exit /b
exit /b
:4real
%fb% -rename %1 --q "%name% %year%" %cf% >nul 2>nul
if not exist %1 echo successfully renamed "%~n1"
exit /b
:data
set ss=
set ep=
set year=
set type=misc
set name=%~1
:: sanitize
set name=%name:.= %
set name=%name:_= %
set name=%name: - = %
set name=%name: - Copy.=.%
set name=%name: (original)=%
set name=%name:(1)=%
set name=%name:(2)=%
set name=%name:[1]=%
set name=%name:[2]=%
set name=%name:(=%
set name=%name:)=%
set name=%name:[=%
set name=%name:]=%
set name=%name:pbs =%
set name=%name:bbc =%
set name=%name: the series=%
set name=%name: = %
:: episode tags as variables + cut
set name=%name:e199=& set ep=E199& set type=show& rem %
set name=%name:e198=& set ep=E198& set type=show& rem %
set name=%name:e197=& set ep=E197& set type=show& rem %
set name=%name:e196=& set ep=E196& set type=show& rem %
set name=%name:e195=& set ep=E195& set type=show& rem %
set name=%name:e194=& set ep=E194& set type=show& rem %
set name=%name:e193=& set ep=E193& set type=show& rem %
set name=%name:e192=& set ep=E192& set type=show& rem %
set name=%name:e191=& set ep=E191& set type=show& rem %
set name=%name:e190=& set ep=E190& set type=show& rem %
set name=%name:e189=& set ep=E189& set type=show& rem %
set name=%name:e188=& set ep=E188& set type=show& rem %
set name=%name:e187=& set ep=E187& set type=show& rem %
set name=%name:e186=& set ep=E186& set type=show& rem %
set name=%name:e185=& set ep=E185& set type=show& rem %
set name=%name:e184=& set ep=E184& set type=show& rem %
set name=%name:e183=& set ep=E183& set type=show& rem %
set name=%name:e182=& set ep=E182& set type=show& rem %
set name=%name:e181=& set ep=E181& set type=show& rem %
set name=%name:e180=& set ep=E180& set type=show& rem %
set name=%name:e179=& set ep=E179& set type=show& rem %
set name=%name:e178=& set ep=E178& set type=show& rem %
set name=%name:e177=& set ep=E177& set type=show& rem %
set name=%name:e176=& set ep=E176& set type=show& rem %
set name=%name:e175=& set ep=E175& set type=show& rem %
set name=%name:e174=& set ep=E174& set type=show& rem %
set name=%name:e173=& set ep=E173& set type=show& rem %
set name=%name:e172=& set ep=E172& set type=show& rem %
set name=%name:e171=& set ep=E171& set type=show& rem %
set name=%name:e170=& set ep=E170& set type=show& rem %
set name=%name:e169=& set ep=E169& set type=show& rem %
set name=%name:e168=& set ep=E168& set type=show& rem %
set name=%name:e167=& set ep=E167& set type=show& rem %
set name=%name:e166=& set ep=E166& set type=show& rem %
set name=%name:e165=& set ep=E165& set type=show& rem %
set name=%name:e164=& set ep=E164& set type=show& rem %
set name=%name:e163=& set ep=E163& set type=show& rem %
set name=%name:e162=& set ep=E162& set type=show& rem %
set name=%name:e161=& set ep=E161& set type=show& rem %
set name=%name:e160=& set ep=E160& set type=show& rem %
set name=%name:e159=& set ep=E159& set type=show& rem %
set name=%name:e158=& set ep=E158& set type=show& rem %
set name=%name:e157=& set ep=E157& set type=show& rem %
set name=%name:e156=& set ep=E156& set type=show& rem %
set name=%name:e155=& set ep=E155& set type=show& rem %
set name=%name:e154=& set ep=E154& set type=show& rem %
set name=%name:e153=& set ep=E153& set type=show& rem %
set name=%name:e152=& set ep=E152& set type=show& rem %
set name=%name:e151=& set ep=E151& set type=show& rem %
set name=%name:e150=& set ep=E150& set type=show& rem %
set name=%name:e149=& set ep=E149& set type=show& rem %
set name=%name:e148=& set ep=E148& set type=show& rem %
set name=%name:e147=& set ep=E147& set type=show& rem %
set name=%name:e146=& set ep=E146& set type=show& rem %
set name=%name:e145=& set ep=E145& set type=show& rem %
set name=%name:e144=& set ep=E144& set type=show& rem %
set name=%name:e143=& set ep=E143& set type=show& rem %
set name=%name:e142=& set ep=E142& set type=show& rem %
set name=%name:e141=& set ep=E141& set type=show& rem %
set name=%name:e140=& set ep=E140& set type=show& rem %
set name=%name:e139=& set ep=E139& set type=show& rem %
set name=%name:e138=& set ep=E138& set type=show& rem %
set name=%name:e137=& set ep=E137& set type=show& rem %
set name=%name:e136=& set ep=E136& set type=show& rem %
set name=%name:e135=& set ep=E135& set type=show& rem %
set name=%name:e134=& set ep=E134& set type=show& rem %
set name=%name:e133=& set ep=E133& set type=show& rem %
set name=%name:e132=& set ep=E132& set type=show& rem %
set name=%name:e131=& set ep=E131& set type=show& rem %
set name=%name:e130=& set ep=E130& set type=show& rem %
set name=%name:e129=& set ep=E129& set type=show& rem %
set name=%name:e128=& set ep=E128& set type=show& rem %
set name=%name:e127=& set ep=E127& set type=show& rem %
set name=%name:e126=& set ep=E126& set type=show& rem %
set name=%name:e125=& set ep=E125& set type=show& rem %
set name=%name:e124=& set ep=E124& set type=show& rem %
set name=%name:e123=& set ep=E123& set type=show& rem %
set name=%name:e122=& set ep=E122& set type=show& rem %
set name=%name:e121=& set ep=E121& set type=show& rem %
set name=%name:e120=& set ep=E120& set type=show& rem %
set name=%name:e119=& set ep=E119& set type=show& rem %
set name=%name:e118=& set ep=E118& set type=show& rem %
set name=%name:e117=& set ep=E117& set type=show& rem %
set name=%name:e116=& set ep=E116& set type=show& rem %
set name=%name:e115=& set ep=E115& set type=show& rem %
set name=%name:e114=& set ep=E114& set type=show& rem %
set name=%name:e113=& set ep=E113& set type=show& rem %
set name=%name:e112=& set ep=E112& set type=show& rem %
set name=%name:e111=& set ep=E111& set type=show& rem %
set name=%name:e110=& set ep=E110& set type=show& rem %
set name=%name:e109=& set ep=E109& set type=show& rem %
set name=%name:e108=& set ep=E108& set type=show& rem %
set name=%name:e107=& set ep=E107& set type=show& rem %
set name=%name:e106=& set ep=E106& set type=show& rem %
set name=%name:e105=& set ep=E105& set type=show& rem %
set name=%name:e104=& set ep=E104& set type=show& rem %
set name=%name:e103=& set ep=E103& set type=show& rem %
set name=%name:e102=& set ep=E102& set type=show& rem %
set name=%name:e101=& set ep=E101& set type=show& rem %
set name=%name:e100=& set ep=E100& set type=show& rem %
set name=%name:e99=& set ep=E99& set type=show& rem %
set name=%name:e98=& set ep=E98& set type=show& rem %
set name=%name:e97=& set ep=E97& set type=show& rem %
set name=%name:e96=& set ep=E96& set type=show& rem %
set name=%name:e95=& set ep=E95& set type=show& rem %
set name=%name:e94=& set ep=E94& set type=show& rem %
set name=%name:e93=& set ep=E93& set type=show& rem %
set name=%name:e92=& set ep=E92& set type=show& rem %
set name=%name:e91=& set ep=E91& set type=show& rem %
set name=%name:e90=& set ep=E90& set type=show& rem %
set name=%name:e89=& set ep=E89& set type=show& rem %
set name=%name:e88=& set ep=E88& set type=show& rem %
set name=%name:e87=& set ep=E87& set type=show& rem %
set name=%name:e86=& set ep=E86& set type=show& rem %
set name=%name:e85=& set ep=E85& set type=show& rem %
set name=%name:e84=& set ep=E84& set type=show& rem %
set name=%name:e83=& set ep=E83& set type=show& rem %
set name=%name:e82=& set ep=E82& set type=show& rem %
set name=%name:e81=& set ep=E81& set type=show& rem %
set name=%name:e80=& set ep=E80& set type=show& rem %
set name=%name:e79=& set ep=E79& set type=show& rem %
set name=%name:e78=& set ep=E78& set type=show& rem %
set name=%name:e77=& set ep=E77& set type=show& rem %
set name=%name:e76=& set ep=E76& set type=show& rem %
set name=%name:e75=& set ep=E75& set type=show& rem %
set name=%name:e74=& set ep=E74& set type=show& rem %
set name=%name:e73=& set ep=E73& set type=show& rem %
set name=%name:e72=& set ep=E72& set type=show& rem %
set name=%name:e71=& set ep=E71& set type=show& rem %
set name=%name:e70=& set ep=E70& set type=show& rem %
set name=%name:e69=& set ep=E69& set type=show& rem %
set name=%name:e68=& set ep=E68& set type=show& rem %
set name=%name:e67=& set ep=E67& set type=show& rem %
set name=%name:e66=& set ep=E66& set type=show& rem %
set name=%name:e65=& set ep=E65& set type=show& rem %
set name=%name:e64=& set ep=E64& set type=show& rem %
set name=%name:e63=& set ep=E63& set type=show& rem %
set name=%name:e62=& set ep=E62& set type=show& rem %
set name=%name:e61=& set ep=E61& set type=show& rem %
set name=%name:e60=& set ep=E60& set type=show& rem %
set name=%name:e59=& set ep=E59& set type=show& rem %
set name=%name:e58=& set ep=E58& set type=show& rem %
set name=%name:e57=& set ep=E57& set type=show& rem %
set name=%name:e56=& set ep=E56& set type=show& rem %
set name=%name:e55=& set ep=E55& set type=show& rem %
set name=%name:e54=& set ep=E54& set type=show& rem %
set name=%name:e53=& set ep=E53& set type=show& rem %
set name=%name:e52=& set ep=E52& set type=show& rem %
set name=%name:e51=& set ep=E51& set type=show& rem %
set name=%name:e50=& set ep=E50& set type=show& rem %
set name=%name:e49=& set ep=E49& set type=show& rem %
set name=%name:e48=& set ep=E48& set type=show& rem %
set name=%name:e47=& set ep=E47& set type=show& rem %
set name=%name:e46=& set ep=E46& set type=show& rem %
set name=%name:e45=& set ep=E45& set type=show& rem %
set name=%name:e44=& set ep=E44& set type=show& rem %
set name=%name:e43=& set ep=E43& set type=show& rem %
set name=%name:e42=& set ep=E42& set type=show& rem %
set name=%name:e41=& set ep=E41& set type=show& rem %
set name=%name:e40=& set ep=E40& set type=show& rem %
set name=%name:e39=& set ep=E39& set type=show& rem %
set name=%name:e38=& set ep=E38& set type=show& rem %
set name=%name:e37=& set ep=E37& set type=show& rem %
set name=%name:e36=& set ep=E36& set type=show& rem %
set name=%name:e35=& set ep=E35& set type=show& rem %
set name=%name:e34=& set ep=E34& set type=show& rem %
set name=%name:e33=& set ep=E33& set type=show& rem %
set name=%name:e32=& set ep=E32& set type=show& rem %
set name=%name:e31=& set ep=E31& set type=show& rem %
set name=%name:e30=& set ep=E30& set type=show& rem %
set name=%name:e29=& set ep=E29& set type=show& rem %
set name=%name:e28=& set ep=E28& set type=show& rem %
set name=%name:e27=& set ep=E27& set type=show& rem %
set name=%name:e26=& set ep=E26& set type=show& rem %
set name=%name:e25=& set ep=E25& set type=show& rem %
set name=%name:e24=& set ep=E24& set type=show& rem %
set name=%name:e23=& set ep=E23& set type=show& rem %
set name=%name:e22=& set ep=E22& set type=show& rem %
set name=%name:e21=& set ep=E21& set type=show& rem %
set name=%name:e20=& set ep=E20& set type=show& rem %
set name=%name:e19=& set ep=E19& set type=show& rem %
set name=%name:e18=& set ep=E18& set type=show& rem %
set name=%name:e17=& set ep=E17& set type=show& rem %
set name=%name:e16=& set ep=E16& set type=show& rem %
set name=%name:e15=& set ep=E15& set type=show& rem %
set name=%name:e14=& set ep=E14& set type=show& rem %
set name=%name:e13=& set ep=E13& set type=show& rem %
set name=%name:e12=& set ep=E12& set type=show& rem %
set name=%name:e11=& set ep=E11& set type=show& rem %
set name=%name:e10=& set ep=E10& set type=show& rem %
set name=%name:e09=& set ep=E09& set type=show& rem %
set name=%name:e08=& set ep=E08& set type=show& rem %
set name=%name:e07=& set ep=E07& set type=show& rem %
set name=%name:e06=& set ep=E06& set type=show& rem %
set name=%name:e05=& set ep=E05& set type=show& rem %
set name=%name:e04=& set ep=E04& set type=show& rem %
set name=%name:e03=& set ep=E03& set type=show& rem %
set name=%name:e02=& set ep=E02& set type=show& rem %
set name=%name:e01=& set ep=E01& set type=show& rem %
set name=%name:e00=& set ep=E00& set type=show& rem %
:: season tags as variables + cut
set name=%name: s00=& set ss=S00& set type=show& rem %
set name=%name: s01=& set ss=S01& set type=show& rem %
set name=%name: s02=& set ss=S02& set type=show& rem %
set name=%name: s03=& set ss=S03& set type=show& rem %
set name=%name: s04=& set ss=S04& set type=show& rem %
set name=%name: s05=& set ss=S05& set type=show& rem %
set name=%name: s06=& set ss=S06& set type=show& rem %
set name=%name: s07=& set ss=S07& set type=show& rem %
set name=%name: s08=& set ss=S08& set type=show& rem %
set name=%name: s09=& set ss=S09& set type=show& rem %
set name=%name: s10=& set ss=S10& set type=show& rem %
set name=%name: s11=& set ss=S11& set type=show& rem %
set name=%name: s12=& set ss=S12& set type=show& rem %
set name=%name: s13=& set ss=S13& set type=show& rem %
set name=%name: s14=& set ss=S14& set type=show& rem %
set name=%name: s15=& set ss=S15& set type=show& rem %
set name=%name: s16=& set ss=S16& set type=show& rem %
set name=%name: s17=& set ss=S17& set type=show& rem %
set name=%name: s18=& set ss=S18& set type=show& rem %
set name=%name: s19=& set ss=S19& set type=show& rem %
set name=%name: s20=& set ss=S20& set type=show& rem %
set name=%name: s21=& set ss=S21& set type=show& rem %
set name=%name: s22=& set ss=S22& set type=show& rem %
set name=%name: s23=& set ss=S23& set type=show& rem %
set name=%name: s24=& set ss=S24& set type=show& rem %
set name=%name: s25=& set ss=S25& set type=show& rem %
set name=%name: s26=& set ss=S26& set type=show& rem %
set name=%name: s27=& set ss=S27& set type=show& rem %
set name=%name: s28=& set ss=S28& set type=show& rem %
set name=%name: s29=& set ss=S29& set type=show& rem %
set name=%name: s30=& set ss=S30& set type=show& rem %
set name=%name:season 1 =& set ss=S01& set type=show& rem %
set name=%name:season 2 =& set ss=S02& set type=show& rem %
set name=%name:season 3 =& set ss=S03& set type=show& rem %
set name=%name:season 4 =& set ss=S04& set type=show& rem %
set name=%name:season 5 =& set ss=S05& set type=show& rem %
set name=%name:season 6 =& set ss=S06& set type=show& rem %
set name=%name:season 7 =& set ss=S07& set type=show& rem %
set name=%name:season 8 =& set ss=S08& set type=show& rem %
set name=%name:season 9 =& set ss=S09& set type=show& rem %
set name=%name:series 1 =& set ss=S01& set type=show& rem %
set name=%name:series 2 =& set ss=S02& set type=show& rem %
set name=%name:series 3 =& set ss=S03& set type=show& rem %
set name=%name:series 4 =& set ss=S04& set type=show& rem %
set name=%name:series 5 =& set ss=S05& set type=show& rem %
set name=%name:series 6 =& set ss=S06& set type=show& rem %
set name=%name:series 7 =& set ss=S07& set type=show& rem %
set name=%name:series 8 =& set ss=S08& set type=show& rem %
set name=%name:series 9 =& set ss=S09& set type=show& rem %
set name=%name:1of=& set ep=E01& set type=show& rem %
set name=%name:2of=& set ep=E02& set type=show& rem %
set name=%name:3of=& set ep=E03& set type=show& rem %
set name=%name:4of=& set ep=E04& set type=show& rem %
set name=%name:5of=& set ep=E05& set type=show& rem %
set name=%name:6of=& set ep=E06& set type=show& rem %
set name=%name:7of=& set ep=E07& set type=show& rem %
set name=%name:8of=& set ep=E08& set type=show& rem %
set name=%name:9of=& set ep=E09& set type=show& rem %
set name=%name:x01=x& set ep=E01& set type=show& rem %
set name=%name:x02=x& set ep=E02& set type=show& rem %
set name=%name:x03=x& set ep=E03& set type=show& rem %
set name=%name:x04=x& set ep=E04& set type=show& rem %
set name=%name:x05=x& set ep=E05& set type=show& rem %
set name=%name:x06=x& set ep=E06& set type=show& rem %
set name=%name:x07=x& set ep=E07& set type=show& rem %
set name=%name:x08=x& set ep=E08& set type=show& rem %
set name=%name:x09=x& set ep=E09& set type=show& rem %
set name=%name:x10=x& set ep=E10& set type=show& rem %
set name=%name:01x=& set ss=S01& set type=show& rem %
set name=%name:02x=& set ss=S02& set type=show& rem %
set name=%name:03x=& set ss=S03& set type=show& rem %
set name=%name:04x=& set ss=S04& set type=show& rem %
set name=%name:05x=& set ss=S05& set type=show& rem %
set name=%name:06x=& set ss=S06& set type=show& rem %
set name=%name:07x=& set ss=S07& set type=show& rem %
set name=%name:08x=& set ss=S08& set type=show& rem %
set name=%name:09x=& set ss=S09& set type=show& rem %
:: lastly year tags as variables + cut
set name=%name: 1963=& set year=1963& if not defined type set type=film& rem %
set name=%name: 1964=& set year=1964& if not defined type set type=film& rem %
set name=%name: 1965=& set year=1965& if not defined type set type=film& rem %
set name=%name: 1966=& set year=1966& if not defined type set type=film& rem %
set name=%name: 1967=& set year=1967& if not defined type set type=film& rem %
set name=%name: 1968=& set year=1968& if not defined type set type=film& rem %
set name=%name: 1969=& set year=1969& if not defined type set type=film& rem %
set name=%name: 1970=& set year=1970& if not defined type set type=film& rem %
set name=%name: 1971=& set year=1971& if not defined type set type=film& rem %
set name=%name: 1972=& set year=1972& if not defined type set type=film& rem %
set name=%name: 1973=& set year=1973& if not defined type set type=film& rem %
set name=%name: 1974=& set year=1974& if not defined type set type=film& rem %
set name=%name: 1975=& set year=1975& if not defined type set type=film& rem %
set name=%name: 1976=& set year=1976& if not defined type set type=film& rem %
set name=%name: 1977=& set year=1977& if not defined type set type=film& rem %
set name=%name: 1978=& set year=1978& if not defined type set type=film& rem %
set name=%name: 1979=& set year=1979& if not defined type set type=film& rem %
set name=%name: 1980=& set year=1980& if not defined type set type=film& rem %
set name=%name: 1981=& set year=1981& if not defined type set type=film& rem %
set name=%name: 1982=& set year=1982& if not defined type set type=film& rem %
set name=%name: 1983=& set year=1983& if not defined type set type=film& rem %
set name=%name: 1984=& set year=1984& if not defined type set type=film& rem %
set name=%name: 1985=& set year=1985& if not defined type set type=film& rem %
set name=%name: 1986=& set year=1986& if not defined type set type=film& rem %
set name=%name: 1987=& set year=1987& if not defined type set type=film& rem %
set name=%name: 1988=& set year=1988& if not defined type set type=film& rem %
set name=%name: 1989=& set year=1989& if not defined type set type=film& rem %
set name=%name: 1990=& set year=1990& if not defined type set type=film& rem %
set name=%name: 1991=& set year=1991& if not defined type set type=film& rem %
set name=%name: 1992=& set year=1992& if not defined type set type=film& rem %
set name=%name: 1993=& set year=1993& if not defined type set type=film& rem %
set name=%name: 1994=& set year=1994& if not defined type set type=film& rem %
set name=%name: 1995=& set year=1995& if not defined type set type=film& rem %
set name=%name: 1996=& set year=1996& if not defined type set type=film& rem %
set name=%name: 1997=& set year=1997& if not defined type set type=film& rem %
set name=%name: 1998=& set year=1998& if not defined type set type=film& rem %
set name=%name: 1999=& set year=1999& if not defined type set type=film& rem %
set name=%name: 2000=& set year=2000& if not defined type set type=film& rem %
set name=%name: 2001=& set year=2001& if not defined type set type=film& rem %
set name=%name: 2002=& set year=2002& if not defined type set type=film& rem %
set name=%name: 2003=& set year=2003& if not defined type set type=film& rem %
set name=%name: 2004=& set year=2004& if not defined type set type=film& rem %
set name=%name: 2005=& set year=2005& if not defined type set type=film& rem %
set name=%name: 2006=& set year=2006& if not defined type set type=film& rem %
set name=%name: 2007=& set year=2007& if not defined type set type=film& rem %
set name=%name: 2008=& set year=2008& if not defined type set type=film& rem %
set name=%name: 2009=& set year=2009& if not defined type set type=film& rem %
set name=%name: 2010=& set year=2010& if not defined type set type=film& rem %
set name=%name: 2011=& set year=2011& if not defined type set type=film& rem %
set name=%name: 2012=& set year=2012& if not defined type set type=film& rem %
set name=%name: 2013=& set year=2013& if not defined type set type=film& rem %
set name=%name: 2014=& set year=2014& if not defined type set type=film& rem %
set name=%name: 2015=& set year=2015& if not defined type set type=film& rem %
set name=%name: 2016=& set year=2016& if not defined type set type=film& rem %
set name=%name: 2017=& set year=2017& if not defined type set type=film& rem %
set name=%name: 2018=& set year=2018& if not defined type set type=film& rem %
set name=%name: 2019=& set year=2019& if not defined type set type=film& rem %
set name=%name: 2020=& set year=2020& if not defined type set type=film& rem %
set name=%name: 2021=& set year=2021& if not defined type set type=film& rem %
set name=%name: 2022=& set year=2022& if not defined type set type=film& rem %
set name=%name: 2023=& set year=2023& if not defined type set type=film& rem %
set name=%name: 2024=& set year=2024& if not defined type set type=film& rem %
set name=%name: 2025=& set year=2025& if not defined type set type=film& rem %
set name=%name: 2026=& set year=2026& if not defined type set type=film& rem %
set name=%name: 2027=& set year=2027& if not defined type set type=film& rem %
set name=%name: 2028=& set year=2028& if not defined type set type=film& rem %
set name=%name: 2029=& set year=2029& if not defined type set type=film& rem %
set name=%name: 2030=& set year=2030& if not defined type set type=film& rem %
:: capitalize
set name=%name:a=A%
set name=%name:b=B%
set name=%name:c=C%
set name=%name:d=D%
set name=%name:e=E%
set name=%name:f=F%
set name=%name:g=G%
set name=%name:h=H%
set name=%name:i=I%
set name=%name:j=J%
set name=%name:k=K%
set name=%name:l=L%
set name=%name:m=M%
set name=%name:n=N%
set name=%name:o=O%
set name=%name:p=P%
set name=%name:q=Q%
set name=%name:r=R%
set name=%name:s=S%
set name=%name:t=T%
set name=%name:u=U%
set name=%name:v=V%
set name=%name:w=W%
set name=%name:x=X%
set name=%name:y=Y%
set name=%name:z=Z%
set name=%name:ä=Ä%
set name=%name:ö=Ö%
答案 0 :(得分:1)
@ECHO OFF
SETLOCAL enabledelayedexpansion
:: precautions
:: cd /d d:\videos\series
:: if /i not "%cd%"=="d:\videos\series" echo invalid series dir. && exit /b
:: if not exist "pilot episodes" echo pilot episodes dir missing. && exit /b
::if not exist "d:\other\scripts\lootname.cmd" echo lootname missing. && exit /b
(
FOR /f "delims=" %%g IN ('dir /s/b /a-d *.mp4 *.mkv *.m4v *.avi *.flv *.mpg *.mpeg *.mpe *.wmv *.mov *.ts *.m2ts *.vob *.3gp *.rm') DO (
rem CALL d:\other\scripts\lootname.cmd %1 data
CALL :extract "%%~ng"
ECHO !name!*%%g
)
)>tempfile.txt
ECHO zzzzzzzzz*zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz>>tempfile.txt
:: File has format extractedname*fullname
SET "lastname="
SET "pilot="
(
FOR /f "tokens=1*delims=*" %%g IN ('sort tempfile.txt') DO (
IF /i "%%g"=="!lastname!" (
REM more than one entry with same extractedname
IF DEFINED pilot (
REM first episode found - directory to be created
IF NOT EXIST "%%g" ECHO MD "%cd%\%%g"
REM move pilot to the directory if required
IF /i "!pilotdir!" neq "%cd%\%%g\" ECHO MOVE "!pilot!" "%cd%\%%g\"
REM done with pilot
SET "pilot="
)
IF /i "%%~dph" neq "%cd%\%%g\" ECHO MOVE "%%h" "%cd%\%%g\"
) ELSE (
REM first occurrence of extractedname
IF DEFINED pilot (
REM pilot following pilot - only pilot
IF /i "!pilotdir!" neq "%cd%\PILOT EPISODES\" ECHO MOVE "!pilot!" "%cd%\PILOT EPISODES\"
)
SET "pilot=%%h"
SET "pilotdir=%%~dph"
SET "lastname=%%g"
)
)
)>whattodo.bat
ENDLOCAL
GOTO :eof
有趣的运动。
上述代码的注意事项:
我已经评论了所有预防措施,因为它们不适用于我的系统。
我假设d:\other\scripts\lootname.cmd %1 data
将建立一个名为name
的变量,具体取决于提供的文件名。我将一个例程替换为名为:extract
的测试,并将其简单地传递给文件名的名称部分。当然,您的%1
也需要更改。
我没有对包含!
等已知批处理错误的文件名进行任何测试。
我认为找到的任何返回唯一[series]name
的文件都是试用版。
所以 - 首先,进行完整的目录扫描并创建一个包含格式为seriesname*fullfilename
的行的文件 - 注意分隔符*
是无效的文件名字符。
现在以此格式获取此列表,对其进行排序并调用第二个for
例程。 for
会将系列名称指定为%%g
,将完整文件名指定给%%h
。该文件将由一系列行PEEEPEPEEPPEE
组成,其中P
是" pilot" - 系列名称更改的位置。
所以 - 如果%%g
与之前的%%g
不同,那么我们有一个新的试用版,所以请保存其系列名称和完整文件名以及完整文件名的目录部分(因为它&#39) ;当时很容易访问)。
如果我们接下来在同一系列中有一集,%%g
会匹配,所以我们"创建"如果目标目录不存在并且"移动" '飞行员'文件名在那里(如果它还没有在正确的目录中)那么我们已经完成了这个试验,所以清除了变量pilot
(所以move
没有被重复)。最后,将剧集移至目录。
如果我们有下一个系列的飞行员,那么实际上我们会做同样的事情,但是如果已经设置pilot
,那么我们需要将其移动到pilot episodes
目录(如果它不是单身人士。
当文件列表用完时,我们可以只留下一个试播剧集(即列表中的最后一个是仅限试播的)。要克服这一点,只需使用z
分隔符添加所有 - *
的虚拟记录。这将排在最后,似乎是一个新的系列名称zzzzz ...我们可以忽略它,因为它是一个虚拟的。
然后弹出一个文件whattodo.bat
,其中包含执行该任务所需的move
和md
。
现在 - 如果您要将所有move
更改为call chkmove
,则可以编写例程来检查移动是否成功。与md
s相同的想法。
哦 - 顺便说一句:批处理开头的单个@echo off
将使所有@
多余。 @
仅表示don't echo this instruction
[替换名称提取程序]
if "%~2"=="data" call :data "%~n1" data & ECHO processed %1 & exit /b
@cd /d "%~dp1"
@if not "%cd%\"=="%~dp1" echo dir %~dp1 not found && exit /b
:: detect extras (from path) and rename to include movie name from parent folder
:: bug: this puts double "making of " to beginning of the first file for some reason.
@echo %1 | find /i "extras" >nul && call :data %2
@echo %1 | find /i "featurettes" >nul && call :data %2
@echo %1 | find /i "extras" >nul && ren %1 "Making of %name% - %~nx1" && exit /b
@echo %1 | find /i "featurettes" >nul && ren %1 "Making of %name% - %~nx1" && exit /b
:: regular job start (show and film only)
@call :data "%~n1"
@if "%type%"=="misc" echo unable to rename without tags "%~n1" && exit /b
@echo "%name%" | find /i "ancient aliens" >nul && echo %~n1 can't be renamed automatically && exit /b
@echo "%name%" | find /i "impractical jokers" >nul && echo %~n1 can't be renamed automatically && 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%
@md "%tempdir%" && @copy /y nul "%tempdir%\%~nx1" >nul
:: variables (to shorten lines)
@set fb=c:\progra~1\filebot\filebot
@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
@%fb% -rename "%tempdir%\%~nx1" --q "%name% %year%" %cf% >nul 2>nul
@for /r "%tempdir%" %%i in (*) do @set "new=%%~ni"
@if "%~n1"=="%new%" echo rename manually "%~n1" && exit /b
:: if as expected rename for real
@if "%type%"=="film" echo %%new:^&=^^^&%% | findstr /i /b /c:"%name% (%year%)" >nul && @goto 4real
@if "%type%"=="show" if not "%year%"=="" echo %%new:^&=^^^&%% | findstr /i /b /c:"%name% (%year%) %ss%%ep%" >nul && @goto 4real
@if "%type%"=="show" if "%year%"=="" echo %%new:^&=^^^&%% | findstr /i /b /c:"%name% %ss%%ep%" >nul && @goto 4real
@echo rename "%~n1" failed && exit /b
@exit /b
:4real
@%fb% -rename %1 --q "%name% %year%" %cf% >nul 2>nul
@if not exist %1 echo successfully renamed "%~n1"
@exit /b
:: =============================================================================================================================
:: FROM FILENAME EXTRAPOLATE NAME AND POSSIBLE YEAR OR SEASON AND EPISODE PLUS DETERMINE TYPE AS SHOW, FILM OR MISC.
:: =============================================================================================================================
:data
set ss=
set ep=
set year=
set type=misc
set name=%~1
:: sanitize
set name=%name:.= %
set name=%name:_= %
set name=%name: - Copy.=.%
set name=%name: - = %
set name=%name: (original)=%
set name=%name:(1)=%
set name=%name:(2)=%
set name=%name:[1]=%
set name=%name:[2]=%
set name=%name:(=%
set name=%name:)=%
set name=%name:[=%
set name=%name:]=%
set name=%name:pbs =%
set name=%name:bbc =%
set name=%name: the series=%
set name=%name: = %
:: detect type
echo %1 | FINDSTR /i /L "203 202 201 200 199 198 197 196" >nul&& set type=film
echo %1 | FINDSTR /i /L "0of 1of 2of 3of 4of 5of 6of 7of 8of 9of 0of" >nul&& set type=show
:: episode tags as variables + cut %
SETLOCAL enabledelayedexpansion
FOR /L %%e IN (199,-1,10 ) 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 (9,-1,1 ) 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:%%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
)
SET "modname=!name:0%%ex=!"
IF "!modname!" neq "%name%" (
SET "setcmd=set name=!name:0%%ex=& set ep=E0%%e& set type=show& rem !"
GOTO gotep
)
)
ENDLOCAL
GOTO skipep
:gotep
%setcmd%
ENDLOCAL &SET name=%name%&SET type=%type%&SET ep=%ep%
:skipep
:: ss tags as variables + cut
SETLOCAL enabledelayedexpansion
FOR /L %%e IN (30,-1,10 ) 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 (9,-1,1 ) DO (
SET "modname=!name:S0%%e=!"
IF "!modname!" neq "%name%" (
SET "setcmd=set name=!name:S0%%e=& set ep=S0%%e& set type=show& rem !"
GOTO gotss
)
)
ENDLOCAL
GOTO skipss
:gotss
%setcmd%
ENDLOCAL &SET name=%name%&SET type=%type%&SET ss=%ss%
:skipss
:: year tags as variables + cut
SETLOCAL enabledelayedexpansion
FOR /L %%e IN (1963,1,2030) DO (
SET "modname=!name:%%e=!"
IF "!modname!" neq "%name%" (
SET "setcmd=set name=!name:%%e=& set year=%%e& rem !"
GOTO gotyear
)
)
ENDLOCAL
GOTO skipyear
:gotyear
%setcmd%
ENDLOCAL &SET name=%name%&SET year=%year%
:skipyear
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%
set name=%name:ä=Ä%
set name=%name:ö=Ö%
GOTO :eof
注意:我只更改了名称提取部分。
评论:您需要在-copy.
之前清理-
。按照目前的情况,-
将首先删除,因此永远不会找到- copy.
。
首先,findstr
允许您找到一系列字符串的任何成员,因此这应该只执行findstr
两次。由于它(和find
)是一个外部例程,因此使用起来很慢 - 因此,毫无疑问,性能会受到影响。
请注意,逻辑将提供年度数字,将type
设置为film
(此时)
下一步 - 分析E ???通过使用delayedexpansion
,它可以提供一组值 - 在E
情况下,199..10 - 并通过检查替换是否有效,构造奇怪的{{1 }指令(我之前没有见过 - 而且我并不确定我喜欢它,但似乎有效......)并且一旦确定,set
循环,因为检查剩余的可能性是愚蠢的。
使用goto
,如果循环退出而没有匹配,请在9..1中使用ep
再次尝试E0?
,然后使用?
{{1} }和?of
,根据需要构建和退出。
如果它完成所有这些操作,则不会找到ep数据,因此只需跳到下一个处理块,因为x0?
未知。由于我们没有做出任何改变,我们可以简单地0?x
来控制setlocal / endlocal帧堆栈。
如果我们提前退出循环,我们已找到所需的值,请执行ep
中的命令,该命令将设置endlocal
,setcmd
和{{1}适当的。由于我们希望保留这些更改,因此我们使用解析技巧来执行此操作 - name
后面是看似冗余的type
命令。所有这些都在同一物理行上非常重要,因为ep
将解析其当前值的赋值,然后执行endlocal
(删除自{{{}}以来对变量所做的更改1}})和然后将变量分配回set
之前的值。
其余部分更相同,但使用不同的关键字符序列。
最后,大写例程使用 search-for-me 字符在set-with-substitution语句中不区分大小写的事实,尽管替换是文字的。
所以 - 有趣的运动。
另一个修订
cmd
这一次,我删除了所有endlocal
处理,这是setlocal
问题的根本原因,并移动了以前依赖{{1}的所有处理1}}进入子程序。这仅仅是为了处理endlocal
问题。我记得你也遇到了@ECHO OFF
SETLOCAL
SET "sourcedir=U:\sourcedir"
SET "tempfile=%temp%\somename"
SET "categories="rock music" music conspiracies"
REM SET "categories=conspiracies music"
:: set up sorting categories
SET "sortingcategories="
FOR %%a IN (%categories%) DO CALL :addsc %%a
SET "sortingcategories=%sortingcategories: =_%"
:: Create "tempfile" containing lines of name|sortingcategory|weight
(
FOR /f "tokens=1,2,*delims=," %%s IN (q45196316.txt) DO (
CALL :findfiles "%%s" "%%t" "%%u"
)
)>"%tempfile%"
SET "lastname="
SORT "%tempfile%">"%tempfile%.s"
FOR /f "usebackqtokens=1,2,3delims=|" %%a IN ("%tempfile%.s") DO (
CALL :resolve %%b %%c "%%a"
)
:: and the last entry...
CALL :resolve dummy 0
GOTO :EOF
:: resolve by totalling weights (%2) in sortingcategories (%1)
:: for each name (%3)
:resolve
IF "%~3" equ "%lastname%" GOTO accum
:: report and reset accumulators
IF NOT DEFINED lastname GOTO RESET
SET "winner=none"
SET /a maxfound=0
FOR %%v IN (%sortingcategories%) DO CALL :findmax %%v
ECHO %winner:_= % %lastname:&=and%
:RESET
FOR %%v IN (%sortingcategories%) DO SET /a $%%v=0
SET "lastname=%~3"
:accum
SET /a $%1+=%2
GOTO :eof
:findmax
FOR /f "tokens=1,2delims=$=" %%w IN ('set $%1') DO IF %%x gtr %maxfound% (
SET "winner=%1"
SET /a maxfound=%%x
)
GOTO :eof
:: add sorting category
:addsc
SET "sortingcategories=%sortingcategories%,%~1"
GOTO :eof
:: Find all files matching %3.
:: They are in category %1 and have weight %2
:findfiles
SET "sortingcategory=%~1"
SET "sortingcategory=%sortingcategory: =_%"
FOR /f "delims=" %%a IN (
'dir /b /a-d "%sourcedir%\*%~3*" 2^>nul'
) DO (
ECHO %%a^|%sortingcategory%^|%~2^|%~1^|%~3
)
GOTO :eof
的问题,但无论是理论还是实践,我都无法找到 的任何问题。
答案 1 :(得分:0)
@cd /d d:\videos\series
@if /i not "%cd%"=="d:\videos\series" echo invalid series dir. && exit /b
@if not exist "pilot episodes" echo pilot episodes dir missing. && exit /b
@if not exist "d:\other\scripts\lootname.cmd" echo lootname missing. && exit /b
@for %%i in (*) do @call :processing "%%i"
@exit /b
:processing
@if not exist %1 exit /b
@call d:\other\scripts\lootname.cmd "%~n1" data
:: move if dir exists. perfect.
@if exist "%name%" move %1 "%name%\" >nul && echo "%~dp1%name%\%~nx1" && exit /b
:: new. find and count possible others.
@set "count=0" & set "dots=%name: =.%"
@for %%i in ("%name% s*" "%dots%.s*") do @set /a count+=1
@for /r "pilot episodes" %%i in ("%name% s*" "%dots%.s*") do @set /a count+=1
:: move if single, pilot
@if "%count%"=="0" echo fatar error while pairing "%name%" && exit /b
@if "%count%"=="1" echo %1 | find /i "01e01" >nul && move %1 "pilot episodes\" >nul && echo "%~dp1pilot episodes\%~nx1" && exit /b
:: move set to new folder
@mkdir "%name%"
@for /r %%i in ("%name% s*" "%dots%.s*") do @move "%%i" "%name%\" >nul
@dir /s /b "%name%"
这只做了极少量的工作,似乎做得很准确(根据非常基本的测试)。很抱歉使用@
,我喜欢这样,所以当出现错误时,我只能启用我怀疑该错误的部分。