diff options
Diffstat (limited to 'youtube_podcaster/podcastupdater.py')
| -rw-r--r-- | youtube_podcaster/podcastupdater.py | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/youtube_podcaster/podcastupdater.py b/youtube_podcaster/podcastupdater.py index 75b8b10..8afebfa 100644 --- a/youtube_podcaster/podcastupdater.py +++ b/youtube_podcaster/podcastupdater.py | |||
| @@ -10,11 +10,14 @@ from . import ( | |||
| 10 | youtube, | 10 | youtube, |
| 11 | ) | 11 | ) |
| 12 | 12 | ||
| 13 | from threading import Thread | ||
| 14 | |||
| 13 | 15 | ||
| 14 | class PodcastUpdater: | 16 | class PodcastUpdater: |
| 15 | def __init__(self, config): | 17 | def __init__(self, config): |
| 16 | self.podcasts = config.podcasts | 18 | self.podcasts = config.podcasts |
| 17 | self.youtube = youtube.Youtube(config.youtube["api-key"]) | 19 | self.youtube = youtube.Youtube(config.youtube["api-key"]) |
| 20 | self.downloads = config.downloads | ||
| 18 | 21 | ||
| 19 | if sys.platform == "linux" and not hasattr(sys, "real_prefix"): | 22 | if sys.platform == "linux" and not hasattr(sys, "real_prefix"): |
| 20 | self.data_dir = "/var/lib/youtube-podcaster" | 23 | self.data_dir = "/var/lib/youtube-podcaster" |
| @@ -95,7 +98,14 @@ class PodcastUpdater: | |||
| 95 | 98 | ||
| 96 | def populate_feed(self, feed, feed_id, yt_playlist, max_results=5): | 99 | def populate_feed(self, feed, feed_id, yt_playlist, max_results=5): |
| 97 | videos = self.youtube.get_playlist_items(yt_playlist, max_results) | 100 | videos = self.youtube.get_playlist_items(yt_playlist, max_results) |
| 98 | downloader = youtube.Downloader.get_instance("vorbis", "downloads", "192.168.178.100") | 101 | |
| 102 | file_format = self.downloads["format"] | ||
| 103 | download_path = self.downloads["path"] | ||
| 104 | download_url = self.downloads["url"] | ||
| 105 | |||
| 106 | downloader = youtube.Downloader.get_instance(file_format, download_path, download_url) | ||
| 107 | |||
| 108 | threads = [] | ||
| 99 | 109 | ||
| 100 | entries = feed.entry() | 110 | entries = feed.entry() |
| 101 | for video in videos: | 111 | for video in videos: |
| @@ -104,17 +114,27 @@ class PodcastUpdater: | |||
| 104 | if entry.id() == video_id: | 114 | if entry.id() == video_id: |
| 105 | break | 115 | break |
| 106 | else: | 116 | else: |
| 107 | url, size, mime = downloader.download(video, video_id, feed_id) | 117 | t = Thread(target=self.process_video, args=(downloader, video, video_id, feed_id)) |
| 108 | 118 | threads.append(t) | |
| 109 | feed_entry = feed.add_entry() | 119 | t.start() |
| 110 | 120 | ||
| 111 | feed_entry.id(video_id) | 121 | for t in threads: |
| 112 | feed_entry.guid(video_id) | 122 | t.join() |
| 113 | feed_entry.title(video["snippet"]["title"]) | ||
| 114 | feed_entry.description(video["snippet"]["description"]) | ||
| 115 | feed_entry.published(video["snippet"]["publishedAt"]) | ||
| 116 | feed_entry.enclosure(url, size, mime) | ||
| 117 | 123 | ||
| 118 | feed.last_updated = time.time() | 124 | feed.last_updated = time.time() |
| 119 | 125 | ||
| 126 | def process_video(self, downloader, video, video_id, feed_id): | ||
| 127 | url, size, mime = downloader.download(video, video_id, feed_id) | ||
| 128 | |||
| 129 | feed = self.feeds[feed_id] | ||
| 130 | feed_entry = feed.add_entry() | ||
| 131 | |||
| 132 | feed_entry.id(video_id) | ||
| 133 | feed_entry.guid(video_id) | ||
| 134 | feed_entry.title(video["snippet"]["title"]) | ||
| 135 | feed_entry.description(video["snippet"]["description"]) | ||
| 136 | feed_entry.published(video["snippet"]["publishedAt"]) | ||
| 137 | feed_entry.enclosure(url, size, mime) | ||
| 138 | |||
| 139 | |||
| 120 | # vim: set ts=8 sw=4 tw=0 et : | 140 | # vim: set ts=8 sw=4 tw=0 et : |
