Jump to content

Download a file reading first a local txt file which contains the full url


Go to solution Solved by Deye,

Recommended Posts

I have an mp3.txt file in my hard disk which contains in this mp3.txt file the url http where to download the file , my mp3.txt contain this http url for example https://ftp.psu.ac.th/pub/demo/mp3/PSU-04.mp3 , how do i do with the autoit scripts to first read the contents of the mp3.txt file and then after reading the file must download the mp3 file located on a remote http server?

 

 

Link to comment
Share on other sites

Link to comment
Share on other sites

i have tried this but is not working 

Func _downloader($link)
    Local $dwnarrayread[3] = [IniRead(@ScriptDir & "mp3.txt", "file_links", "link_1", Default), IniRead(@ScriptDir & "mp3-2.txt", "file_links", "link_2", Default), IniRead(@ScriptDir & "mp3-3.txt", "file_links", "link_3", Default)]
    $dwnlink = InetGet($dwnarrayread[$link], @ScriptDir & "PSU-04.mp3", 1, 1)

    Do
        Sleep(50)
        $prc = Round(InetGetInfo($dwnlink, 0) / (InetGetInfo($dwnlink, 1)) * 100)
        GUICtrlSetData($progressbar1, $prc)
    Until InetGetInfo($dwnlink, $INET_DOWNLOADCOMPLETE)
EndFunc


mp3.txt file >>>>>>>>>>>>>
[files_links]
link_1=https://ftp.psu.ac.th/pub/demo/mp3/PSU-04.mp3
link_2=http://somesite.com/files/file2.zip
link_3=http://somesite.com/files/file3.zip
mp3-1.txt file >>>>>>>>>>>>>

Edited by gogloc
Link to comment
Share on other sites

Better use :

Local $aLink = IniReadSection(@ScriptDir & "\mp3.txt", "files_links")

You will get all the content without knowing how may links there is...

ps.  when you post code, please use method shown in the link.

Edited by Nine
Link to comment
Share on other sites

  • Solution

Try This:

#include <File.au3>

$s = FileRead("mp3.txt")
$aReadUrl = StringRegExp($s, "(?:http).+(?=\w\/)+[!-~]+\.\w{3}", 3)
If IsArray($aReadUrl) Then
;~  MsgBox(0, StringRegExpReplace($aReadUrl[0], ".*\/", ""), $aReadUrl[0])
    InetGet($aReadUrl[0], StringRegExpReplace($aReadUrl[0], ".*\/", ""), "", 2)
;~  _ArrayDisplay($aReadUrl, "File Url List")
EndIf

 

Edited by Deye
Link to comment
Share on other sites

13 hours ago, Deye said:

Try This:

#include <File.au3>

$s = FileRead("mp3.txt")
$aReadUrl = StringRegExp($s, "(?:http).+(?=\w\/)+[!-~]+\.\w{3}", 3)
If IsArray($aReadUrl) Then
;~  MsgBox(0, StringRegExpReplace($aReadUrl[0], ".*\/", ""), $aReadUrl[0])
    InetGet($aReadUrl[0], StringRegExpReplace($aReadUrl[0], ".*\/", ""), "", 2)
;~  _ArrayDisplay($aReadUrl, "File Url List")
EndIf

 

okay this is working good thanks , but now how can I save the downloaded file to a specific folder? for example C: \Users\Admin\Desktop\song.mp3

Edited by gogloc
Link to comment
Share on other sites

Quote

" ... how can I save the downloaded file to a specific folder?"

See here.

Does sir want fries a GUI with that? :muttley:

#include <AutoItConstants.au3>
#include <InetConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

_Download('mp3.txt', 'files_links', @DesktopDir & '\')

Func _Download(Const $sFileIni, Const $sSection, Const $sDest)
    Local Const $aFile = IniReadSection($sFileIni, $sSection)
    Local       $aDownload[$aFile[0][0] + 1]

    $aDownload[0] = $aFile[0][0]

    For $i1 = 1 To $aFile[0][0]

        $aDownload[$i1] = InetGet($aFile[$i1][1], $sDest & StringTrimLeft($aFile[$i1][1], StringInStr($aFile[$i1][1], '/', 0, -1)), $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND)

    Next

    Local Const $iWidth  = 400, _
                $iHeight =  20
    Local $hWnd = GUICreate(@ScriptName, $iWidth, $iHeight * $aDownload[0])
    Local $aHnd[$aDownload[0] + 1]

    For $i1 = 1 To $aDownload[0]

        $aHnd[$i1] = GUICtrlCreateProgress(0, ($i1 - 1) * $iHeight, $iWidth, $iHeight)
        GUICtrlSetTip($aHnd[$i1], $aFile[$i1][1])

    Next

    GUISetState(@SW_SHOW, $hWnd)
    Local $aInfo

    While Not (GUIGetMsg() = $GUI_EVENT_CLOSE)

        For $i1 = 1 To $aDownload[0]

            $aInfo = InetGetInfo($aDownload[$i1])
            GUICtrlSetData($aHnd[$i1], ($aInfo[$INET_DOWNLOADCOMPLETE] Or $aInfo[$INET_DOWNLOADSUCCESS]) ? 100 : $aInfo[$INET_DOWNLOADSIZE] / $aInfo[$INET_DOWNLOADREAD])

        Next

        If InetGetInfo() Then ContinueLoop

        MsgBox($MB_OK, @ScriptName, 'No more running downloads.', 0, $hWnd)
        ExitLoop

    WEnd

    For $i1 = 1 To $aDownload[0]

        InetClose($aDownload[$i1])

    Next

EndFunc

 

Edited by user4157124
Link to comment
Share on other sites

7 hours ago, user4157124 said:

See here.

Does sir want fries a GUI with that? :muttley:

#include <AutoItConstants.au3>
#include <InetConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

_Download('mp3.txt', 'files_links', @DesktopDir & '\')

Func _Download(Const $sFileIni, Const $sSection, Const $sDest)
    Local Const $aFile = IniReadSection($sFileIni, $sSection)
    Local       $aDownload[$aFile[0][0] + 1]

    $aDownload[0] = $aFile[0][0]

    For $i1 = 1 To $aFile[0][0]

        $aDownload[$i1] = InetGet($aFile[$i1][1], $sDest & StringTrimLeft($aFile[$i1][1], StringInStr($aFile[$i1][1], '/', 0, -1)), $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND)

    Next

    Local Const $iWidth  = 400, _
                $iHeight =  20
    Local $hWnd = GUICreate(@ScriptName, $iWidth, $iHeight * $aDownload[0])
    Local $aHnd[$aDownload[0] + 1]

    For $i1 = 1 To $aDownload[0]

        $aHnd[$i1] = GUICtrlCreateProgress(0, ($i1 - 1) * $iHeight, $iWidth, $iHeight)
        GUICtrlSetTip($aHnd[$i1], $aFile[$i1][1])

    Next

    GUISetState(@SW_SHOW, $hWnd)
    Local $aInfo

    While Not (GUIGetMsg() = $GUI_EVENT_CLOSE)

        For $i1 = 1 To $aDownload[0]

            $aInfo = InetGetInfo($aDownload[$i1])
            GUICtrlSetData($aHnd[$i1], ($aInfo[$INET_DOWNLOADCOMPLETE] Or $aInfo[$INET_DOWNLOADSUCCESS]) ? 100 : $aInfo[$INET_DOWNLOADSIZE] / $aInfo[$INET_DOWNLOADREAD])

        Next

        If InetGetInfo() Then ContinueLoop

        MsgBox($MB_OK, @ScriptName, 'No more running downloads.', 0, $hWnd)
        ExitLoop

    WEnd

    For $i1 = 1 To $aDownload[0]

        InetClose($aDownload[$i1])

    Next

EndFunc

 

I don't want a gui and this script is not working to me , i receive this error ((subscript used on non-accesible variable))

Edited by gogloc
Link to comment
Share on other sites

GUICtrlSetData($progressbar1, $prc) in your code seems an attempt at GUI creation. I get no errors, only successfully downloaded files. What's the full error message (line number)? Make sure _Download()'s parameters are correct (provide full path to .txt if not in same directory as script file, also check section name).

Link to comment
Share on other sites

21 minutes ago, user4157124 said:

GUICtrlSetData($progressbar1, $prc) in your code seems an attempt at GUI creation. I get no errors, only successfully downloaded files. What's the full error message (line number)? Make sure _Download()'s parameters are correct (provide full path to .txt if not in same directory as script file, also check section name).

this error

error.png

Link to comment
Share on other sites

Means IniReadSection() failed. Happens (from documentation) :

Quote

"... if unable to read the section (The INI file may not exist or the section may not exist or is empty)"

So:

4 hours ago, user4157124 said:

Make sure _Download()'s parameters are correct (provide full path to .txt if not in same directory as script file, also check section name).

If you're sure mp3.txt exists (containing non-empty [files_links] -section) and is in same directory as script file, try (everyone in this topic already said this) :

_Download(@ScriptDir & '\mp3.txt', 'files_links', @DesktopDir & '\')

Most likely your script is run in a way that changes its working directory; it looks for mp3.txt in altered working directory when provided relative- instead of absolute (full) file path.

P.S.: Use [Alt] + [Prt Scr] for screenshots of a window without having to manually crop it.

Edited by user4157124
Link to comment
Share on other sites

now it works I forgot to add some parameters to the file mp3.txt , but I would like to download the file to a folder on the desktop, for example C: \Users\Admin \Desktop\mp3-songs

_Download(@ScriptDir & '\mp3.txt', 'files_links', @DesktopDir & '\')

this script only downloads it to the desktop I want to download the file in the \mp3-songs folder on the desktop

Edited by gogloc
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...