gogloc Posted July 27, 2022 Share Posted July 27, 2022 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 More sharing options...
Nine Posted July 27, 2022 Share Posted July 27, 2022 (edited) To get the entries from your file use FileReadToArray Loop thru the array to get each entry To retrieve the file from the url use InetGet Edited July 27, 2022 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
gogloc Posted July 27, 2022 Author Share Posted July 27, 2022 (edited) 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 July 27, 2022 by gogloc Link to comment Share on other sites More sharing options...
mikell Posted July 27, 2022 Share Posted July 27, 2022 (edited) IniRead(@ScriptDir & "\mp3.txt", "fileS_links" Edited July 27, 2022 by mikell Link to comment Share on other sites More sharing options...
Nine Posted July 27, 2022 Share Posted July 27, 2022 (edited) 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 July 27, 2022 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Solution Deye Posted July 27, 2022 Solution Share Posted July 27, 2022 (edited) 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 July 27, 2022 by Deye gogloc 1 Link to comment Share on other sites More sharing options...
user4157124 Posted July 27, 2022 Share Posted July 27, 2022 Cross-posted. AUERLO (AutoIt error logger) Link to comment Share on other sites More sharing options...
gogloc Posted July 27, 2022 Author Share Posted July 27, 2022 2 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, "First File Url Found", $aReadUrl[0]) _ArrayDisplay($aReadUrl, "File Url List") EndIf this does not download the http url present in the mp3.txt file Link to comment Share on other sites More sharing options...
Deye Posted July 27, 2022 Share Posted July 27, 2022 @gogloc, See my Edit above Link to comment Share on other sites More sharing options...
gogloc Posted July 28, 2022 Author Share Posted July 28, 2022 (edited) 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 July 28, 2022 by gogloc Link to comment Share on other sites More sharing options...
user4157124 Posted July 28, 2022 Share Posted July 28, 2022 (edited) Quote " ... how can I save the downloaded file to a specific folder?" See here. Does sir want fries a GUI with that? expandcollapse popup#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 July 28, 2022 by user4157124 AUERLO (AutoIt error logger) Link to comment Share on other sites More sharing options...
gogloc Posted July 28, 2022 Author Share Posted July 28, 2022 (edited) 7 hours ago, user4157124 said: See here. Does sir want fries a GUI with that? expandcollapse popup#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 July 28, 2022 by gogloc Link to comment Share on other sites More sharing options...
user4157124 Posted July 28, 2022 Share Posted July 28, 2022 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). AUERLO (AutoIt error logger) Link to comment Share on other sites More sharing options...
gogloc Posted July 28, 2022 Author Share Posted July 28, 2022 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 Link to comment Share on other sites More sharing options...
user4157124 Posted July 28, 2022 Share Posted July 28, 2022 (edited) 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 July 28, 2022 by user4157124 AUERLO (AutoIt error logger) Link to comment Share on other sites More sharing options...
gogloc Posted July 29, 2022 Author Share Posted July 29, 2022 (edited) 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 July 29, 2022 by gogloc Link to comment Share on other sites More sharing options...
user4157124 Posted July 29, 2022 Share Posted July 29, 2022 _Download(@ScriptDir & '\mp3.txt', 'files_links', @DesktopDir & '\mp3-songs\') gogloc 1 AUERLO (AutoIt error logger) Link to comment Share on other sites More sharing options...
gogloc Posted July 29, 2022 Author Share Posted July 29, 2022 2 hours ago, user4157124 said: _Download(@ScriptDir & '\mp3.txt', 'files_links', @DesktopDir & '\mp3-songs\') thanks was just what i wanted Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now