Reference PodcastEpisode only on model.Model

This commit is contained in:
Thomas Perl 2010-12-20 15:48:29 +01:00
parent b04ca2c58a
commit 0f5a45bc42
3 changed files with 26 additions and 28 deletions

View File

@ -106,28 +106,6 @@ class PodcastModelObject(object):
setattr(self, k, d[k])
class Model(object):
@staticmethod
def get_podcasts(db):
return PodcastChannel.load_from_db(db)
@staticmethod
def load_podcast(db, url, create=True, authentication_tokens=None, \
max_episodes=0, mimetype_prefs=''):
return PodcastChannel.load(db, url, create, authentication_tokens, \
max_episodes, mimetype_prefs)
@staticmethod
def sort_episodes_by_pubdate(episodes, reverse=False):
"""Sort a list of PodcastEpisode objects chronologically
Returns a iterable, sorted sequence of the episodes
"""
get_key = lambda e: e.published
return sorted(episodes, key=get_key, reverse=reverse)
class PodcastEpisode(PodcastModelObject):
"""holds data for one object in a channel"""
MAX_FILENAME_LENGTH = 200
@ -1143,3 +1121,26 @@ class PodcastChannel(PodcastModelObject):
def cover_file(self):
return os.path.join(self.save_dir, 'folder.jpg')
class Model(object):
PodcastClass = PodcastChannel
@classmethod
def get_podcasts(cls, db):
return cls.PodcastClass.load_from_db(db)
@classmethod
def load_podcast(cls, db, url, create=True, authentication_tokens=None, \
max_episodes=0, mimetype_prefs=''):
return cls.PodcastClass.load(db, url, create, authentication_tokens, \
max_episodes, mimetype_prefs)
@staticmethod
def sort_episodes_by_pubdate(episodes, reverse=False):
"""Sort a list of PodcastEpisode objects chronologically
Returns a iterable, sorted sequence of the episodes
"""
get_key = lambda e: e.published
return sorted(episodes, key=get_key, reverse=reverse)

View File

@ -195,8 +195,7 @@ class SoundcloudFeed(object):
if t['guid'] not in guids]
for track in tracks:
episode = model.PodcastEpisode(channel)
episode.update_from_dict(track)
episode = channel.episode_factory(track)
episode.save()
return len(tracks)
@ -222,8 +221,7 @@ class SoundcloudFavFeed(SoundcloudFeed):
if t['guid'] not in guids]
for track in tracks:
episode = model.PodcastEpisode(channel)
episode.update_from_dict(track)
episode = channel.episode_factory(track)
episode.save()
return len(tracks)

View File

@ -144,8 +144,7 @@ class FM4OnDemandPlaylist(object):
continue
filesize, filetype, filedate, filename = get_metadata(url)
episode = model.PodcastEpisode(channel)
episode.update_from_dict({
episode = channel.episode_factory({
'title': title,
'link': '',
'description': '',