Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- title 0/0 ^(0/100%%^)
- setlocal EnableDelayedExpansion
- set "CHANNEL=%1"
- if exist "images\!CHANNEL!\" (
- del /q "images\!CHANNEL!"
- ) else (
- md "images\!CHANNEL!"
- )
- set /a counter=0, counted=0, percentage=0
- for /f "usebackq delims=" %%A in ("!CHANNEL!") do (
- set /a counter+=1
- )
- for /f "usebackq delims=" %%A in ("!CHANNEL!") do (
- set /a counted+=1, percentage=counted*100/counter
- set "image_url=%%~A"
- set "image_name_extension=%%~nxA"
- call :CREATE_IMAGE
- )
- endlocal
- exit /b 0
- :CREATE_IMAGE
- if exist "images\!CHANNEL!\!image_name_extension!" (
- call :FORM_VALID_FILE_NAME image_name_extension
- )
- curl -fks -o "images\!CHANNEL!\!image_name_extension!" "!image_url!" || (
- call :ERROR "Downloading, or creating the image failed." || (
- exit /b 0
- )
- )
- title !counted!/!counter! ^(!percentage!/100%%^)
- exit /b 0
- :FORM_VALID_FILE_NAME
- for %%A in (name ext) do (
- if defined %%A (
- set %%A=
- )
- )
- set try=0
- for %%A in ("!%1!") do (
- set "name=%%~nA"
- set "ext=%%~xA"
- )
- :_FORM_VALID_FILE_NAME
- set /a try+=1
- if exist "images\!CHANNEL!\!name! (!try!)!ext!" (
- goto :_FORM_VALID_FILE_NAME
- )
- set "%1=!name! (!try!)!ext!"
- exit /b
- :ERROR
- echo ERROR: %~1 (!errorlevel!)
- echo image_url: "!image_url!"
- echo image_url: "!image_name_extension!"
- echo:
- ::<nul set /p="Do you want to continue the script execution anyways? [Y/N] : "
- ::choice /n /c YN
- exit /b 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement