Rev 20 | Rev 22 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 20 | Rev 21 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | #!/usr/bin/php |
1 | #!/usr/bin/php |
2 | <?php |
2 | <?php |
3 | 3 | ||
4 | // ViaThinkSoft YouTube Downloader Util 2.4 |
4 | // ViaThinkSoft YouTube Downloader Util 2.4.1 |
5 | // Revision: 2022-12-27 |
5 | // Revision: 2023-06-10 |
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 635... | Line 635... | ||
635 | 635 | ||
636 | function EndsWith($Haystack, $Needle){ |
636 | function EndsWith($Haystack, $Needle){ |
637 | return strrpos($Haystack, $Needle) === strlen($Haystack)-strlen($Needle); |
637 | return strrpos($Haystack, $Needle) === strlen($Haystack)-strlen($Needle); |
638 | } |
638 | } |
639 | 639 | ||
- | 640 | /** |
|
- | 641 | * Tries to put the video ID into the MP3 meta tags, and then removes the ID |
|
- | 642 | * from the file name. |
|
- | 643 | * @param $written_file |
|
- | 644 | * @param $video_id |
|
- | 645 | * @return bool |
|
- | 646 | */ |
|
640 | function mp3_transfer_vid_to_id(&$written_file, $video_id) { |
647 | function mp3_transfer_vid_to_id(&$written_file, $video_id) { |
641 | global $verbose; |
648 | global $verbose; |
642 | global $default_template; |
649 | global $default_template; |
643 | 650 | ||
644 | if (!command_exists('id3v2')) { |
651 | if (!command_exists('id3v2')) { |
Line 932... | Line 939... | ||
932 | } else { |
939 | } else { |
933 | return 0; |
940 | return 0; |
934 | } |
941 | } |
935 | } |
942 | } |
936 | 943 | ||
- | 944 | /** |
|
- | 945 | * @param string $fileName |
|
- | 946 | * @param bool $caseSensitive |
|
- | 947 | * @return bool |
|
- | 948 | * @see https://stackoverflow.com/questions/3964793/php-case-insensitive-version-of-file-exists |
|
- | 949 | */ |
|
- | 950 | function file_exists_ext(string $fileName, bool $caseSensitive = true): bool { |
|
- | 951 | if(file_exists($fileName)) { |
|
- | 952 | return true; // $fileName; |
|
- | 953 | } |
|
- | 954 | if($caseSensitive) return false; |
|
- | 955 | ||
- | 956 | // Handle case insensitive requests |
|
- | 957 | $directoryName = dirname($fileName); |
|
- | 958 | $fileArray = glob($directoryName . '/*', GLOB_NOSORT); |
|
- | 959 | $fileNameLowerCase = strtolower($fileName); |
|
- | 960 | foreach($fileArray as $file) { |
|
- | 961 | if(strtolower($file) == $fileNameLowerCase) { |
|
- | 962 | return true; // $file; |
|
- | 963 | } |
|
- | 964 | } |
|
- | 965 | return false; |
|
- | 966 | } |
|
- | 967 | ||
937 | function intelligent_rename($src, &$dest) { |
968 | function intelligent_rename($src, &$dest) { |
938 | $pos = strrpos($dest, '.'); |
969 | $pos = strrpos($dest, '.'); |
939 | $ext = substr($dest, $pos); |
970 | $ext = substr($dest, $pos); |
940 | $namewoext = substr($dest, 0, $pos); |
971 | $namewoext = substr($dest, 0, $pos); |
941 | $failcnt = 1; |
972 | $duplicate_count = 1; |
942 | $dest_neu = $dest; |
973 | $dest_neu = $dest; |
943 | while (file_exists($dest_neu)) { |
974 | while (file_exists_ext($dest_neu, false)) { |
944 | $failcnt++; |
975 | $duplicate_count++; |
945 | $dest_neu = "$namewoext ($failcnt)$ext"; |
976 | $dest_neu = "$namewoext ($duplicate_count)$ext"; |
946 | } |
977 | } |
947 | $res = rename($src, $dest_neu); |
978 | $res = rename($src, $dest_neu); |
948 | if ($res) $dest = $dest_neu; |
979 | if ($res) $dest = $dest_neu; |
949 | return $res; |
980 | return $res; |
950 | } |
981 | } |