The short video business has been booming in the past year or two, and each video website has its own short video content. If there was a program that could download the latest videos released by popular users of major video websites, it would not only facilitate viewing, but also allow you to post copyright-free videos on personal social networking sites to increase your own popularity. How great would it be?
The short video business has been booming in the past year or two, and each video website has its own short video content. Wouldn't it be nice if there was such a program that could download the latest videos released by popular users of major video websites? Not only would it be convenient for you to watch, but you could also post copyright-free videos on personal social networking sites to increase your popularity. ?
parker is such a project (project address: https://github.com/LiuRoy/parker), which uses the celeryframework to regularly crawl user video lists and compile the latest released videos Distributed deployment can be easily implemented through you-get asynchronous download. Because the page layout and interface of each website are updated frequently, in order to ensure the high availability of the program, Statsd monitoring is specially added to facilitate timely detection of errors.
CodeArchitecture
Program operation
windows environment.
Dependent librariesInstallation##The python version is 3.5. After entering the project directory, execute:
pip install -r requirements.txt
Create database
TableBuild it in the database in advance Two tables (sql: https://github.com/LiuRoy/parker/blob/master/spider/models/tables.sql)
Parameter configuration logging.yaml, params.yaml, and sites.yaml under the config path correspond to log configuration, running parameter configuration, and popular user configuration respectively.
Log configurationIn debug mode, the log will be output directly to the standard output stream. In release mode, the log content will be output to a file. Therefore, the output log file needs to be configured.
Run configuration
, in this mode the log points to the standard output , and there is no monitoring data; in release mode, the log is output to the specified file, and there is monitoring data.
_url Database address, two tables need to be built in advance
video_number_per_page How many video playback addresses are parsed from the user's video homepage each time? Because most users publish a small number of videos each time, it only needs to be set to a very small value. During the first run, a large number of long-standing videos will not be downloaded.
download_timeout Timeout for video download
Popular user configuration
parker will generate a list of celery beat schedulers based on this configuration.
name rule is
url user Publish video homepage
task Corresponding celery parsing asynchronous task
minute How many minutes to check the user video list
Start the task
Enter the project directory and execute the following command to start the celery worker
celery -A spider worker
Execute the following command to start the celery beat scheduled task
celery -A spider beat
Monitoring
Strongly use a docker image to configure the monitoring environment in one minute. After that, you only need to add the data of successful execution and abnormal execution, and you can easily monitor whether the program is running normally.
The above is the detailed content of Using Python to implement video download function example code. For more information, please follow other related articles on the PHP Chinese website!