China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-07-31 21:17
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Original] Build an Automatic BT Download BOT Using Curl and Task Scheduler DigestI View 5,625 Replies 5
Original Poster Posted 2006-08-02 13:38 ·  中国 四川 成都 电信
初级用户
Credits 58
Posts 6
Joined 2006-08-01 22:48
19-year member
UID 59645
Status Offline
**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:

curl -o tmp.txt http://bt.popgo.net/


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:

'findstr "漫游字幕组" tmp.txt^|findstr "href"'


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:

 for /f "tokens=5,6,9 delims==>" %%i in ('findstr "漫游字幕组" tmp.txt^|findstr "href"') do (
set flag=1
set tmp=%%i
if "!tmp:~1,2%!"=="置顶" (
set temp=%%k
set posthash=!temp:~0,-1%!
) else (
set temp=%%j
set posthash=!temp:~0,-1%!
)
for /f "delims=" %%j in (download.txt) do if !posthash!==%%j set flag=0
if !flag!==1 (
curl -O http://bt.popgo.net/allowed/!posthash!.torrent
)
)


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:

start bitcomet.exe /s /tray !posthash!.torrent /o e:\downloads\


Finally, store the file name that has been downloaded into the download.txt file for next use:

@echo !posthash!>>download.txt


**Completion**

The final complete code is:

@echo off

setlocal ENABLEDELAYEDEXPANSION
curl -o tmp.txt http://bt.popgo.net/
for /f "tokens=5,6,9 delims==>" %%i in ('findstr "漫游字幕组" tmp.txt^|findstr "href"') do (
set flag=1
set tmp=%%i
if "!tmp:~1,2%!"=="置顶" (
set temp=%%k
set posthash=!temp:~0,-1%!
) else (
set temp=%%j
set posthash=!temp:~0,-1%!
)
for /f "delims=" %%j in (download.txt) do if !posthash!==%%j set flag=0
if !flag!==1 (
curl -O http://bt.popgo.net/allowed/!posthash!.torrent
start bitcomet.exe /s /tray !posthash!.torrent /o e:\downloads\
@echo !posthash!>>download.txt
)
)
endlocal


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 ]
Floor 2 Posted 2006-12-23 08:19 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
I downloaded the forum just in time today, and I'm learning!

A good post shouldn't sink!
Floor 3 Posted 2007-08-18 23:28 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
Today I used curl again, very good and powerful

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 4 Posted 2007-08-19 15:30 ·  中国 福建 三明 电信
高级用户
★★
论坛上抢劫的
Credits 551
Posts 246
Joined 2006-09-21 12:35
19-year member
UID 63270
Status Offline
I'll take it!
Floor 5 Posted 2007-12-06 09:02 ·  中国 浙江 杭州 电信
中级用户
★★
Credits 321
Posts 135
Joined 2007-02-04 04:48
19-year member
UID 78578
Gender Male
Status Offline
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.
Floor 6 Posted 2008-04-14 05:23 ·  中国 浙江 嘉兴 平湖市 电信
初级用户
★★
Credits 157
Posts 67
Joined 2007-05-13 11:03
19-year member
UID 88378
Gender Male
Status Offline
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 ]
Forum Jump: