49 lines
1.3 KiB
PHP
49 lines
1.3 KiB
PHP
#!/bin/php
|
|
|
|
<?php
|
|
|
|
include 'FeedParser.php';
|
|
|
|
$feeds = [
|
|
'https://www.youtube.com/feeds/videos.xml?channel_id=UCAFQjCZo5okIPkHUQlBZM-g',
|
|
'https://www.youtube.com/feeds/videos.xml?channel_id=UCk-_PEY3iC6DIGJKuoEe9bw',
|
|
];
|
|
|
|
$to_download = [];
|
|
|
|
foreach ($feeds as $feed) {
|
|
|
|
$to_add = [];
|
|
|
|
$url = $feed;
|
|
$parts = parse_url($url);
|
|
$file = sprintf('%s/%s-%s.json', __DIR__, basename($parts['path']), $parts['query']);
|
|
$first = null;
|
|
if (!file_exists($file)) {
|
|
touch($file);
|
|
$content = [];
|
|
} else {
|
|
$content = json_decode(file_get_contents($file));
|
|
$first = isset($content[0]) ? $content[0] : null;
|
|
}
|
|
|
|
$rss = new FeedParser();
|
|
|
|
$rss->parse($feed);
|
|
$items = $rss->getItems();
|
|
|
|
foreach ($items as $article) {
|
|
$link = sprintf('http://www.youtube.com/watch?v=%s', $article['YT:VIDEOID']);
|
|
if (!in_array($link, $content)) {
|
|
$to_add[] = $link;
|
|
$to_download[] = $link;
|
|
}
|
|
}
|
|
|
|
file_put_contents($file, json_encode(array_merge($content, $to_add)));
|
|
}
|
|
|
|
foreach ($to_download as $url) {
|
|
// https://www.reddit.com/r/selfhosted/comments/60hus4/searching_for_a_youtube_2_podcast_solution/
|
|
shell_exec("youtube-dl --extract-audio --audio-format mp3 -o '/volume1/music/Podcast/Youtube/%(upload_date)s-%(uploader)s-%(title)s.%(ext)s' $url");
|
|
} |