![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-09-15 09:08 |
47,812 topics / 349,917 posts / today 0 new / 48,268 members |
| DOS批处理 & 脚本技术(批处理室) » [Original] Build an Automatic BT Download BOT Using Curl and Task Scheduler |
| Printable Version 5,889 / 5 |
| Floor1 ikari | Posted 2006-08-02 13:38 |
| 初级用户 Posts 6 Credits 58 | |
|
**Inducement**
Doufu neither smokes nor drinks. The only hobby he can be considered to have is Anime. And he likes to follow new episodes, never missing a single one every week. The first thing to do when sitting in front of the computer is to flip through various BT pages to see if the animated series he cares about has been updated. Over time, this has become a habit. Although it is tedious, he doesn't feel any inconvenience. But recently, due to work reasons, he has to go to another place for a month, and most of the stations have no network. Does he have to wait until he comes back to drag it slowly with eMule? If he can automatically download the BT torrent and then download the corresponding files, that would be great. He searched the Internet but didn't find a suitable ready-made software. It seems he has to DIY again. **Idea** To do a good job, one must first sharpen one's tools Recently, CMD scripts are easy to use, and Curl is just right for him. The old partner should be able to get the BT torrent easily. Then there is the problem of BT downloading. BitComet is what Doufu often uses. Looking through the instructions, it supports the command line. Well, that's it. Finally, for automatic timing operation, no other software is needed. The task scheduler built into Windows is enough. Know yourself and know your enemy, and you can win a hundred battles To get things from others, of course, one must be familiar with their rules. One should analyze the structure of the web pages that provide BT torrents respectively. Choosing those with clear structures can save a lot of work. Take the BT page where Doufu often hangs out as an example: All the entries containing torrents are in a <table>. The structure in each <td> element is ordered and divided into two situations: top-sticked and general. In this way, it is convenient to use FOR to get the corresponding URL. Then look at the HASH value in href, which is exactly the file name of the actual torrent file. So it is very convenient to get it with CURL. Moreover, as long as the file names of the torrents that have been downloaded each time are saved to an external file, when executing repeatedly, these downloaded files can be excluded by comparison. **Practice** To follow the clues, first use Curl to get the homepage of the BT page: To successfully find the items that meet the specified conditions to be downloaded, FINDSTR is a good choice. Here, Doufu takes "Man漫游Subtitle Group" as the key word, and all the works of this group can be included: After analyzing the tmp.txt file, decide to use '=' and '>' as delimiters, take the 5th, 6th, and 9th segments of the divided strings and store them in environment variables i, j, k. Use variable i to judge whether it is a top-sticked entry. If it is, k is the torrent file name; otherwise, j is the torrent file name. Finally, make corresponding interception processing of the string. Before substituting into the Curl parameter to get the torrent file, it is also necessary to check whether the file has been downloaded: After getting the torrent file, use the START command to pass command line parameters to BitComet.exe to start BT downloading. '/s' means quiet mode without confirmation to start downloading immediately; '/tray' means minimize to the system tray when starting; '/o' means the path to store files: Finally, store the file name that has been downloaded into the download.txt file for next use: **Completion** The final complete code is: Save the above code as test.cmd. Confirm that Task Scheduler is 'Automatic'. Add a new task in Task Scheduler to execute test.cmd. Set the start time to start at 0:00 every day, every 30 minutes, for 24 hours: ![]() This script will check the specified website every 30 minutes and download the latest translated works of Man漫游Subtitle Group. So far, it's done. Doufu can finally go out with peace of mind. This article is original by chenke_ikari, first published on Doufu's Simple Hut This article is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 2.5 China License ![]() [ Last edited by ikari on 2006-8-2 at 13:41 ] |
|
| Floor2 electronixtar | Posted 2006-12-23 08:19 |
| 铂金会员 Posts 2,672 Credits 7,493 | |
|
I downloaded the forum just in time today, and I'm learning!
A good post shouldn't sink! |
|
| Floor3 electronixtar | Posted 2007-08-18 23:28 |
| 铂金会员 Posts 2,672 Credits 7,493 | |
|
Today I used curl again, very good and powerful
|
|
| Floor4 lotus516 | Posted 2007-08-19 15:30 |
| 高级用户 Posts 246 Credits 551 | |
|
I'll take it!
|
|
| Floor5 honghunter | Posted 2007-12-06 09:02 |
| 中级用户 Posts 135 Credits 321 | |
|
First of all, thank you to the LZ for sharing. Secondly, I hope everyone doesn't blame me for digging up old posts.
My current problem is that it's easy to find torrents, but the problem is how to judge whether there are still seeds in the .torrent file now? Because my situation is different from the LZ's. I need to download a few old movies, and I found many torrent files, but they all have no seeds. My question is how to judge the quality of a torrent file, that is, whether there are still seeds. |
|
| Floor6 tvzml | Posted 2008-04-14 05:23 |
| 初级用户 Posts 67 Credits 157 | |
|
For the purpose of learning, I referred to the article by user ikari. Since I am a beginner and not proficient in the FOR command, I used multiple temporary files to analyze the hash value of the torrent. The principle is actually very simple: first use wget to download the web page, then use the FOR statement to analyze and filter out the hash address of the website, then use WGET to download the BT torrent, then use BitComet to download the movie from the torrent, and record it in download.txt to prevent repeated downloads.
::BitComet installation path is the default C:\Program Files\BitComet ::Download save path is d:\downloads\ @echo off&setlocal ENABLEDELAYEDEXPANSION set path=%path%;%cd%;%~dp0;C:\Program Files\BitComet wget -w 3 -N http://bt.popgo.net/index.html cd.>index1.txt cd.>index2.txt cd.>index3.txt cd.>index4.txt cd.>index5.txt cd.>Hash.txt for /f "delims=" %%i in ('findstr "href=" index.html') do echo %%i>>index1.txt for /f "delims=" %%i in ('findstr "漫游字幕组" index1.txt') do echo %%i>>index2.txt for /f "delims=" %%i in ('findstr "置顶" index2.txt') do echo %%i>>index3.txt for /f "tokens=8 delims==>" %%i in (index3.txt) do echo %%~i >>index4.txt for /f "tokens=1* delims=_" %%a in (index4.txt) do echo %%b >>index5.txt for /f "delims=." %%a in (index5.txt) do echo %%a>>Hash.txt del index1.txt del index2.txt del index3.txt del index4.txt del index5.txt for /f "delims=" %%i in (Hash.txt) do ( set flag=1 for /f "delims=" %%j in (download.txt) do if %%i==%%j set flag=0 if !flag!==1 ( wget -w 2 -N http://bt.popgo.net/down/down.php?hash=%%i echo %%i>>download.txt start BitComet.exe /s /tray %%i.torrent /o d:\downloads\ ) ) ) endlocal ::Please前辈help optimize, especially the FOR part where a few sentences can be omitted. Hope to get the guidance of experts. [ Last edited by tvzml on 2008-4-14 at 05:26 AM ] |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |