-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubscription.py
87 lines (61 loc) · 2.19 KB
/
subscription.py
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import index
import re
import logging
import os
from parser import Parser
from prefs import prefs_dirs_rss, prefs_dirs_podcasts
DEFAULT_MAXEPS = 3
logger = logging.getLogger()
def rss_file_name_from_text(text):
# return os.path.join(re.sub(r'\W', '', text ), '.rss' )
return re.sub(r"\W", "", text) + ".rss"
class Subscription:
def __init__(self, feedurl=None, title=None, maxeps=3, rssfile=None):
self.parser = Parser()
# A subscription object is constructed primarily following
# using itunes to search for a podcast. The three attributes
# below come from the results object that follows searching
# itunes, and are used for writing to an RSS file.
# The feedurl is the internet source for the RSS file, and
# will be used as an attribute in the config file entry, as is
# the maxeps attribute.
self.feedurl = feedurl
self.title = title
logging.info(
"Subscription.__init_ is now setting title to be [%s]" % self.title
)
self.maxeps = maxeps
self.rssfile = rssfile
def set_title(self, title):
self.title = title
def set_feedurl(self, feedurl):
self.feedurl = feedurl
def set_maxeps(self, m):
self.maxeps = m
def set_rssfile(self, x):
rssfile = x
self.rssfile = os.path.join(prefs_dirs_rss(), rssfile)
def get_db(self):
return self.database
def full_path_to_index_file(self):
return os.path.join(
prefs_dirs_rss(),
self.filesystem_safe_sub_title() + "." + index.FILE_EXTENSION,
)
def episodes(self, filename=None):
if filename is None:
filename = self.rssfile
self.parser.parse(filename)
return self.parser.episodes()
def title(self):
return self.title
def filesystem_safe_sub_title(self):
return re.sub(r"\W", "", self.title)
def base_podcasts_dir(self):
return prefs_dirs_podcasts()
def _sub_dir(self):
return re.sub(r"\W", "", self.title)
def podcasts_subdir(self):
return os.path.join(prefs_dirs_podcasts(), self._sub_dir())
if __name__ == "__main__":
pass