1iJaCk

gifdir.bat

Aug 21st, 2017
303
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 9.29 KB | None | 0 0
  1. ::  By JaCk | DevStable 07/26/2017 | https://pastebin.com/26ezgSpq | gifdir.bat -- uses ffmpeg_gifme.bat [ https://pastebin.com/JGL83SM8 ] to create gifs recursively through a directory tree
  2.  
  3. @echo off && setlocal EnableDelayedExpansion EnableExtensions && (for /f "tokens=1 delims==" %%a in ('set gf_') do set "%%a=") 2>nul 1>nul
  4. @title %~nx0 -- Dr.GIF'd with Gifmei Haurdor
  5. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  6. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  7. ::::::                                                                ::::::
  8.  ::::                        Development Version                       ::::
  9.  ::::                       USE AT YOUR OWN RISK                       ::::
  10. ::::::                                                                ::::::
  11. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  12. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  13.  
  14.  
  15. :::::::::::::::::::::::::::::::::::::::
  16. :: user settings
  17. :::::::::::::::::::::::::::::::::::::::
  18.  
  19. rem :: Default: [undef] :: Type: dir location :: Accepted Values: [relative/absolute path] :: Description: -- hardcoded base directory
  20. set "gf_rpath="
  21.  
  22.  
  23. :::::::::::::::::::::::::::::::::::::::
  24. :: script setttings
  25. :::::::::::::::::::::::::::::::::::::::
  26.  
  27. rem :: Default: .avi .mkv :: Type: space delin list :: Accepted Values: [.ext1 .ext2] :: Description: -- extension list of video files
  28. set "gf_extensions=.avi .mkv .mpg .mpeg .webm .mp4 .ogm .mov .flv .bik"
  29.  
  30. rem :: Default:  true  :: Type: Bi-State Boolean :: Accepted Values: [true/undef] :: Description: -- To dump files needed to be processed in the total counter :: Personal Note :: It helps as a sanity check, especially when doing large quantity of files/directories to have this enabled.
  31. set "gf_dump_pre_process_list=true"
  32.  
  33. rem :: Default:  true  :: Type: Bi-State Boolean :: Accepted Values: [true/undef] :: Description: -- Set windows console encoding env to UTF8 to enable processing of non-latin characters.  Disable if you encounter weird problems with naming.
  34. set "gf_utf8_support=true"
  35.  
  36.  
  37. :::::::::::::::::::::::::::::::::::::::
  38. :: script magic-de-do-dads
  39. :::::::::::::::::::::::::::::::::::::::
  40.  
  41. :: UTF8 support -- Grab current encoding setting - when needed, change it to utf8
  42. if defined gf_utf8_support (
  43.     for /f "tokens=2 delims=:" %%c in ('chcp') do set "gf_chcp_orig=%%c"
  44.  
  45.     if !gf_chcp_orig! neq 65001 (
  46.         chcp 65001 2>nul 1>nul || (
  47.             echo/    ERROR: CHCP: UTF8 Support unavailible
  48.             chcp !gf_chcp_orig! 2>nul 1>nul
  49.             set "gf_chcp_orig="
  50.         )
  51.     ) else (
  52.         set "gf_chcp_orig="
  53.     )
  54. )
  55.  
  56. :: params
  57. if "%~1" neq "" (
  58.     set "gf_rpath=%*"
  59. )
  60.  
  61.  
  62. :: popd like you've never popd before
  63. if !pushme_gf! geq 1 for /l %%P in (1,1,!pushme_gf!) do (
  64.     popd
  65.     echo Info: pushme_gf: [%%P]: Stale Popds found... BAM - Blopd de-Popd-eded
  66.     echo Info: pushme_gf: [%%P]: Current Directory: [!cd!]
  67.     set /a "pushme_gf-=1"
  68. )
  69.  
  70.  
  71. :: prompts
  72. if not defined gf_rpath (
  73.     set "gf_rpath=!cd!"
  74.     echo/&echo/&echo/
  75.     echo/_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  76.     echo/_~_~_~_~_~_~_~_~_~_~_~_~_~_~_~_~_~_~_~_~_
  77.     echo/
  78.     echo/ ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
  79.     echo/  Input: Base Directory Path:
  80.     echo/
  81.     echo/    Default ~^> !gf_rpath!
  82.     echo/   ~-~  ~-~  ~-~  ~-~  ~-~
  83.     set /p "gf_rpath= ~>"
  84.     echo/   ~-~  ~-~  ~-~  ~-~  ~-~
  85.     echo/-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
  86. )
  87.  
  88.  
  89. :: when double-quoted path, remove first and last double-quotes
  90. if defined gf_rpath if "!gf_rpath:~0,1!!gf_rpath:~-1,1!" equ """" set "gf_rpath=!gf_rpath:~1,-1!"
  91.  
  92.  
  93. :: f-u error-checking -- no purdy msgs, just f-u and gtfo
  94. if not defined gf_rpath goto :eof
  95. if not defined gf_extensions goto :eof
  96.  
  97.  
  98. :::::::::::::::::::::::::::::::::::::::
  99. ::
  100. :: Setup Script
  101. ::
  102. :::::::::::::::::::::::::::::::::::::::
  103.  
  104. :: fixing extension list formatting -- make sure [no commas][space-delin][eol regex marker]
  105. for %%X in (!gf_extensions!) do set "gf_ext_li=%%X$ !gf_ext_li!"
  106.  
  107.  
  108. echo/&echo/&echo/&echo/&echo/&echo/
  109. echo/ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  110. echo/-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
  111. echo/ `'` `'` `'` `'` `'` `'` `'` `'` `'` `'`
  112. echo/
  113. if defined gf_dump_pre_process_list (
  114.     echo/ -- GifDir: Info: Fluffing TollTalls and Dumpling filletnames
  115. ) else (
  116.     echo/ -- GifDir: Info: Tallying Gif'd'ed Counts
  117. )
  118. echo/    -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
  119.  
  120.  
  121.  
  122. :: Total Possible files matching extension list
  123. :: for /f "tokens=1* delims=" %%A in ('dir /b /o:-n /a:-d /s "!gf_rpath!" ^| findstr /i "!gf_ext_li!" ^| find /c " "') do set "gf_total_matching_files=%%A"
  124.  
  125. :: For roll call, getting missing Count Gif, He'll be write back
  126. set "gf_total_cnt=0"
  127. for /f "tokens=1* delims=" %%A in ('dir /b /o:-n /a:-d /s "!gf_rpath!" ^| findstr /i "!gf_ext_li!"') do (
  128.     set /a "gf_total_matching_files+=1"
  129.  
  130.     if not exist "%%~dpnA.gif" (
  131.         set /a "gf_total_cnt+=1"
  132.         if defined gf_dump_pre_process_list echo/     [!gf_total_cnt!]: "%%~nxA"
  133.     )
  134. )
  135.  
  136. :: get string length of gf_total_cnt
  137. if !gf_total_cnt! geq 10 (
  138.     set "gf_P=!gf_total_cnt!#"
  139.  
  140.     for %%P in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do (
  141.         if "!gf_P:~%%P,1!" NEQ "" (
  142.             set /a "gf_zcount+=%%P"
  143.             for /l %%q in (1,1,%%P) do set "gf_z=0!gf_z!"
  144.             set "gf_P=!gf_P:~%%P!"
  145.         )
  146.     )
  147. ) else (
  148.     set "gf_zcount=1"
  149.     set "gf_z=0"
  150. )
  151.  
  152.  
  153. :: get string length of gf_total_matching_files
  154. if !gf_total_matching_files! geq 10 (
  155.     set "gf_P=!gf_total_matching_files!#"
  156.  
  157.     for %%P in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do (
  158.         if "!gf_P:~%%P,1!" NEQ "" (
  159.             set /a "gf_bmatchcount+=%%P"
  160.             set "gf_P=!gf_P:~%%P!"
  161.             for /l %%q in (1,1,%%P) do set "gf_mz=0!gf_mz!"
  162.         )
  163.     )
  164. ) else (
  165.     set "gf_bmatchcount=1"
  166.     set "gf_mz=0"
  167. )
  168.  
  169.  
  170. :: pretty colors.... em... I mean... Pretty numbers
  171. :: pad em first :: trim the fat
  172. if defined gf_mz if defined gf_total_cnt if defined gf_bmatchcount (
  173.     set "gf_scount_tl=!gf_mz:0= !!gf_total_cnt!"
  174.     set "gf_scount_tl=!gf_scount_tl:~-%gf_bmatchcount%!"
  175.     set "gf_smatchedf=!gf_mz!!gf_total_matching_files!"
  176.     set "gf_smatchedf=!gf_smatchedf:~-%gf_bmatchcount%!"
  177.  
  178.     rem note - todo - finish making this purdy
  179.     set "gf_empty_wshc=%gf_bmatchcount%"
  180.     set "gf_empty_wspace=       "
  181.     set "gf_empty_wspace=!gf_empty_wspace:~%gf_empty_wshc%!"
  182. )
  183.  
  184. ::    LFM     -- Looking for more; totals
  185. ::   WTBGif   -- Gifs to be created by %~nx0
  186. :: ICanHasGif -- Candidate Files for giffing by %~nx0
  187.  
  188. if not !gf_total_cnt! gtr 0 (
  189.     echo/            No gif-able files found        
  190. )
  191. echo/    -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
  192. if defined gf_smatchedf if defined gf_scount_tl (
  193.     echo/    !gf_empty_wspace!~-~ #  Gif   Needed: !gf_scount_tl! ~-~    !gf_empty_wspace!    
  194.     echo/    !gf_empty_wspace!~-~ # Total Checked: !gf_smatchedf! ~-~    !gf_empty_wspace!    
  195. ) else (
  196.     echo/       !gf_empty_wspace!~-~ Creating [!gf_smatchedf!] Gifs ~-~   !gf_empty_wspace!    
  197. )
  198.     echo/    -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
  199.     echo/
  200.     echo/ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  201.     echo/-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
  202.     echo/ `'` `'` `'` `'` `'` `'` `'` `'` `'` `'`
  203.     echo/
  204. if not !gf_total_cnt! gtr 0 goto :eof
  205.  
  206. :::::::::::::::::::::::::::::::::::::::
  207. ::
  208. :: Main
  209. ::
  210. :::::::::::::::::::::::::::::::::::::::
  211. :: run it
  212. echo/
  213. echo/ -- GifDir: Info: Main: [!date:~0,3! !time:~0,-6!]: Find em n gif-em
  214. echo/    -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
  215.  
  216.  
  217. for /f "tokens=1* delims=" %%A in ('dir /b /o:-n /a:-d /s "!gf_rpath!" ^| findstr /i "!gf_ext_li!"') do (
  218.     if "!cd!\" neq "%%~dpA" (
  219.         popd
  220.         set /a "pushme_gf-=1"
  221.        
  222.         pushd "%%~dpA"
  223.         set /a "pushme_gf+=1"
  224.         set "gf_dpush_msg=true"
  225.     )
  226.  
  227.     if exist "%%~nxA" if not exist "%%~nA.gif" (
  228.         set /a "gf_current_cnt+=1"
  229.         set /a "gf_count_perc=!gf_current_cnt!00 / !gf_total_cnt!"
  230.         set "gf_count_perc=!gf_count_perc!%%"
  231.         set "gf_zcurrent_cnt=!gf_z!!gf_current_cnt!"
  232.         set "gf_zcurrent_cnt=!gf_zcurrent_cnt:~-%gf_zcount%!"
  233.    
  234.         echo/
  235.         if defined gf_dpush_msg (
  236.             echo/
  237.             echo/ -- GifDir: Pushd Dir: "%%~dpA"
  238.             set "gf_dpush_msg="
  239.         )
  240.  
  241.         echo/ -- GifDir[!gf_count_perc!] !time:~0,-6!: File: !gf_zcurrent_cnt!/!gf_total_cnt! ~ "%%~nxA"
  242.         call ffmpeg_gifme.bat "%%~nxA" "%%~nA.gif" "%%~nA.palette.png"
  243.        
  244.         if exist "%%~nA.gif" call attrib +H /S /D /L "%%~nA.gif"
  245.         if exist "%%~nA.palette.png" call attrib +H /S /D /L "%%~nA.palette.png"
  246.     )
  247. )
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255. :::::::::::::::::::::::::::::::::::::::
  256. ::
  257. :: Destroy env changes made by me
  258. ::
  259. :::::::::::::::::::::::::::::::::::::::
  260. :: Last minute popd-ing (when you gotta go, you go), setting up blanks (better than shooting em), and ending any local relationships (its not you, its me)
  261. if defined pushme_gf for /l %%p in (1,1,!pushme_gf!) do ( call popd && set /a "pushme_gf-=1" )
  262. if !pushme_gf! leq 0 set "pushme_gf=
  263.  
  264. if defined gf_chcp_orig chcp !gf_chcp_orig! 1>nul
  265.  
  266. (for /f "tokens=1 delims==" %%a in ('set gf_') do set "%%a=") 2>nul 1>nul
  267. endlocal
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment