diff options
author | Thorsten Ortlepp <post@ortlepp.eu> | 2021-09-29 00:38:41 +0200 |
---|---|---|
committer | Thorsten Ortlepp <post@ortlepp.eu> | 2021-09-29 00:38:41 +0200 |
commit | 5e3180be6b9aab92c84960e86a031c3b4107bb56 (patch) | |
tree | 16c295e4fc5aa3179b0ce80ea9fc58107b2d9257 | |
parent | 9ea8c4d0a37d7a2ed5a550d929df1d16ca1102d6 (diff) | |
download | php-stuff-5e3180be6b9aab92c84960e86a031c3b4107bb56.zip |
DLF changed from absolute to relative URLs
-rw-r--r-- | feed2podcast/feed2podcast.php | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/feed2podcast/feed2podcast.php b/feed2podcast/feed2podcast.php index 6f8f2a9..4c5f805 100644 --- a/feed2podcast/feed2podcast.php +++ b/feed2podcast/feed2podcast.php @@ -152,20 +152,20 @@ function downloadMediaFile($url, $id, $temp, $downloads) { // Download first playlist and get "inner" playlist preg_match_all($regex, download($url), $lines); - $playlist = array_values(array_filter($lines[1], "isUrl"))[0]; + $playlist = getUrlBase($url).(array_values(array_filter($lines[1], "isNotCommentLine"))[0]); // Download contents of "inner" playlist preg_match_all($regex, download($playlist), $urls); // Download all media file segments $counter = 0; - foreach (array_filter($urls[1], "isUrl") as $url) { + foreach (array_filter($urls[1], "isNotCommentLine") as $url) { $outfile = fopen($temp.'/'.$counter.'.ts', 'wb') or exit('File open failed'); $curl = curl_init(); curl_setopt($curl, CURLOPT_FILE, $outfile); curl_setopt($curl, CURLOPT_HEADER, 0); - curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt($curl, CURLOPT_URL, getUrlBase($playlist).$url); curl_exec($curl); curl_close($curl); @@ -207,9 +207,15 @@ function download($url) { } -// Check if a string looks like a url -function isUrl($var) { - return !(strpos( $var , 'http') === false); +// Check if a string does not look like a comment line +function isNotCommentLine($var) { + return (strcmp( substr( $var , 0, 1 ) , '#' ) !== 0); } + +// Get the base of an URL (= URL without last element) +function getUrlBase($url) { + return substr($url, 0, strripos($url, '/') + 1); +} + ?> |