-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.php
More file actions
54 lines (44 loc) · 1.46 KB
/
Copy pathmain.php
File metadata and controls
54 lines (44 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
//Derive Settings
$local_folder = $local_parent_folder . $local_subfolder ."/";
$rss_file = basename($rss_url);
//Download RSS File
shell_exec("wget -N " . $rss_url . " -P " . $local_folder);
//Open RSS File as XML
$rss_xml=simplexml_load_file( $local_folder . $rss_file) or die("Error opening XML");
//Get Podcast URLs from the XML
$podcasts_to_download = array();
$i=0;
foreach($rss_xml->channel->children() as $podcast) {
if($i <= $n_podcasts_to_download){
$podcast_url = $podcast->link[0];
$podcast_url = preg_replace('/\?.*/', '', $podcast_url);
array_push($podcasts_to_download, $podcast_url);
$i++;
}
}
//Check Podcast URLs and if they meet the criteria (correct file extension, not already downloaded), download them
foreach($podcasts_to_download as $item){
//Comment these out in PROD - only for debugging
echo $item . "\n";
echo basename($item) . "\n";
$continue = true;
if(file_exists( $local_folder."/".basename($item) )){
$continue = false;
echo basename($item) . " already downloaded! \n";
}else{}
$ext = pathinfo( basename($item) , PATHINFO_EXTENSION);
switch($ext){
case "mp3":{}
case "mp4":{}
break;
default: {
$continue = false;
}
}
if($continue == true){
echo "downloading ". basename($item) . "\n";
shell_exec("wget " . $item . " -P " . $local_folder);
}else{}
}
?>