Subversion Repositories yt_downloader

Rev

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

Rev 19 Rev 20
Line 1... Line 1...
1
#!/usr/bin/php
1
#!/usr/bin/php
2
<?php
2
<?php
3
 
3
 
4
// ViaThinkSoft YouTube Downloader Util 2.3.3
4
// ViaThinkSoft YouTube Downloader Util 2.4
5
// Revision: 2022-12-19
5
// Revision: 2022-12-27
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 54... Line 54...
54
              '-c ';  // resume partially downloaded video files
54
              '-c ';  // resume partially downloaded video files
55
$default_template = '%(title)s-%(id)s.%(ext)s';
55
$default_template = '%(title)s-%(id)s.%(ext)s';
56
$cookie_file = AUTO_COOKIE_FILE;
56
$cookie_file = AUTO_COOKIE_FILE;
57
$downloader = 'yt-dlp';
57
$downloader = 'yt-dlp';
58
 
58
 
-
 
59
if (($downloader == 'yt-dlp') && file_exists(__DIR__.'/ffmpeg')) {
-
 
60
	// With yt-dlp, you might get the error "ERROR: Postprocessing: Conversion failed!" if
-
 
61
	// you have a tool old ffmpeg version.
-
 
62
	$extra_args .= ' --ffmpeg-location '.escapeshellarg(__DIR__.'/ffmpeg');
-
 
63
}
-
 
64
 
59
// Parse arguments
65
// Parse arguments
60
// We do not use getopt() at the moment, because the important functionality "optind" is only available in PHP 7.1, which is not yet distributed with most of the stable Linux distros
66
// We do not use getopt() at the moment, because the important functionality "optind" is only available in PHP 7.1, which is not yet distributed with most of the stable Linux distros
61
 
67
 
62
$init_extra_args = false;
68
$init_extra_args = false;
63
$argv_bak = $_SERVER['argv'];
69
$argv_bak = $_SERVER['argv'];
Line 547... Line 553...
547
	$outputTemplate = rtrim(_getOutputDir(), '/').'/'.$default_template;
553
	$outputTemplate = rtrim(_getOutputDir(), '/').'/'.$default_template;
548
 
554
 
549
	if (substr($type,0,2) == 'v:') {
555
	if (substr($type,0,2) == 'v:') {
550
		$format = substr($type,2);
556
		$format = substr($type,2);
551
		if (!empty($format)) {
557
		if (!empty($format)) {
552
			exec(YTDL_EXE.' -o '.escapeshellarg($outputTemplate).' '.$extra_args.(empty($cookie_file) ? '' : ' --cookies '.$cookie_file).' '.escapeshellarg(vid_to_vurl($video_id)).' --format '.escapeshellarg($format), $out, $code);
558
			$cmd = YTDL_EXE.' -o '.escapeshellarg($outputTemplate).' '.$extra_args.(empty($cookie_file) ? '' : ' --cookies '.$cookie_file).' '.escapeshellarg(vid_to_vurl($video_id)).' --format '.escapeshellarg($format);
-
 
559
			echo "$cmd\n";
-
 
560
			exec($cmd, $out, $code);
553
		} else {
561
		} else {
554
			exec(YTDL_EXE.' -o '.escapeshellarg($outputTemplate).' '.$extra_args.(empty($cookie_file) ? '' : ' --cookies '.$cookie_file).' '.escapeshellarg(vid_to_vurl($video_id)), $out, $code);
562
			$cmd = YTDL_EXE.' -o '.escapeshellarg($outputTemplate).' '.$extra_args.(empty($cookie_file) ? '' : ' --cookies '.$cookie_file).' '.escapeshellarg(vid_to_vurl($video_id));
-
 
563
			echo "$cmd\n";
-
 
564
			exec($cmd, $out, $code);
555
		}
565
		}
556
 
566
 
557
		$written_file = $code == 0 ? ytdwn_get_downloaded_filename($outputTemplate, $video_id) : false;
567
		$written_file = $code == 0 ? ytdwn_get_downloaded_filename($outputTemplate, $video_id) : false;
558
 
568
 
559
	} else if (substr($type,0,2) == 'a:') {
569
	} else if (substr($type,0,2) == 'a:') {
560
		$format = substr($type,2);
570
		$format = substr($type,2);
561
		if (!empty($format)) {
571
		if (!empty($format)) {
562
			exec(YTDL_EXE.' -o '.escapeshellarg($outputTemplate).' '.$extra_args.(empty($cookie_file) ? '' : ' --cookies '.$cookie_file).' '.escapeshellarg(vid_to_vurl($video_id)).' --extract-audio --audio-format '.escapeshellarg($format), $out, $code);
572
			$cmd = YTDL_EXE.' -o '.escapeshellarg($outputTemplate).' '.$extra_args.(empty($cookie_file) ? '' : ' --cookies '.$cookie_file).' '.escapeshellarg(vid_to_vurl($video_id)).' --extract-audio --audio-format '.escapeshellarg($format);
-
 
573
			echo "$cmd\n";
-
 
574
			exec($cmd, $out, $code);
563
		} else {
575
		} else {
564
			exec(YTDL_EXE.' -o '.escapeshellarg($outputTemplate).' '.$extra_args.(empty($cookie_file) ? '' : ' --cookies '.$cookie_file).' '.escapeshellarg(vid_to_vurl($video_id)).' --extract-audio', $out, $code);
576
			$cmd = YTDL_EXE.' -o '.escapeshellarg($outputTemplate).' '.$extra_args.(empty($cookie_file) ? '' : ' --cookies '.$cookie_file).' '.escapeshellarg(vid_to_vurl($video_id)).' --extract-audio';
-
 
577
			echo "$cmd\n";
-
 
578
			exec($cmd, $out, $code);
565
		}
579
		}
566
 
580
 
567
		$written_file = $code == 0 ? ytdwn_get_downloaded_filename($outputTemplate, $video_id) : false;
581
		$written_file = $code == 0 ? ytdwn_get_downloaded_filename($outputTemplate, $video_id) : false;
568
 
582
 
569
		if (($code == 0) && ($mp3id_transfer) && (strtolower($format) == 'mp3')) {
583
		if (($code == 0) && ($mp3id_transfer) && (strtolower($format) == 'mp3')) {