Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2013
527
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 15.58 KB | None | 0 0
  1. @echo off
  2. cls
  3. setlocal
  4. echo -------------------------------------------------------------------------------
  5. echo I Quickly create thumbnails for your Synology DiskStation                     I
  6. echo I                                                                             I
  7. echo I created by Olaf Noehring, http://www.team-noehring.de                       I
  8. echo I version: 2012-09-17, v25a                                                   I
  9. echo -------------------------------------------------------------------------------
  10. echo.
  11. echo Edit/adjust the values in the Configuration area of this file only!
  12. echo.
  13. echo If you have special characters in your file-/pathnames (e.g. öäüß) the irfanview 4.33 version will stop working because it can not access the correct file/path! I have contacted Irfan (the irfanview programmer) about a special commandline parameter for this but have not received an answer.
  14. echo IMPORTANT:
  15. echo.
  16. echo EVEN FASTER:
  17. echo I suggest you set the source to your /photo (or a subdirectory), but the target to a local (on your PC) directory. This will read the image data only once from the network which (this script reads the thumbnails after the creation of the first thumbnail) should for the 2nd...5th thumbnail result in a VERY large speed increase: Files will be read and written from/to local directory = much faster. Afterwards simply transfer (copy) the created @eaDir to your DiskStation.
  18. echo You can start multiple instances - you MUST change the source (obviously).
  19. echo Each instance uses unique names for temporary files and a unique subdir in your target directory.
  20. echo Still: This will make more use of your network capacity in combination with CPU speed as your CPU and network will be more busy at all times.
  21. echo.
  22. echo PS: USE AT YOU OWN RISK!
  23. echo.
  24. pause
  25.  
  26. :: --- Configuration START --->
  27.  
  28. ::
  29. ::CHANGE THIS (1/3)
  30. ::
  31. :: Source folder - Where (probably a mapped drive) are your images (/photo directory)
  32. :: Make sure no special characters (öäüß etc.) are in your foldernames and filenames!
  33. ::Lets assume /photo is accessable from windows with driveletter z:
  34. ::NO trailing (back)slash!, NO quotes!
  35. set source=c:\TEMP\01_Fotos_bearbeiten
  36.  
  37. ::
  38. ::CHANGE THIS TOO (2/3)
  39. ::
  40. :: Target folder - Where should the thumbnails (in @eaDir 's) be  stored? They need to be transfered later using WinSCP for example to the appropiate folder of your DiskStation
  41. ::NO trailing (back)slash!, NO quotes!
  42. set target=c:\TEMP\02_Fotos_erledigt
  43.  
  44. ::
  45. ::FINALLY ADJUST THIS (3/3)
  46. ::
  47. :: IrfanView application directory
  48. ::for my test I used irfanview version 4.33
  49. ::NO trailing (back)slash!, NO quotes!
  50. :: c:\Program Files (x86)\IrfanView\i_view32.exe
  51. :: set iview=c:\programme\irfanview\i_view32.exe
  52. set iview=c:\TEMP\IrfanView\i_view32.exe
  53.  
  54. ::
  55. ::You CAN adjust the settings below - but you do NOT need to!
  56. ::
  57.  
  58. ::Thumbnail sizes
  59. ::This should probably match the settings of your DiskStation
  60. set sizeXL=1280
  61. set sizeL=800
  62. set sizeB=640
  63. set sizeM=320
  64. set sizeS=120
  65.  
  66. :: JPG compression Mode
  67. :: set jpgq=82
  68.  
  69. :: JPG compression Mode
  70. set jpgqB=81
  71.  
  72. :: JPG compression Mode
  73. set jpgqM=86
  74.  
  75. :: JPG compression Mode
  76. set jpgqS=45
  77.  
  78.  
  79. :: JPG compression XL Bild
  80. set jpgqXL=93
  81.  
  82.  
  83. ::Extra quality? You can use "/resample" or just leave it empty!
  84. rem set extraquality=
  85. set extraquality=/resample
  86.  
  87. :: <--- Configuration END ---
  88. ::
  89. :: DO NOT change below! (except you know what you are doing)
  90. ::
  91.  
  92. ::Create uniquefilenames with a random number!
  93. ::%random% is a random number between 0 and 32768
  94. ::Number between 1 and 100:
  95. :: set /a randomNumber=%RANDOM% * 100 / 32768 + 1
  96.  
  97. if (%1)==() (
  98.     set /a randomNumber=%RANDOM%
  99. ) else (
  100.     set /a randomNumber=%1
  101. )
  102.    
  103. ::Make the user check the configuration
  104. echo Please check the settings that will be used:
  105. echo.
  106. echo - Source (subdirectories will also be treated):
  107. echo   %source%
  108. echo - Target (unique so you can start this batch file multiple times)(subdirectories will be created):
  109. echo   %target%\%randomNumber%
  110. echo - JPQ quality is (100 = very good ... 10 = very fast): %jpgq%
  111. echo - Extraquality is (NULL = quicker or /resample = better quality): %extraquality%
  112. echo - Sizes (long sides): %sizeXL%, %sizeL%, %sizeB%, %sizeM%, %sizeS%
  113. echo.
  114. echo The following is for information only and can not be changed by the user:
  115. echo - Unique (random) ID of this instance (prefix for filenames): %randomNumber%
  116. echo.
  117. echo If this is correct, please press any key. If this is wrong, stop this script with the keycombination CRTL-C (or STRG-C) right now!
  118. echo.
  119. pause
  120.  
  121. ::Start measuring runtime after the user actually starts the complex process of indexing and converting/creating.
  122. ::Measure script time 1/2
  123. set start=%time%
  124. set startTotal=%start%
  125. ::Measure script time 1/2 END
  126.  
  127. ::Run progress-meter script
  128. start cmd.exe /c "progress23x.cmd %randomNumber%"
  129.  
  130. ::Generate a fileliste of all jpg files in /photo (your source drive)
  131. :: /S gives us all subdirectories (you might want to be careful as MANY files can result from this
  132. :: /B gives us filenames (with paths) only
  133. echo.
  134. echo -------------------------------------------------------------------------------
  135. set start=%time%
  136. echo Reading JPG files in %source% and it's subdirectories
  137. dir "%source%\*.jpg" /S /B >%randomNumber%_filelist_original.txt
  138. echo.|set /P ="..filelist created in: "
  139. call :OUTPUTTIME
  140.  
  141. ::Count files and calulate how many thumbs will be created, inform the user
  142. echo.
  143. echo -------------------------------------------------------------------------------
  144. echo.|set /P ="Counting files... "
  145. set start=%time%
  146. set _File=%randomNumber%_filelist_original.txt
  147. set /a total_Lines=0
  148. for /f %%j in ('Type %_File%^|Find "" /v /c') do set /a total_Lines=%%j
  149. set /a total_massthumbs=total_Lines*5
  150. echo %total_massthumbs% thumbnails should be created (%total_Lines% files * 5 thumbs each)
  151. echo.|set /P ="..finished in: "
  152. call :OUTPUTTIME
  153. echo (If time-taken is 24+ hours, calculated result will be wrong. Same below.)
  154. echo Now let's start...
  155. ::Count end
  156.  
  157. ::We use the filelist_original.txt to create a batch job for irfanview.
  158. echo.
  159. echo -------------------------------------------------------------------------------
  160. set start=%time%
  161. echo Creating XL version (%sizeXL% / something) thumbs (1 of 5)
  162. echo This step will take the longest time, each of the following will be quicker.
  163. echo Have patience - really! And ... I mean it! Really ... do not stop here - give it time!
  164. "%iview%" /filelist=%randomNumber%_filelist_original.txt /resize_long=%sizeXL% /aspectratio /convert="%target%\%randomNumber%\$D\@eaDir\$F\SYNOPHOTO_THUMB_XL.jpg" /filepattern="*.jpg" /jpgq=%jpgqXL% /silent /cmdexit %extraquality%
  165. echo.|set /P ="..finished in: "
  166. call :OUTPUTTIME
  167.  
  168. ::for the smaller thumbs we search the TARGET (!) directory as we use only the 1280-thumbs to create the smaller (800-thumbs) now.
  169. ::This should save us a lot of calculation power and give us a noticeable speed improvement, especially if your original images have a 1280+ resolution.
  170. ::Of course this might result in (a little) quality loss - but the speed improvement should make this worth.
  171. ::the %3 in the filename (SYNOPHOTO_THUMB_XL) will be transformed on the DiskStation to a colon (:). We need the second % because the Windows commandline (DOS window) would assume this a special character.
  172. echo.
  173. ::  echo -------------------------------------------------------------------------------
  174. ::  set start=%time%
  175. ::  echo Creating L version (%sizeL% / something) thumbs (2 of 5) ... please wait
  176. ::  dir "%target%\%randomNumber%\SYNOPHOTO_THUMB_XL.*" /S /B >%randomNumber%_filelist_xl.txt
  177.  
  178.     ::Count files and calulate how many thumbs will be created, inform the user
  179. ::  echo.|set /P =".counting XL thumbnails... "
  180. ::  set _File=%randomNumber%_filelist_xl.txt
  181. ::  set /a _LinesXL=0
  182. ::  for /f %%j in ('Type %_File%^|Find "" /v /c') Do Set /a _LinesXL=%%j
  183.     ::echo %_LinesXL% found (%total_Lines% expected)
  184. ::  if (%_LinesXL%)==(%total_Lines%) (
  185.         :: everything as expected, it seems no error occured
  186. ::      echo.|set /P ="all %_LinesXL% found"
  187. ::  ) else (
  188. ::      echo.|set /P ="only %_LinesXL% found (%total_Lines% expected)"
  189.     )
  190.     ::Count end
  191. ::  echo.|set /P ="..creating L size "
  192.  
  193. ::  "%iview%" /filelist=%randomNumber%_filelist_xl.txt /resize_long=%sizeL% /aspectratio /convert="$D\SYNOPHOTO_THUMB_L.jpg" /filepattern="*.jpg" /jpgq=%jpgqL% /silent /cmdexit %extraquality%
  194. ::  echo.|set /P ="..finished in: "
  195. ::  call :OUTPUTTIME
  196.  
  197. ::for the smaller thumbs we search the TARGET (!) directory as we use only the 800-thumbs to create the smaller (640-thumbs) now.
  198. echo.
  199. echo -------------------------------------------------------------------------------
  200. set start=%time%
  201. echo Creating B version (%sizeB% / something) thumbs (3 of 5) ... please wait
  202. dir "%target%\%randomNumber%\SYNOPHOTO_THUMB_XL.*" /S /B >%randomNumber%_filelist_xl.txt
  203.  
  204. ::Count files and calulate how many thumbs will be created, inform the user
  205. echo.|set /P =".counting L thumbnails... "
  206. set _File=%randomNumber%_filelist_xl.txt
  207. set /a _LinesL=0
  208. for /f %%j in ('Type %_File%^|Find "" /v /c') Do Set /a _LinesL=%%j
  209. ::echo %_LinesL% found (%total_Lines% expected)
  210. if (%_LinesL%)==(%total_Lines%) (
  211.     :: everything as expected, it seems no error occured
  212.     echo.|set /P ="all %_LinesL% found"
  213. ) else (
  214.     echo.|set /P ="only %_LinesL% found (%total_Lines% expected)"
  215. )
  216. ::Count end
  217. echo.|set /P ="..creating B size "
  218.  
  219. "%iview%" /filelist=%randomNumber%_filelist_xl.txt /resize_long=%sizeB% /aspectratio /convert="$D\SYNOPHOTO_THUMB_B.jpg" /filepattern="*.jpg" /jpgq=%jpgqB% /silent /cmdexit %extraquality%
  220. echo.|set /P ="..finished in: "
  221. call :OUTPUTTIME
  222.  
  223. ::for the smaller thumbs we search the TARGET (!) directory as we use only the 640-thumbs to create the smaller (320-thumbs) now.
  224. echo.
  225. echo -------------------------------------------------------------------------------
  226. set start=%time%
  227. echo Creating M version (%sizeM% / something) thumbs (4 of 5) ... please wait
  228. dir "%target%\%randomNumber%\SYNOPHOTO_THUMB_B.*" /S /B >%randomNumber%_filelist_b.txt
  229.  
  230. ::Count files and calulate how many thumbs will be created, inform the user
  231. echo.|set /P =".counting B thumbnails... "
  232. set _File=%randomNumber%_filelist_b.txt
  233. set /a _LinesB=0
  234. for /f %%j in ('Type %_File%^|Find "" /v /c') Do Set /a _LinesB=%%j
  235. ::echo %_LinesB% found (%total_Lines% expected)
  236. if (%_LinesB%)==(%total_Lines%) (
  237.     :: everything as expected, it seems no error occured
  238.     echo.|set /P ="all %_LinesB% found"
  239. ) else (
  240.     echo.|set /P ="only %_LinesB% found (%total_Lines% expected)"
  241. )
  242. ::Count end
  243. echo.|set /P ="..creating M size "
  244.  
  245. "%iview%" /filelist=%randomNumber%_filelist_b.txt /resize_long=%sizeM% /aspectratio /convert="$D\SYNOPHOTO_THUMB_M.jpg" /filepattern="*.jpg" /jpgq=%jpgqM% /silent /cmdexit %extraquality%
  246. echo.|set /P ="..finished in: "
  247. call :OUTPUTTIME
  248.  
  249.  
  250. ::for the smaller thumbs we search the TARGET (!) directory as we use only the 320-thumbs to create the smaller (120-thumbs) now.
  251. echo.
  252. echo -------------------------------------------------------------------------------
  253. set start=%time%
  254. echo Creating S version (%sizeS% / something) thumbs (5 of 5) ... please wait
  255. dir "%target%\%randomNumber%\SYNOPHOTO_THUMB_M.*" /S /B >%randomNumber%_filelist_m.txt
  256.  
  257. ::Count files and calulate how many thumbs will be created, inform the user
  258. echo.|set /P =".counting M thumbnails... "
  259. set _File=%randomNumber%_filelist_m.txt
  260. set /a _LinesM=0
  261. for /f %%j in ('Type %_File%^|Find "" /v /c') Do Set /a _LinesM=%%j
  262. ::echo %_LinesM% M thumbnails found (%total_Lines% expected)
  263. if (%_LinesM%)==(%total_Lines%) (
  264.     :: everything as expected, it seems no error occured
  265.     echo.|set /P ="all %_LinesM% found"
  266. ) else (
  267.     echo.|set /P ="only %_LinesM% found (%total_Lines% expected)"
  268. )
  269. ::Count end
  270. echo.|set /P ="..creating S size "
  271.  
  272. "%iview%" /filelist=%randomNumber%_filelist_m.txt /resize_long=%sizeS% /aspectratio /convert="$D\SYNOPHOTO_THUMB_S.jpg" /filepattern="*.jpg" /jpgq=%jpgqS% /silent /cmdexit %extraquality%
  273.  
  274. ::Finally count S thumbs
  275. dir "%target%\%randomNumber%\SYNOPHOTO_THUMB_S.*" /S /B >%randomNumber%_filelist_s.txt
  276. ::Count files and calulate how many thumbs will be created, inform the user
  277. echo.|set /P =".counting S thumbnails (final count)... "
  278. set _File=%randomNumber%_filelist_s.txt
  279. set /a _LinesS=0
  280. for /f %%j in ('Type %_File%^|Find "" /v /c') Do Set /a _LinesS=%%j
  281. ::echo %_LinesS% found (%total_Lines% expected)
  282. if (%_LinesS%)==(%total_Lines%) (
  283.     :: everything as expected, it seems no error occured
  284.     echo.|set /P ="all %_LinesS% found"
  285. ) else (
  286.     echo.|set /P ="only %_LinesS% found (%total_Lines% expected)"
  287. )
  288. ::Count end
  289. echo.|set /P ="..finished in: "
  290. call :OUTPUTTIME
  291.  
  292.  
  293. ::Inform user about cleanup (remove temporary files
  294. echo.
  295. echo -------------------------------------------------------------------------------
  296. echo.|set /P ="Cleaning up (removing temporary files)... "
  297. ::echo .. deleting temporary filelist_original.txt
  298. del %randomNumber%_filelist_original.txt
  299. ::echo .. deleting temporary filelist_xl.txt
  300. del %randomNumber%_filelist_xl.txt
  301. ::echo .. deleting temporary filelist_l.txt
  302. del %randomNumber%_filelist_l.txt
  303. ::echo .. deleting temporary filelist_b.txt
  304. del %randomNumber%_filelist_b.txt
  305. ::echo .. deleting temporary filelist_m.txt
  306. del %randomNumber%_filelist_m.txt
  307. ::echo .. deleting temporary filelist_s.txt
  308. del %randomNumber%_filelist_s.txt
  309.  
  310. ::Show Progress, END progress now - START
  311. del %randomNumber%_tmp_payload.flg
  312. ::Show Progress, END progress now - END
  313. echo done
  314.  
  315. ::Output statistics
  316. set /a created_thumbs=_LinesXL+_LinesL+_LinesB+_LinesM+_LinesS
  317. echo.
  318. echo -------------------------------------------------------------------------------
  319. echo.
  320. echo Thumbnails of your %total_Lines% images in %source% (and it's subdirectories) should have been created (with quality: %jpgq%).
  321. echo Size  :  Count
  322. echo -----------------
  323. echo %sizeXL%  :  %_LinesXL%
  324. echo %sizeL%   :  %_LinesL%
  325. echo %sizeB%   :  %_LinesB%
  326. echo %sizeM%   :  %_LinesM%
  327. echo %sizeS%   :  %_LinesS%
  328. echo.
  329. echo Total : %created_thumbs%
  330. if (%created_thumbs%)==(%total_massthumbs%) (
  331.     echo Everything seems all right
  332. ) else (
  333.     echo Error?! Mismatch of expected and created thumbs!
  334.     echo It should have been: %total_massthumbs%!
  335.     echo One or more errors occured. Probably cause: Special characters exist in folder- and filenames! You may rename directories and files before, rename them back afterwards - this should avoid the error.
  336.  )
  337. echo.
  338. echo Your results are in %target%\%randomNumber% (and it's subdirectories)
  339. echo.
  340. echo.|set /P ="Complete conversion took: "
  341. set start=%startTotal%
  342. call :OUTPUTTIME
  343. echo.
  344. echo.
  345. echo.
  346. echo.
  347.  
  348. goto END
  349.  
  350.  
  351. :OUTPUTTIME
  352. ::Measure script time 2/2
  353. ::source: http://stackoverflow.com/questions/673523/how-to-measure-execution-time-of-command-in-windows-command-line
  354. set end=%time%
  355. set options="tokens=1-4 delims=:."
  356. for /f %options% %%a in ("%start%") do set start_h=%%a&set /a start_m=100%%b %% 100&set /a start_s=100%%c %% 100&set /a start_ms=100%%d %% 100
  357. for /f %options% %%a in ("%end%") do set end_h=%%a&set /a end_m=100%%b %% 100&set /a end_s=100%%c %% 100&set /a end_ms=100%%d %% 100
  358.  
  359. set /a hours=%end_h%-%start_h%
  360. set /a mins=%end_m%-%start_m%
  361. set /a secs=%end_s%-%start_s%
  362. set /a ms=%end_ms%-%start_ms%
  363. if %hours% lss 0 set /a hours = 24%hours%
  364. if %mins% lss 0 set /a hours = %hours% - 1 & set /a mins = 60%mins%
  365. if %secs% lss 0 set /a mins = %mins% - 1 & set /a secs = 60%secs%
  366. if %ms% lss 0 set /a secs = %secs% - 1 & set /a ms = 100%ms%
  367. if 1%ms% lss 100 set ms=0%ms%
  368.  
  369. :: mission accomplished
  370. set /a totalsecs = %hours%*3600 + %mins%*60 + %secs%
  371. echo %hours%:%mins%:%secs%.%ms% (%totalsecs%.%ms%s total)
  372. ::Measure script time 2/2 END
  373. goto :EOF
  374.  
  375.  
  376. :END
  377.  
  378. endlocal
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement