During the crawling process, I did not know why and could not be caught directly, so I thought of calling thunder download. This was found on the website and I did not expect it to be very useful, I just used the simple file download function. 
 
 
 
 
[Guide] This article describes in detail the process and steps of using VB. NET programming to call the file download function of Xunlei. The content includes: creating a referer call object, querying download task information using the Referer call object, and defining the functions of the thunder platform interface.
 
 
 
 
 
 
 
First, make sure that the computer has been installed with Xunlei. Open vs. NET and click the menu: Project> Add reference> COM> Add a reference to the thunderagent 1.0 Type Library.
 
 
 
1. Create a record call object
 
 
 
Private thundereng as new thunderagentlib. AGENT: Creates a record call object.
 
 
 
 
 
 
Thundereng. addtask ("", "save another file name", "Save directory", "task comment", "reference address", "Start mode", "Download from original address only ", "Number of threads downloaded from the original address") 'Add a download task
 
 
 
 
 
 
Thundereng. committasks () 'submit the download task
 
 
 
 
 
 
2. Use Xunlei to call objects to query download task information
 
 
 
Sfilesize = thundereng. gettaskinfo (txturl. Text, "filesize") 'to get the downloaded file size
 
 
 
Sdownedsize = thundereng. gettaskinfo (txturl. Text, "completedsize") 'to get the completed size
 
 
Sfilename = thundereng. gettaskinfo (txturl. Text, "FILENAME") 'get the file name
 
 
 
Ii. Definition of interfaces of the thunder Platform 
 
 
 
Obtain information 
 
 
 
1. BSTR getinfo (BSTR pinfoname) 
 
 
 
Function: obtain information about thunder or platform.
 
 
 
Parameters:
 
 
 
  
   
   | Parameter Name |  
   Description |  
  
 
   
   | Pinfoname |  
   Information name, which has the following four types: ◆ "Thunderexists": Does thunder exist? ◆ "Thunderrunning": whether or not thunder runs ◆ "Thunderversion": the thunder version number ◆ "Platformversion": Platform version number  |  
  
 
  
 
 
Return Value: The returned value is a string that corresponds to the pinfoname parameter.
 
 
 
  
   
   | Parameters |  
   Return Value |  
  
 
   
   | "Thunderexists" |  
   "True" exists, and "false" does not exist |  
  
 
   
   | "Thunderrunning" |  
   "True" is running, and "false" is not running |  
  
 
   
   | "Thunderversion" |  
   Thunder version "x. x" |  
  
 
   
   | "Platformversion" |  
   Platform version "x. x" |  
  
 
  
 
 
2. hresult getinfostruct (INT pinfo) 
 
 
 
Function: obtain all information related to thunder or platform.
 
 
 
Parameters:
 
 
 
  
   
   | Parameter Name |  
   Description |  
  
 
   
   | Pinfo |  
   It is actually a structure pointer of the thunder_info type. It is converted to the int type before calling. The platform information will be filled in the structure after calling, which is defined as follows: Typedef struct _ thunder_info { Bool bthunderexists; Bool bthunderrunning; Char szthunderversion [32]; Char szplatformversion [32]; } Thunder_info; After the function is called, the corresponding information is filled in the structure.  |  
  
 
  
 
 
Return Value:
 
 
 
  
   
   | 0 |  
   Obtained successfully |  
  
 
   
   | Non-0 |  
   Failed to get |  
  
 
  
 
 
Task operations 
 
 
 
3. Add a task 
 
 
 
Hresult addtask
 
 
 
(BSTR Purl,
 
 
 
BSTR pfilename = "",
 
 
 
BSTR ppath = "",
 
 
 
BSTR pcomments = "",
 
 
 
BSTR preferurl = "",
 
 
Int nstartmode =-1,
 
 
 
Int nonlyfromorigin = 0,
 
 
 
Int noriginthreadcount =-1 );
 
 
 
Function:
 
 
 
Add the download task information to the platform, which is not yet reflected in thunder.
 
 
 
Parameters:
 
 
 
 
 
 
  
   
   | Parameter Name |  
   Description |  
  
 
   
   | Purl |  
   Target URL, required Parameter |  
  
 
   
   | Pfilename |  
   Another storage name. The default value is null, indicating that it is processed by thunder. Optional Parameter |  
  
 
   
   | Ppath |  
   Storage directory. It is empty by default, indicating that it is processed by thunder. Optional Parameter |  
  
 
   
   | Pcomments |  
   Download comments. The default value is null. Optional. |  
  
 
   
   | Preferurl |  
   URL of the reference page. The default value is null. Optional. |  
  
 
   
   | Nstartmode |  
   Start mode. The value 0 starts manually. The value 1 starts immediately. The default value is-1, indicating that it is processed by thunder. An optional parameter. |  
  
 
   
   | Nonlyfromorigin |  
   Whether to download from the original URL, 1 from the original URL, more than 0 resources, 0 by default, optional parameter |  
  
 
   
   | Noriginthreadcount |  
   Number of download threads from the original address. The value range is 1-10. The default value is-1, indicating that the thread is processed by thunder. Optional Parameter |  
  
 
  
 
 
 
 
 
 
 
 
 
4. Start the task
 
 
 
 
 
 
Hresult committaskss ()
 
 
 
Function:
 
 
 
Submit the information of the addtask download task to thunder for download and delete it from the platform.
 
 
 
Note: If the task added by addtask is not submitted and canceled (canceltasks is called), the agent object is blocked during analysis, therefore, the caller should not leave any unsubmitted or canceled tasks to prevent the script executor from stopping the response.
 
 
 
5. Cancel the task 
 
 
 
Hresult canceltasks ()
 
 
 
Function:
 
 
 
Cancel all download task information added by addtask on the platform
 
 
 
6. Query Task Information 
 
 
 
BSTR gettaskinfo (BSTR Purl, BSTR pinfoname );
 
 
 
Parameters:
 
 
 
 
 
 
  
   
   | Parameter Name |  
   Description |  
  
 
   
   | Purl |  
   Download URL Information to be queried |  
  
 
   
   | Pinfoname |  
   Status name, which can be any of the following ◆ "Exists": whether purl is in the thunder task list ◆ "Path": storage directory ◆ "FILENAME": File Name ◆ "Filesize": File Size ◆ "Completedsize": downloaded size ◆ "Percent": download progress ◆ "Status": Task status  |  
  
 
  
 
 
Return Value: The returned value is a string that corresponds to the pinfoname parameter.
 
 
 
 
 
 
  
   
   | Parameters |  
   Return Value |  
  
 
   
   | "Exists" |  
   "True" exists, "false" does not exist |  
  
 
   
   | "Path" |  
   Storage directory, with backslash \, for example: C: \ tddownload \ |  
  
 
   
   | "Filename" |  
   File Name |  
  
 
   
   | "Filesize" |  
   File size, in bytes, 0 indicates the size is unknown |  
  
 
   
   | "Completedsize" |  
   Downloaded size, in bytes |  
  
 
   
   | "Percent" |  
   Download progress, with 1 decimal point, for example: 70.0 |  
  
 
   
   | "Status" |  
   Task status, which has the following six statuses: . "Running": running status . "Stopped": stopped . "Failed": failure status . "Success": Successful . "Creatingfile": creating a data file . "Connecting": Connecting  |  
  
 
  
 
 
7. gettaskinfostruct (INT ptaskinfo)
 
 
 
Function: Query all information of a task.
 
 
 
 
 
 
  
   
   | Parameter Name |  
   Description |  
  
 
   
   | Ptaskinfo |  
   It is actually a structure pointer of the thunder_taskinfo type. It is converted to the int type before calling. After calling, the structure will fill in the platform information, which is defined as follows: Typedef struct _ thunder_taskinfo { Char szurl [1024]; // task URL, prefilled Bool btaskexists; // whether the task exists. True indicates that the task exists. Char szpath [256]; // Local save path for download Char szfilename [256]; // local file name Ulonglong nfilesize; // File Size Ulonglong ncompletedsize; // completed size Char szpercent [16]; // percentage of completion, in the "56.8" Format Char szstatus [16]; // The Current Status, defining the same function as gettaskinfo } Thunder_taskinfo; The caller fills in the szurl member in the structure to specify the URL of the task to be queried. Then, after the function returns, the caller can obtain information about the task from other members.  |  
  
 
  
 
 
In this example, allCode:
 
 
 
 
 
 
  
   
               Imports system
  Imports system. Text
  Public class frmthunderclass frmthunder
  Private _ istartmode as integer 'thunder task download start Mode
  Private thundereng as new thunderagentlib. AGENT: Creates a record call object.
  Private sub frmthunder_load () sub frmthunder_load (byval sender as system. object,                Byval e as system. eventargs) handles mybase. Load
  End sub
  Private sub btncancel_click () sub btncancel_click (byval sender as system. object,                Byval e as system. eventargs) handles btncancel. Click
  Close ()
  End sub
  'Start the download task
  Private sub btnstartdown_click () sub btnstartdown_click (byval sender as system. object,              Byval e as system. eventargs) handles btnstartdown. Click
  Dim ionlyfromorigin, ioriginthreadcount as integer
  Ionlyfromorigin = IIF (chkonlyfromorigin. Checked = true, 1, 0)
  Ioriginthreadcount = CINT (txtoriginthreadcounts. Text)
  If chkdefault. Checked then
  Ioriginthreadcount =-1
  End if
  Thundereng. addtask (txturl. Text, txtsaveasfilename. Text, txtsavedir. Text,                Txtcomment. Text, _ txtreferencepage. Text, _ istartmode, ionlyfromorigin,                Ioriginthreadcount)
  Thundereng. committasks ()
  Timer1.enabled = true
  End sub
  Private sub radmaual_click () sub radmaual_click (byval sender as system. object,                Byval e as system. eventargs) handles radmaual. Click, radimmediate. Click,               raddefault. click   dim rad as radiobutton = ctype (sender, radiobutton)   _ istartmode = CINT (rad. tag)   end sub   'query task download information regularly when the task starts.   private sub timer1_tick () sub timereffectick (byval sender as system. object,               byval e as system. eventargs) handles timer1.tick   dim sfilesize, sdownedsize, sStatus, sfilename, spercent as string   try   sStatus = thundereng. gettaskinfo (txturl. text, "status")   sfilesize = thundereng. gettaskinfo (txturl. text, "filesize")   sdownedsize = thundereng. gettaskinfo (txturl. text, "completedsize")   sfilename = thundereng. gettaskinfo (txturl. text, "FILENAME")   lbldownedsize. TEXT = string. format (lbldownedsize. tag, sdownedsize)   lblfilesize. TEXT = string. format (lblfilesize. tag, sfilesize)   lbltaskstatus. TEXT = string. format (lbltaskstatus. tag, sStatus)   lblfilename. TEXT = string. format (lblfilename. tag, sfilename)   spercent = thundereng. gettaskinfo (txturl. text, "percent") 'Get the download percentage   lblprogress. TEXT = string. format (lblprogress. tag,              Spercent. Remove (3, Len (spercent)-3 ))
  Catch ex as exception
  End try
  End sub
  Private sub chkonlyfromorigin_checkedchanged_1 () sub                Chkonlyfromorigin_checkedchanged_1 (byval sender as system. object,                Byval e as system. eventargs) handles chkonlyfromorigin. checkedchanged
  Panel1.enabled = chkonlyfromorigin. Checked
  End sub
  Private sub groupboxincluenter () sub groupboxincluenter (byval sender as system. object,                Byval e as system. eventargs) handles groupbox1.enter
  End sub
  End Class                |