Made a auto-download using wget. I need some help in some things.....

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
DjDiabolik
Posts: 1
Joined: 27 Jan 2019 09:56

Made a auto-download using wget. I need some help in some things.....

#1 Post by DjDiabolik » 27 Jan 2019 10:12

Hi, i'm totally news here and i have found this forum by google and i have register to find some help whit some my batch.

I have created a batch command to download (using wget) some files from a specific site.... on my fist version i have myself created a multi prompt request and only when you put a empty value there's start to download all previously input.
This is how i created:

Code: Select all

@ECHO OFF
CLS
SETLOCAL EnableDelayedExpansion
REM Variabili
SET User=My access on site
SET Pass=obviously my pass
SET UserAgent=Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
SET Link_Base=https://bda.retroroms.info/downloads/mame/currentroms/

REM Nomi Downloads
:START
ECHO.
ECHO Inserire Nome/i Roms (VUOTO per iniziare i/il Downloads):
:NEXT
REM SET /P File%num% = %num%. 
FOR /L %%A IN (1,1,100) DO (
	SET /P File[%%A]=%%A. 
	IF [!File[%%A]!]==[] GOTO DOWNLOAD
)

:DOWNLOAD
FOR /L %%A IN (1,1,100) DO (
	IF [!File[%%A]!]==[] GOTO OUT
	SET Cmd=wget --user=%User% --password=%Pass% --user-agent="%UserAgent%" "%Link_Base%!File[%%A]!.zip"
	ECHO !Cmd!
	ECHO.
	!Cmd!
	CHOICE /C:AB /T:5 /D:A >NUL
	
)

:OUT
Whit cmd i can put 100 names (if i want to download only 1 files i can leave the input empty at next request...) and after all names it's setted it's be start the download using wget.
I have to set the limit to 100 because this site whit a "normal account" has a limit download...... 100 files for every 24hours :)

At this point i have another idea to create a different batch....... a totally news batch can be read all files name from a TXT files and after that need to start download.
I have start to "develop" it last night whitout success.......... i need some helps whit for command..... that's is all i have already write:

Code: Select all

@ECHO OFF
CLS
SETLOCAL EnableDelayedExpansion
SET User=Myuser
SET Pass=Mypass
SET UserAgent=Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
SET Link_Base=https://bda.retroroms.info/downloads/mame/currentroms/

REM Nome File TXT da Leggere
:LOOP1
ECHO.
SET /P FileTXT=Inserire Nome File TXT: 
IF [%FileTXT%]==[] (
	ECHO File non valido
	GOTO LOOP1
)
IF EXIST .\%FileTXT% (
	GOTO OK1
) ELSE (
	ECHO File non trovato...
	GOTO LOOP1
)

:OK1
REM Inizio Lettura FileTXT
FOR /F "skip=1" %%A IN (.\%FileTXT%) DO (
	SET File[%%A]=%%A.zip
)
On same patch of batch i have a file called Sets.txt.... i have need to entered the name... and now need to learn how i can read the first 100 lines (because the files Sets.txt contain about 250Lines).
Apparently whit this i can read the txt files but it's my idea to be obtain every variable for every line....... it's not possible ?
If i add a "ECHO !%File[%%A]%!" after the set i can see on screen all lines on txt whit correctly .zip at ends.... but apparently i can't read a specific line, i have tryed to "echo" the variable "50" and there's no works..

Someone can me some sugggestion ? Thanks in advance..........


*EDIT nm.1*
In this last night and about in this last hours i have made some TEST on this........... apparently after a various and various "Google search" i have found and made a working version of this batch.... i thinks i can post how i obtain:

Code: Select all

@ECHO OFF
CLS
SETLOCAL EnableDelayedExpansion
SET L=0
SET User=My User
SET Pass=MyPassword
SET UserAgent=Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
SET Link_Base=https://bda.retroroms.info/downloads/mame/currentroms/

REM Nome File TXT da Leggere
:LOOP1
ECHO.
SET /P FileTXT=Inserire Nome File TXT: 
IF [%FileTXT%]==[] (
	ECHO File non valido
	GOTO LOOP1
)
IF EXIST .\%FileTXT% (
	GOTO OK1
) ELSE (
	ECHO File non trovato...
	GOTO LOOP1
)

:OK1
REM Inizio Lettura FileTXT
for /f "usebackq tokens=*" %%A in (".\%FileTXT%") do (
  set /a L += 1
  set "File!L!=%%A.zip"
)

REM Conferma dei File da Scaricare
CLS
ECHO.
ECHO Lista dei File da scaricare:
FOR /L %%A IN (1,1,100) DO (
	ECHO %%A. !File%%A!
	IF [!File%%A!]==[] GOTO OUT1
)

:OUT1
ECHO Confermare l'avvio dei download (S/N) ?
CHOICE /C:SN
IF %ERRORLEVEL% EQU 2 GOTO EXIT
IF %ERRORLEVEL% EQU 1 GOTO DOWNLOAD

:DOWNLOAD
REM Inizio dei Download
CLS
FOR /L %%A IN (1,1,100) DO (
	SET Cmd=wget --user=%User% --password=%Pass% --user-agent="%UserAgent%" "%Link_Base%!File%%A!"
	ECHO Download File %%A:
	ECHO !Cmd!
	ECHO.
	!Cmd!
	CHOICE /C:AB /T:5 /D:A >NUL
	IF [!File%%A!]==[] GOTO OUT2
)
:OUT2

:EXIT
About last night i have found this suggestion over internet:

Code: Select all

:OK1
REM Inizio Lettura FileTXT
for /f "usebackq tokens=*" %%A in (".\%FileTXT%") do (
  set /a L += 1
  set "File!L!=%%A.zip"
)
In this parts you can say...... pratically it's do a "full read" the txt files previously setted and it's set a variable called "FileXX" whit every line of my txt. At end i obtain %File1% %File2% etc etc.

After that for another FOR /L i have pick the fist 100 variable (Becuase remember....... the daily download it's limited at 100 whit a normal account)....... and ask to user if want to start download or not.

Another after that....... i have start the download using wget......... another FOR /L for all download.

In the both loop you can also found a if condition....... it's need if the txt contain less of 100 line....... this will need to not set EMPTY variable........ apparently there's works.




At this my condition....... i don't know if the BEST way to obtain my result. For Example....... it's possibly directly to extract only the first 100 line directly and set only the first 100 variable from txt ? I don't know how it's possible....... if someone can.... please explain.

Another question......... on actually batch all .zip it's be download in same location when it's placed the wget.exe and the all .batch and it's a lot of confusion to pick all .zip files....... i thinks it's an idea to add a path folder on wget.......

pieh-ejdsch
Posts: 239
Joined: 04 Mar 2014 11:14
Location: germany

Re: Made a auto-download using wget. I need some help in some things.....

#2 Post by pieh-ejdsch » 28 Jan 2019 15:55

Hallo DjDiabolik,
if the ROMs all remain in the folder you can take the list to compare with existing files.
if the file does not exist it will be downloaded.
a counter counts the downloaded files up to one hundred.
then it will be canceled.
with wget the links can also be extracted wonderfully
directly from the website and then load the files automatically.
I made such a script.
I'll see where it's lying around.
Phil

Post Reply