aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--youtube_podcaster/podcastupdater.py2
-rw-r--r--youtube_podcaster/youtube/downloader.py18
2 files changed, 5 insertions, 15 deletions
diff --git a/youtube_podcaster/podcastupdater.py b/youtube_podcaster/podcastupdater.py
index 8afebfa..4ba4c8d 100644
--- a/youtube_podcaster/podcastupdater.py
+++ b/youtube_podcaster/podcastupdater.py
@@ -71,7 +71,7 @@ class PodcastUpdater:
71 feed = self.add_feed(feed_id, yt_playlist) 71 feed = self.add_feed(feed_id, yt_playlist)
72 72
73 if feed.last_updated < time.time() - 600: 73 if feed.last_updated < time.time() - 600:
74 self.populate_feed(feed, feed_id, yt_playlist) 74 self.populate_feed(feed, feed_id, yt_playlist, max_results=1)
75 feed.rss_file(feed_file) 75 feed.rss_file(feed_file)
76 76
77 with open(self.feeds_file, "wb") as feeds: 77 with open(self.feeds_file, "wb") as feeds:
diff --git a/youtube_podcaster/youtube/downloader.py b/youtube_podcaster/youtube/downloader.py
index 24fa1b0..bbae2e4 100644
--- a/youtube_podcaster/youtube/downloader.py
+++ b/youtube_podcaster/youtube/downloader.py
@@ -20,20 +20,11 @@ class Downloader:
20 self.location = location 20 self.location = location
21 self.base_url = base_url 21 self.base_url = base_url
22 22
23 self.downloaded = []
24
25 if file_format == "vorbis": 23 if file_format == "vorbis":
26 self.extension = "ogg" 24 self.extension = "ogg"
27 elif file_format == "opus": 25 elif file_format == "opus":
28 self.extension = "opus" 26 self.extension = "opus"
29 27
30 if sys.platform == "linux" and not hasattr(sys, "real_prefix"):
31 self.tmp_dir = "/tmp/youtube-podcaster"
32 else:
33 self.tmp_dir= "%s/tmp/youtube-podcaster" % (sys.prefix)
34
35 os.makedirs(self.tmp_dir, 0o755, True)
36
37 def download(self, video, video_id, feed_id): 28 def download(self, video, video_id, feed_id):
38 29
39 # Real output 30 # Real output
@@ -43,7 +34,8 @@ class Downloader:
43 34
44 # Tmp output 35 # Tmp output
45 tmp_filename = "%s.webm" % (video_id) 36 tmp_filename = "%s.webm" % (video_id)
46 tmp_output = "%s/%s" % (self.tmp_dir, tmp_filename) 37 tmp_dir = "%s/tmp" % output_dir
38 tmp_output = "%s/%s" % (tmp_dir, tmp_filename)
47 39
48 options = {"format": "bestaudio/best", 40 options = {"format": "bestaudio/best",
49 "outtmpl": tmp_output, 41 "outtmpl": tmp_output,
@@ -55,17 +47,15 @@ class Downloader:
55 video_url = "https://www.youtube.com/watch?v=%s" % (video["snippet"]["resourceId"]["videoId"]) 47 video_url = "https://www.youtube.com/watch?v=%s" % (video["snippet"]["resourceId"]["videoId"])
56 youtube_dl.YoutubeDL(options).download([video_url]) 48 youtube_dl.YoutubeDL(options).download([video_url])
57 49
58 tmp_output = "%s/%s" % (self.tmp_dir, filename) 50 tmp_output = "%s/%s" % (tmp_dir, filename)
59 51
60 url = "%s/%s/%s.%s" % (self.base_url, feed_id, video_id, self.extension) 52 url = "%s/%s/%s" % (self.base_url, feed_id, filename)
61 size = str(os.path.getsize(tmp_output)) 53 size = str(os.path.getsize(tmp_output))
62 mime = mimetypes.guess_type(tmp_output)[0] 54 mime = mimetypes.guess_type(tmp_output)[0]
63 55
64 os.makedirs(output_dir, 0o755, True) 56 os.makedirs(output_dir, 0o755, True)
65 os.rename(tmp_output, output) 57 os.rename(tmp_output, output)
66 58
67 self.downloaded.append(output)
68
69 return (url, size, mime) 59 return (url, size, mime)
70 60
71# vim: set ts=8 sw=4 tw=0 et : 61# vim: set ts=8 sw=4 tw=0 et :