Автоматизиран код за сваляне на видео и субтитри

C++ JAVA
Forum rules
Моля, маркирайте отговора на потребитeля, който най-много ви е помогнал за решаването на проблема/въпроса Ви!
Повече за системата за оценяване може да прочетете тук: viewtopic.php?f=28&t=130265
Post Reply
User avatar

Topic author
Ticketa
Редовен
Редовен
Reactions: 6
Posts: 676
Joined: Mon Feb 27, 2012 1:54 pm
Support: 24
9
Location: in /root
Contact:

Автоматизиран код за сваляне на видео и субтитри

Post by Ticketa »

Привет,
Опитвам се да направя код, който сваля уроци от chess.com

За момента съм направил кода да сваля файловете, когато си поставил линка на съответния урок. Обаче ми се иска да го направя по следния начин:
Създаваме папка с името на категорията:
Beginner (Fundamentals)
Създаваме под папка с името на под категорията:
Opening Principles
=> Сваляме файловете

Използвам: https://simplehtmldom.sourceforge.io/

Code: Select all

<?php
include("simple_html_dom.php");
// Create DOM from URL or file
$html = file_get_html('https://www.chess.com/lessons/opening-principles/develop-your-pieces');

// Find all links
// Find all article blocks
$str_html=str_get_html($html);
// $file_html=file_get_html($html); // use file_get_html if you parse an url.
$div=$str_html->find("div#lessons-upgrade-modal");
$count=count($div)-1;
for($a=0;$a<=$count;$a++){
    $url = $str_html->find("div#lessons-upgrade-modal", $a)->getAttribute('data-lesson');
	
	$prefix_video = 'video_url'; 
	$index = strpos($url, $prefix_video) + strlen($prefix_video);
	$result1 = substr($url, $index);
	$variable = strstr($result1, '.mp4', true);
	$variable = str_replace("&quot;:&quot;", '', $variable);
	
	shell_exec("wget $variable . ".mp4"");
	//echo $variable.".mp4";
	//echo "<br />";
	
	$prefix_subs = '[{&quot;url&quot;:&quot;'; 
	$index_subs = strpos($url, $prefix_subs) + strlen($prefix_subs);
	$result_subs = substr($url, $index_subs);
	$variable_subs = strstr($result_subs, '.vtt', true);
	#$variable_subs = str_replace("&quot;:&quot;", '', $variable_subs);
	shell_exec("wget $variable_subs . ".vtt"");
	//echo $variable_subs.".vtt";
	//,"video_url":"https://media.chesscomfiles.com/videos/square/ENG-develop-your-pieces-b2s.mp4"
	//[{"url":"https://media.chesscomfiles.com/subtitles/develop-your-pieces5e54d9bf759ec.en_US.vtt"
	
	/*
	Създаваме папка с името на категорията:
	Beginner (Fundamentals)
		Създаваме под папка с името на под категорията:
			Opening Principles
				=> Сваляме файловете
	
	
	
	First the grab:
	=> https://www.chess.com/lessons
	====> Beginner (Fundamentals)
	mkdir Beginner (Fundamentals)
		=> open url
			=> https://www.chess.com/lessons/opening-principles
				=> mkdir "Opening Principles"
					=> open url
						=> https://www.chess.com/lessons/opening-principles/control-the-center
							=> download video and subtitres
								=> https://media.chesscomfiles.com/videos/square/ENG-develop-your-pieces-b2s.mp4
								=> https://media.chesscomfiles.com/subtitles/develop-your-pieces5e54d9bf759ec.en_US.vtt
								
						=> https://www.chess.com/lessons/opening-principles/develop-your-pieces
							=> download video and subtitres
								=>
								=>
						=> https://www.chess.com/lessons/opening-principles/protect-your-king
							=> download video and subtitres
								=>
								=>
						=> https://www.chess.com/lessons/opening-principles/active-pieces
							=> download video and subtitres
								=>
								=>
						=> https://www.chess.com/lessons/opening-principles/phases-of-the-game
							=> download video and subtitres
								=>
								=>
				
			=> https://www.chess.com/lessons/winning-the-game
				=> mkdir "Winning the Game"
				
			=> https://www.chess.com/lessons/capturing-pieces
				=> mkdir "Capturing Pieces"
				
			=> https://www.chess.com/lessons/finding-checkmate
				=> mkdir "Finding Checkmate"
				
			=> https://www.chess.com/lessons/intro-to-book-openings
				=> mkdir "Intro to Book Openings"
	
	====> Intermediate (Key Concepts)
	mkdir Intermediate (Key Concepts)
	
	====> Advanced (Taking Control)
	mkdir Advanced (Taking Control)

	
	
	*/
	
}
Post Reply