-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpypodcastr.py
More file actions
executable file
·68 lines (57 loc) · 1.63 KB
/
pypodcastr.py
File metadata and controls
executable file
·68 lines (57 loc) · 1.63 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
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python3
import feedparser
import urllib
import os
import sys
podcastdir = os.getenv("HOME")+"/Podcasts/"
#try to read what podcasts to download
if os.path.isfile(".podcasts.pod"):
f = open(".podcasts.pod", "r")
podcasts = f.readlines()
f.close()
else:
f = open(".podcasts.pod", "w")
f.close()
#Add a podcast
try:
if sys.argv[1] == "--add":
f = open(".podcasts.pod", "r")
podcasts = f.readlines()
f.close()
podcasts.append(str(sys.argv[2]+"\n"))
f = open(".podcasts.pod", "w")
for line in podcasts:
f.write(line)
f.close()
print("Starting")
except:
print("Starting")
#For all the podcasts download the latest
#if the latest is not in the .lastdownload file
#if it is just skip
for podcast in podcasts:
feed = feedparser.parse(podcast)
#Make sure there is a podcast folder
if not(os.path.exists(podcastdir)):
os.mkdir(podcastdir)
#Make correct podcast directories
if not (os.path.exists(podcastdir + feed.feed.title + "/")):
os.mkdir(podcastdir + feed.feed.title + "/")
#Try to read in last downloaded files
try:
f = open(".lastdownloaded", "r")
lastdownloaded = f.readlines()
f.close()
except:
lastdownloaded = []
for key in feed["entries"]:
if (key["title"] + "\n") in lastdownloaded:
print(key["title"] + " already downloaded...skipping")
else:
print("Downloading: ", key["title"])
urllib.request.urlretrieve(key["link"], podcastdir + feed.feed.title + "/" + key["title"] + ".mp3")
f = open(".lastdownloaded", "a")
f.write(key["title"] + "\n")
f.close()
break
print("Podcasts are up to date")