diff options
-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); +} + ?> |