Subversion Repositories yt_downloader

Rev

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

Rev 18 Rev 19
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.2
4
// ViaThinkSoft YouTube Downloader Util 2.3.3
5
// Revision: 2022-09-21
5
// Revision: 2022-12-19
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 189... Line 189...
189
	if ($verbose) echo "Handle: $resource\n";
189
	if ($verbose) echo "Handle: $resource\n";
190
	if (strpos($resource, ':') === false) {
190
	if (strpos($resource, ':') === false) {
191
		fwrite(STDERR, "Invalid resource '$resource' (you are missing the prefix, e.g. vurl: or vid:). Skipping.\n");
191
		fwrite(STDERR, "Invalid resource '$resource' (you are missing the prefix, e.g. vurl: or vid:). Skipping.\n");
192
	} else {
192
	} else {
193
		list($resourceType, $resourceValue) = explode(':', $resource, 2);
193
		list($resourceType, $resourceValue) = explode(':', $resource, 2);
-
 
194
		try {
194
		ytdwn_handle_resource($resourceType, $resourceValue);
195
			ytdwn_handle_resource($resourceType, $resourceValue);
-
 
196
		} catch(Exception $e) {
-
 
197
			fwrite(STDERR, "Error at '$resourceType:$resourceValue': ".$e->getMessage()."\n");
-
 
198
		}
195
	}
199
	}
196
}
200
}
197
 
201
 
198
// ------------------------------------------------------------------------------------------------
202
// ------------------------------------------------------------------------------------------------
199
 
203
 
Line 322... Line 326...
322
		if ($line[0] == '#') continue;
326
		if ($line[0] == '#') continue;
323
		if (strpos($line, ':') === false) {
327
		if (strpos($line, ':') === false) {
324
			fwrite(STDERR, "Invalid resource '$line' (you are missing the prefix, e.g. vurl: or vid:). Skipping.\n");
328
			fwrite(STDERR, "Invalid resource '$line' (you are missing the prefix, e.g. vurl: or vid:). Skipping.\n");
325
		} else {
329
		} else {
326
			list($resourceType, $resourceValue) = explode(':',$line,2);
330
			list($resourceType, $resourceValue) = explode(':',$line,2);
-
 
331
			try {
327
			ytdwn_handle_resource($resourceType, $resourceValue);
332
				ytdwn_handle_resource($resourceType, $resourceValue);
-
 
333
			} catch(Exception $e) {
-
 
334
				fwrite(STDERR, "Error at line '$line': ".$e->getMessage()."\n");
-
 
335
			}
328
		}
336
		}
329
	}
337
	}
330
	array_pop($listFilenameStack);
338
	array_pop($listFilenameStack);
331
}
339
}
332
 
340
 
Line 368... Line 376...
368
			$out[$key]['results'] = yt_channel_items($channel_id, $search);
376
			$out[$key]['results'] = yt_channel_items($channel_id, $search);
369
		} else {
377
		} else {
370
			$out[$key]['results'] = yt_channel_items($channel_id);
378
			$out[$key]['results'] = yt_channel_items($channel_id);
371
		}
379
		}
372
		if (!$out[$key]['results']) {
380
		if (!$out[$key]['results']) {
-
 
381
			// TODO: If a channel has deleted all videos, then this message comes.
-
 
382
			//       However, technically this is not an error.
373
			fwrite(STDERR, "Cannot get result for channel with ID '$channel_id'\n");
383
			fwrite(STDERR, "Cannot get result for channel with ID '$channel_id'\n");
374
			return;
384
			return;
375
		}
385
		}
376
	} else {
386
	} else {
377
		if ($verbose) echo "Video count for channel is still $videocount, keep ".count($out[$key]['results'])." results.\n";
387
		if ($verbose) echo "Video count for channel is still $videocount, keep ".count($out[$key]['results'])." results.\n";
Line 386... Line 396...
386
	}
396
	}
387
 
397
 
388
	// Now download
398
	// Now download
389
 
399
 
390
	if (!$out[$key]['results']) {
400
	if (!$out[$key]['results']) {
-
 
401
		// TODO: If a channel has deleted all videos, then this message comes.
-
 
402
		//       However, technically this is not an error.
391
		fwrite(STDERR, "Cannot get result for channel with ID '$channel_id'\n");
403
		fwrite(STDERR, "Cannot get result for channel with ID '$channel_id'\n");
392
		return;
404
		return;
393
	}
405
	}
394
	foreach ($out[$key]['results'] as list($id, $title)) {
406
	foreach ($out[$key]['results'] as list($id, $title)) {
395
		if ($verbose) echo "Downloading '$title' as ".hf_type($type)." ...\n";
407
		if ($verbose) echo "Downloading '$title' as ".hf_type($type)." ...\n";
Line 431... Line 443...
431
	if ($videocount_old != $videocount) { // Attention: This might not work if videos are deleted and added (= the count stays the same)
443
	if ($videocount_old != $videocount) { // Attention: This might not work if videos are deleted and added (= the count stays the same)
432
		if ($verbose && $use_cache) echo "Video count changed from $videocount_old to $videocount\n";
444
		if ($verbose && $use_cache) echo "Video count changed from $videocount_old to $videocount\n";
433
		$out[$key]['count'] = $videocount;
445
		$out[$key]['count'] = $videocount;
434
		$out[$key]['results'] = yt_playlist_items($playlist_id);
446
		$out[$key]['results'] = yt_playlist_items($playlist_id);
435
		if (!$out[$key]['results']) {
447
		if (!$out[$key]['results']) {
-
 
448
			// TODO: If a playlist has deleted all videos, then this message comes.
-
 
449
			//       However, technically this is not an error.
436
			fwrite(STDERR, "Cannot get result for playlist with ID '$playlist_id'\n");
450
			fwrite(STDERR, "Cannot get result for playlist with ID '$playlist_id'\n");
437
			return;
451
			return;
438
		}
452
		}
439
	} else {
453
	} else {
440
		if ($verbose) echo "Video count for playlist is still $videocount, keep ".count($out[$key]['results'])." results.\n";
454
		if ($verbose) echo "Video count for playlist is still $videocount, keep ".count($out[$key]['results'])." results.\n";
Line 886... Line 900...
886
	$file = _getFailList();
900
	$file = _getFailList();
887
	$cont = file_get_contents($file);
901
	$cont = file_get_contents($file);
888
	$m = null;
902
	$m = null;
889
	if (preg_match("@Video ID ".preg_quote($video_id,'@')." failed (\d+) time\(s\) with type ".preg_quote($type,'@')."@ismU", $cont, $m)) {
903
	if (preg_match("@Video ID ".preg_quote($video_id,'@')." failed (\d+) time\(s\) with type ".preg_quote($type,'@')."@ismU", $cont, $m)) {
890
		$cont = preg_replace("@Video ID ".preg_quote($video_id,'@')." failed (\d+) time\(s\) with type ".preg_quote($type,'@')."@ismU",
904
		$cont = preg_replace("@Video ID ".preg_quote($video_id,'@')." failed (\d+) time\(s\) with type ".preg_quote($type,'@')."@ismU",
891
		                     "Video ID $video_id failed ".($m[1]+1)." time(s) with type $type", $cont);
905
		                     "Video ID $video_id failed ".(((int)$m[1])+1)." time(s) with type $type", $cont);
892
		file_put_contents($file, $cont);
906
		file_put_contents($file, $cont);
893
	} else {
907
	} else {
894
		file_put_contents($file, "Video ID $video_id failed 1 time(s) with type $type\n", FILE_APPEND);
908
		file_put_contents($file, "Video ID $video_id failed 1 time(s) with type $type\n", FILE_APPEND);
895
	}
909
	}
896
}
910
}