**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 ]
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
)
)
endlocalSave 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 ]

DigestI