Rev 14 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 14 | Rev 15 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | // ViaThinkSoft YouTube Downloader Util 2.3 |
3 | // ViaThinkSoft YouTube Downloader Util 2.3 |
4 | // Revision: 2022-02-06 |
4 | // Revision: 2022-02-07 |
5 | // Author: Daniel Marschall <www.daniel-marschall.de> |
5 | // Author: Daniel Marschall <www.daniel-marschall.de> |
6 | // Licensed under the terms of the Apache 2.0 License |
6 | // Licensed under the terms of the Apache 2.0 License |
7 | 7 | ||
8 | function cs_get_checksumfilename($file, $type='sfv') { |
8 | function cs_get_checksumfilename($file, $type='sfv') { |
9 | $dir = dirname($file); |
9 | $dir = dirname($file); |
Line 16... | Line 16... | ||
16 | } |
16 | } |
17 | return $cs_file; |
17 | return $cs_file; |
18 | } |
18 | } |
19 | 19 | ||
20 | function cs_add_automatically($file, $type='sfv') { |
20 | function cs_add_automatically($file, $type='sfv') { |
- | 21 | $type = strtolower($type); |
|
21 | $cs_file = cs_get_checksumfilename($file, $type); |
22 | $cs_file = cs_get_checksumfilename($file, $type); |
22 | // echo "Checksum file: $cs_file\n"; |
23 | // echo "Checksum file: $cs_file\n"; |
23 | if (strtolower($type) == 'sfv') { |
24 | if ($type == 'sfv') { |
24 | if (file_exists($cs_file)) { |
25 | if (file_exists($cs_file)) { |
25 | $files = sfv_get_files($cs_file); |
26 | $files = sfv_get_files($cs_file); |
26 | if (in_arrayi(basename($file), $files)) return true; |
27 | if (in_arrayi(basename($file), $files)) return true; |
27 | } else { |
28 | } else { |
28 | file_put_contents($cs_file, "; Generated by ViaThinkSoft\r\n"); // TODO: BOM |
29 | file_put_contents($cs_file, "; Generated by ViaThinkSoft\r\n"); // TODO: BOM |
Line 35... | Line 36... | ||
35 | } |
36 | } |
36 | $crc32 = strtoupper($hash); |
37 | $crc32 = strtoupper($hash); |
37 | file_put_contents($cs_file, basename($file)." $crc32\r\n", FILE_APPEND); |
38 | file_put_contents($cs_file, basename($file)." $crc32\r\n", FILE_APPEND); |
38 | return true; |
39 | return true; |
39 | } |
40 | } |
40 | else if (strtolower($type) == 'md5') { |
41 | else if ($type == 'md5') { |
41 | if (file_exists($cs_file)) { |
42 | if (file_exists($cs_file)) { |
42 | $files = md5_get_files($cs_file); |
43 | $files = md5_get_files($cs_file); |
43 | if (in_arrayi(basename($file), $files)) return true; |
44 | if (in_arrayi(basename($file), $files)) return true; |
44 | } else { |
45 | } else { |
45 | file_put_contents($cs_file, "; Generated by ViaThinkSoft\r\n"); // TODO: BOM |
46 | file_put_contents($cs_file, "; Generated by ViaThinkSoft\r\n"); // TODO: BOM |
Line 52... | Line 53... | ||
52 | } |
53 | } |
53 | $md5 = strtolower($hash); |
54 | $md5 = strtolower($hash); |
54 | file_put_contents($cs_file, "$md5 *".basename($file)."\r\n", FILE_APPEND); |
55 | file_put_contents($cs_file, "$md5 *".basename($file)."\r\n", FILE_APPEND); |
55 | return true; |
56 | return true; |
56 | } |
57 | } |
57 | else if (strtolower($type) == 'none') { |
58 | else if ($type == 'none') { |
58 | return true; |
59 | return true; |
59 | } |
60 | } |
60 | else { |
61 | else { |
61 | fwrite(STDERR, "Unknown checksum type '$type'. Must be SFV, MD5 or None\n"); |
62 | fwrite(STDERR, "Unknown checksum type '$type'. Must be SFV, MD5 or None\n"); |
62 | return false; |
63 | return false; |