Rev 2 | Rev 8 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2 | Rev 7 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | // ViaThinkSoft YouTube Downloader Functions 2.1 |
3 | // ViaThinkSoft YouTube Downloader Functions 2.1 |
4 | // Revision: 2018-05-21 |
4 | // Revision: 2021-05-09 |
5 | // Author: Daniel Marschall <www.daniel-marschall.de> |
5 | // Author: Daniel Marschall <www.daniel-marschall.de> |
6 | // Licensed under the terms of GPLv3 |
6 | // Licensed under the terms of the Apache 2.0 License |
7 | 7 | ||
8 | // Get API key: https://console.developers.google.com/apis/credentials |
8 | // Get API key: https://console.developers.google.com/apis/credentials |
9 | // Test API here: https://developers.google.com/apis-explorer/?hl=de#p/youtube/v3/youtube.playlistItems.list |
9 | // Test API here: https://developers.google.com/apis-explorer/?hl=de#p/youtube/v3/youtube.playlistItems.list |
10 | 10 | ||
11 | $yt_apikey = null; |
11 | $yt_apikey = null; |
Line 175... | Line 175... | ||
175 | return $out; |
175 | return $out; |
176 | } |
176 | } |
177 | 177 | ||
178 | function getVideoIDFromURL($url) { |
178 | function getVideoIDFromURL($url) { |
179 | // Extract video ID from the URL |
179 | // Extract video ID from the URL |
180 | // TODO: are there more formats? |
- | |
181 | 180 | ||
182 | $vid = false; |
181 | $vid = false; |
- | 182 | $m = null; |
|
183 | 183 | ||
184 | # Usual format |
184 | # Usual format |
185 | if (($vid === false) && (preg_match("@https{0,1}://(www\\.|)youtube\\.com/watch(.*)(&|\\?)v=(.+)&@ismU", $url.'&', $m))) { |
185 | if (($vid === false) && (preg_match("@https{0,1}://(www\\.|)youtube\\.com/watch(.*)(&|\\?)v=([a-zA-Z0-9_-]{11})@ismU", $url, $m))) { |
186 | $vid = $m[4]; |
186 | $vid = $m[4]; |
187 | } |
187 | } |
188 | 188 | ||
189 | # Short format |
189 | # Short format |
190 | if (($vid === false) && (preg_match("@https{0,1}://(www\\.|)youtu\\.be/(.+)\$@ismU", $url, $m))) { |
190 | if (($vid === false) && (preg_match("@https{0,1}://(www\\.|)youtu\\.be/([a-zA-Z0-9_-]{11}))@ismU", $url, $m))) { |
- | 191 | $vid = $m[2]; |
|
- | 192 | } |
|
- | 193 | ||
- | 194 | # YouTube "Shorts" |
|
- | 195 | if (($vid === false) && (preg_match("@https{0,1}://(www\\.|)youtube\\.com/shorts/([a-zA-Z0-9_-]{11})@ismU", $url, $m))) { |
|
191 | $vid = $m[2]; |
196 | $vid = $m[2]; |
192 | } |
197 | } |
193 | 198 | ||
194 | return $vid; |
199 | return $vid; |
195 | } |
200 | } |
196 | 201 | ||
197 | function getPlaylistIDFromURL($url) { |
202 | function getPlaylistIDFromURL($url) { |
198 | $pid = false; |
203 | $pid = false; |
199 | 204 | ||
200 | # Usual format |
205 | # Usual format |
- | 206 | $m = null; |
|
201 | if (($pid === false) && (preg_match("@https{0,1}://(www\\.|)youtube\\.com/(.*)(&|\\?)list=(.+)&@ismU", $url.'&', $m))) { |
207 | if (($pid === false) && (preg_match("@https{0,1}://(www\\.|)youtube\\.com/(.*)(&|\\?)list=(.+)&@ismU", $url.'&', $m))) { |
202 | $pid = $m[4]; |
208 | $pid = $m[4]; |
203 | } |
209 | } |
204 | 210 | ||
205 | return $pid; |
211 | return $pid; |