Advertisement
RealBUZZARD

Untitled

Oct 12th, 2022 (edited)
1,511
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.45 KB | None | 0 0
  1. @echo off
  2. title 0/0 ^(0/100%%^)
  3.  
  4. setlocal EnableDelayedExpansion
  5.  
  6. set "CHANNEL=%1"
  7.  
  8. if exist "images\!CHANNEL!\" (
  9.     del /q "images\!CHANNEL!"
  10. ) else (
  11.     md "images\!CHANNEL!"
  12. )
  13. set /a counter=0, counted=0, percentage=0
  14. for /f "usebackq delims=" %%A in ("!CHANNEL!") do (
  15.     set /a counter+=1
  16. )
  17. for /f "usebackq delims=" %%A in ("!CHANNEL!") do (
  18.     set /a counted+=1, percentage=counted*100/counter
  19.     set "image_url=%%~A"
  20.     set "image_name_extension=%%~nxA"
  21.     call :CREATE_IMAGE
  22. )
  23.  
  24. endlocal
  25. exit /b 0
  26.  
  27. :CREATE_IMAGE
  28. if exist "images\!CHANNEL!\!image_name_extension!" (
  29.     call :FORM_VALID_FILE_NAME image_name_extension
  30. )
  31. curl -fks -o "images\!CHANNEL!\!image_name_extension!" "!image_url!" || (
  32.     call :ERROR "Downloading, or creating the image failed." || (
  33.         exit /b 0
  34.     )
  35. )
  36. title !counted!/!counter! ^(!percentage!/100%%^)
  37. exit /b 0
  38.  
  39. :FORM_VALID_FILE_NAME
  40. for %%A in (name ext) do (
  41.     if defined %%A (
  42.         set %%A=
  43.     )
  44. )
  45. set try=0
  46. for %%A in ("!%1!") do (
  47.     set "name=%%~nA"
  48.     set "ext=%%~xA"
  49. )
  50. :_FORM_VALID_FILE_NAME
  51. set /a try+=1
  52. if exist "images\!CHANNEL!\!name! (!try!)!ext!" (
  53.     goto :_FORM_VALID_FILE_NAME
  54. )
  55. set "%1=!name! (!try!)!ext!"
  56. exit /b
  57.  
  58. :ERROR
  59. echo ERROR: %~1 (!errorlevel!)
  60. echo image_url: "!image_url!"
  61. echo image_url: "!image_name_extension!"
  62. echo:
  63. ::<nul set /p="Do you want to continue the script execution anyways? [Y/N] : "
  64. ::choice /n /c YN
  65. exit /b 0
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement