Subversion Repositories yt_downloader

Rev

Rev 12 | Rev 14 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 12 Rev 13
Line 1... Line 1...
1
#!/usr/bin/php
1
#!/usr/bin/php
2
<?php
2
<?php
3
 
3
 
4
// ViaThinkSoft YouTube Downloader Util 2.2
4
// ViaThinkSoft YouTube Downloader Util 2.2
5
// Revision: 2022-02-05
5
// Revision: 2022-02-06
6
// Author: Daniel Marschall <www.daniel-marschall.de>
6
// Author: Daniel Marschall <www.daniel-marschall.de>
7
// Licensed under the terms of the Apache 2.0 License
7
// Licensed under the terms of the Apache 2.0 License
8
//
8
//
9
// For syntax and other documentation, please read the file README.
9
// For syntax and other documentation, please read the file README.
10
 
10
 
Line 157... Line 157...
157
		if (file_exists(__DIR__.'/youtube-dl')) {
157
		if (file_exists(__DIR__.'/youtube-dl')) {
158
			echo "Trying to update 'youtube-dl' in local directory...\n";
158
			echo "Trying to update 'youtube-dl' in local directory...\n";
159
		} else {
159
		} else {
160
			echo "Trying to download 'youtube-dl' into local directory...\n";
160
			echo "Trying to download 'youtube-dl' into local directory...\n";
161
		}
161
		}
-
 
162
 
-
 
163
		@chmod(__DIR__.'/youtube-dl', 0777); // otherwise we might not be able to write to it
-
 
164
 
162
		if (!@file_put_contents(__DIR__.'/youtube-dl', file_get_contents('https://yt-dl.org/downloads/latest/youtube-dl'))) {
165
		if (!($binary = file_get_contents('https://yt-dl.org/latest/youtube-dl'))) {
163
			fwrite(STDERR, "Failed to download 'youtube-dl' into local directory (file_get_contents).\n");
166
			fwrite(STDERR, "Failed to download 'youtube-dl' into local directory (file_get_contents).\n");
-
 
167
		} else if (!@file_put_contents(__DIR__.'/youtube-dl', $binary)) {
-
 
168
			fwrite(STDERR, "Failed to download 'youtube-dl' into local directory (file_put_contents).\n");
164
		} else {
169
		} else {
165
			if (!@chmod(__DIR__.'/youtube-dl', 0544)) {
170
			if (!@chmod(__DIR__.'/youtube-dl', 0544)) {
166
				fwrite(STDERR, "Failed to download 'youtube-dl' into local directory (chmod 544).\n");
171
				fwrite(STDERR, "Failed to download 'youtube-dl' into local directory (chmod 544).\n");
167
				@unlink(__DIR__.'/youtube-dl'); // try to delete, otherwise we might try to execute a non-executable file
172
				@unlink(__DIR__.'/youtube-dl'); // try to delete, otherwise we might try to execute a non-executable file
168
			}
173
			}
Line 249... Line 254...
249
		$search = parse_quoting($search);
254
		$search = parse_quoting($search);
250
 
255
 
251
		$channel_name = parse_quoting($channel_name);
256
		$channel_name = parse_quoting($channel_name);
252
		$channel_id = yt_get_channel_id($channel_name);
257
		$channel_id = yt_get_channel_id($channel_name);
253
		if (!$channel_id) {
258
		if (!$channel_id) {
254
			fwrite(STDERR, "URL $channel_name is a valid YouTube channel or username. Skipping.\n");
259
			fwrite(STDERR, "URL $channel_name is a valid YouTube username. Will now try to interprete it as channel ID instead....\n");
255
		} else {
-
 
256
			ytdwn_channel_id($channel_id, $search);
-
 
257
		}
260
		}
-
 
261
		ytdwn_channel_id($channel_id, $search);
258
	} else if ($resourceType == 'curl') {
262
	} else if ($resourceType == 'curl') {
259
		$channel_url = parse_quoting($resourceValue);
263
		$channel_url = parse_quoting($resourceValue);
260
 
264
 
261
		$m = null;
265
		$m = null;
262
		if (preg_match('@\[search=(.+)\]@ismU', $channel_url, $m)) {
266
		if (preg_match('@\[search=(.+)\]@ismU', $channel_url, $m)) {
Line 596... Line 600...
596
	}
600
	}
597
	return $allok;
601
	return $allok;
598
}
602
}
599
 
603
 
600
function curl_to_cid($channel_url) {
604
function curl_to_cid($channel_url) {
601
	$m = null;
-
 
602
	if (preg_match("@https{0,1}://(www\\.|)youtube\\.com/user/(.*)(/|&|\\?)@ismU", $channel_url.'&', $m)) {
-
 
603
		$username = $m[2];
-
 
604
		$channel_id = yt_get_channel_id($username);
605
	return yt_get_channel_id_from_url($channel_url);
605
		return $channel_id;
-
 
606
	} else if (preg_match("@https{0,1}://(www\\.|)youtube\\.com/(channel|c)/(.*)(/|&|\\?)@ismU", $channel_url.'&', $m)) {
-
 
607
		$channel_id = $m[3];
-
 
608
		return $channel_id;
-
 
609
	} else {
-
 
610
		return false;
-
 
611
	}
-
 
612
}
606
}
613
 
607
 
614
function in_alreadydownloaded_file($type, $video_id) {
608
function in_alreadydownloaded_file($type, $video_id) {
615
	$lines = file(_getAlreadyDownloaded());
609
	$lines = file(_getAlreadyDownloaded());
616
	foreach ($lines as $line) {
610
	foreach ($lines as $line) {