Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize Magnetic Link to download seed in batch by Python Code

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

Python code how to achieve magnetic link batch download seeds, in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.

This paper mainly introduces how to use Python to realize magnetic link to download movies in batch.

A few days ago, a friend sent me a bunch of magnetic links, saying that they were some good movies that I could watch for the past two days. But there are too many links, if you add and download one by one, you must not be tired to death! So I decided to try some automated downloads.

At first I tried to find some API of the existing download tools, but unfortunately, I couldn't find it, but I found an interesting library, pypiwin32, which is used to execute some windows instructions. It's also a great library. It was useful to deal with excel before. At this time, I intend to use win32 to automatically drive Xunlei to achieve seed connection batch automatic download.

With regard to the pypiwin32 library, I noticed the Dispatch function, which should be able to drive Thunderbolt directly. This function is used to connect to the fixed software. To use this program, you only need to get the name of the installation software registered on this computer. In order to simplify the process of finding the registration name, I wrote the registration name of Xunlei directly here:

ThunderAgent.Agent.1

My local registration name is the one above, of course, if the above one doesn't work, you can try the following one:

ThunderAgent.Agent64.1

There should be no problem with the current version of Thunderbolt 9 or 10.

Then we will begin our automated journey!

First of all, we need to download the library pypiwin32, which we install directly using pip.

Pip install pypiwin32

If the download speed is too slow, you can specify Tsinghua Source to download:

Pip install-I https://pypi.tuna.tsinghua.edu.cn/simple pypiwin32

Now we can use this module directly.

We mainly use the function Dispatch to put the registration name of Thunderbolt into this function. To complete the loading of Thunderbolt.

From win32com.client import Dispatchthunder = Dispatch ('ThunderAgent.Agent.1')

After successfully starting Thunderbolt, we can add quests to Thunderbolt.

At this point we use the AddTask method.

Three parameters need to be passed in the AddTask method:

Thunder.AddTask (Magnetic connection, download saved file name, save path)

Then we just need to use the CommitTasks function to submit the task.

The complete code is as follows:

From win32com.client import Dispatch

Thunder = Dispatch ('ThunderAgent.Agent.1')

Url = "ftp://ygdy8:ygdy8@yg39.dydytt.net:3010"\"

"/ Sunshine Movie www.ygdy8.com. Detective chasing billions beyond the Dragon"\

".HD.1080p. Mandarin Chinese character .mkv"

Filename = "Detective 1 billion in pursuit of the Dragon. MKV"

Thunder.AddTask (url, filename, r "C:\ Thunderbolt download")

Thunder.CommitTasks ()

Print ("Task created, start downloading: {}...." .format (filename))

That's all the code. However, for Thunderbolt, we still need to make some settings:

We need to check the one-click download and select download now in the default download mode.

This is fine. Here is the video of the effect:

Let's create several tasks to download, and let's take the resources of "Love apartment 5" as a demonstration:

In a total of 36 episodes, we can see some rules of url. We can obtain all the magnetic connections of 36 episodes, and then add them to the task in batches:

For i in range (1,37):

If I < 10:

I = "0 {}" .format (I)

Url = "ftp://ygdy8:ygdy8@yg76.dydytt.net:5919/"\"

"[sunshine movie-www.ygdy8.com] Love apartment 5-{} .mp4"\

.format (I)

Filename = url.split (']') [1]

Thunder.AddTask (url, filename, r "C:\ Thunderbolt download")

Print ("download Task creation: {}...." .format (filename))

Thunder.CommitTasks ()

At this point, the task of batch download is established, and the batch download can be carried out automatically. The effect video is as follows:

If the magnetic connection given to you by your friend is a txt file, we can also read the magnetic connection of each line of the file and download it:

Import csv

With open ("Love apartment Resources. Txt", 'rushing, encoding='utf-8') as f:

Reader = csv.reader (f)

Films = [I [0] for i in reader]

Thunder = Dispatch ('ThunderAgent.Agent.1')

For film in films:

Thunder.AddTask (film, film [- 12:], r "C:\ Thunderbolt download")

Thunder.CommitTasks () on how the Python code to achieve magnetic link batch download seed questions are shared here, I hope the above content can be of some help to you, if you still have a lot of doubts to be solved, you can follow the industry information channel to learn more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report