Subversion Repositories yt_downloader

Rev

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

Rev 13 Rev 14
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.3
5
// Revision: 2022-02-06
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.
Line 19... Line 19...
19
define('DEFAULT_SEARCH_MAXRESULTS', 10);
19
define('DEFAULT_SEARCH_MAXRESULTS', 10);
20
 
20
 
21
putenv("LANG=de_DE.UTF-8"); // required if video titles contain non-ASCII symbols
21
putenv("LANG=de_DE.UTF-8"); // required if video titles contain non-ASCII symbols
22
 
22
 
23
require_once __DIR__ . '/youtube_functions.inc.phps';
23
require_once __DIR__ . '/youtube_functions.inc.phps';
-
 
24
require_once __DIR__ . '/checksum_functions.inc.phps';
24
 
25
 
25
// Check if we are running in command line
26
// Check if we are running in command line
26
 
27
 
27
if (PHP_SAPI !== 'cli') {
28
if (PHP_SAPI !== 'cli') {
28
	fwrite(STDERR, "Error: Can only run in CLI mode\n");
29
	fwrite(STDERR, "Error: Can only run in CLI mode\n");
Line 37... Line 38...
37
 
38
 
38
$allow_creation_outputdir = false;
39
$allow_creation_outputdir = false;
39
$type = 'v:';
40
$type = 'v:';
40
$outputDir = '';
41
$outputDir = '';
41
$alreadyDownloaded = '';
42
$alreadyDownloaded = '';
-
 
43
$checksumMode = 'none';
42
$failList = '';
44
$failList = '';
43
$failTreshold = 3;
45
$failTreshold = 3;
44
$rest_args = array();
46
$rest_args = array();
45
$verbose = false;
47
$verbose = false;
46
$mp3id_transfer = true;
48
$mp3id_transfer = true;
Line 85... Line 87...
85
		$failTreshold = $m[3];
87
		$failTreshold = $m[3];
86
	} else if (preg_match('@^(/C|\-C|\-\-resultcache)(\s+|=)(.*)$@s', $arg2, $m)) {
88
	} else if (preg_match('@^(/C|\-C|\-\-resultcache)(\s+|=)(.*)$@s', $arg2, $m)) {
87
		array_shift($argv_bak);
89
		array_shift($argv_bak);
88
		if (count($rest_args) > 0) syntax_error("Invalid argument: ".$rest_args[0]);
90
		if (count($rest_args) > 0) syntax_error("Invalid argument: ".$rest_args[0]);
89
		$resultcache = $m[3];
91
		$resultcache = $m[3];
-
 
92
	} else if (preg_match('@^(/H|\-H|\-\-checksumMode)(\s+|=)(.*)$@s', $arg2, $m)) {
-
 
93
		array_shift($argv_bak);
-
 
94
		if (count($rest_args) > 0) syntax_error("Invalid argument: ".$rest_args[0]);
-
 
95
		$checksumMode = $m[3];
-
 
96
		if ((strtolower($checksumMode) != 'none')
-
 
97
			&& (strtolower($checksumMode) != 'sfv')
-
 
98
			&& (strtolower($checksumMode) != 'md5')
-
 
99
			&& (strtolower($checksumMode) != 'sfv,md5')
-
 
100
			&& (strtolower($checksumMode) != 'md5,sfv')) syntax_error("Checksum mode needs to be either 'None', 'MD5', 'SFV', or 'MD5,SFV'.");
90
	} else if (preg_match('@^(/T|\-T|\-\-default-template)(\s+|=)(.*)$@s', $arg2, $m)) {
101
	} else if (preg_match('@^(/T|\-T|\-\-default-template)(\s+|=)(.*)$@s', $arg2, $m)) {
91
		array_shift($argv_bak);
102
		array_shift($argv_bak);
92
		if (count($rest_args) > 0) syntax_error("Invalid argument: ".$rest_args[0]);
103
		if (count($rest_args) > 0) syntax_error("Invalid argument: ".$rest_args[0]);
93
		$default_template = $m[3];
104
		$default_template = $m[3];
94
	} else if (preg_match('@^(/A|\-A|\-\-api-key)(\s+|=)(.*)$@s', $arg2, $m)) {
105
	} else if (preg_match('@^(/A|\-A|\-\-api-key)(\s+|=)(.*)$@s', $arg2, $m)) {
Line 486... Line 497...
486
	global $mp3id_transfer;
497
	global $mp3id_transfer;
487
	global $extra_args;
498
	global $extra_args;
488
	global $default_template;
499
	global $default_template;
489
	global $failTreshold;
500
	global $failTreshold;
490
	global $cookie_file;
501
	global $cookie_file;
-
 
502
	global $checksumMode;
491
 
503
 
492
	if (DOWNLOAD_SIMULATION_MODE) {
504
	if (DOWNLOAD_SIMULATION_MODE) {
493
		echo "SIMULATE download of video id $video_id as ".hf_type($type)." to "._getOutputDir()."\n";
505
		echo "SIMULATE download of video id $video_id as ".hf_type($type)." to "._getOutputDir()."\n";
494
		return;
506
		return;
495
	}
507
	}
Line 530... Line 542...
530
		if ($verbose) fwrite(STDOUT, "Successfully downloaded video ID $video_id as ".hf_type($type)."\n");
542
		if ($verbose) fwrite(STDOUT, "Successfully downloaded video ID $video_id as ".hf_type($type)."\n");
531
		if (!empty(_getAlreadyDownloaded())) {
543
		if (!empty(_getAlreadyDownloaded())) {
532
			try {
544
			try {
533
				addto_alreadydownloaded_file($type, $video_id);
545
				addto_alreadydownloaded_file($type, $video_id);
534
			} catch(Exception $e) {
546
			} catch(Exception $e) {
535
				fwrite(STDERR, "Cannot add to already downloaded file\n");
547
				fwrite(STDERR, "Cannot add to 'already downloaded' file\n");
-
 
548
			}
-
 
549
		}
-
 
550
 
-
 
551
		// Now do the checksums
-
 
552
		foreach (explode(',',$checksumMode) as $mode) {
-
 
553
			$test = glob(rtrim(_getOutputDir(), '/').'/*-'.$video_id.'.*');
-
 
554
			if (count($test) == 0) {
-
 
555
				fwrite(STDERR, "Cannot determine output file name.\n");
-
 
556
			}
-
 
557
			$written_file = $test[0];
-
 
558
			if (!cs_add_automatically($written_file, $mode)) {
-
 
559
				fwrite(STDERR, "Could not write to '$mode' checksum file!\n");
536
			}
560
			}
537
		}
561
		}
538
	} else {
562
	} else {
539
		fwrite(STDERR, "Error downloading $video_id! (Code $code)\n");
563
		fwrite(STDERR, "Error downloading $video_id! (Code $code)\n");
540
		if (!empty(_getFailList())) {
564
		if (!empty(_getFailList())) {