Enhanced the API; more features for "gpo"

Add the ability to update feeds and download episodes
from the API and implement more features in "gpo".
This commit is contained in:
Thomas Perl 2009-05-10 23:16:48 +02:00
parent de3750e190
commit aab4e524ef
2 changed files with 59 additions and 1 deletions

40
bin/gpo
View file

@ -177,6 +177,46 @@ class gPodderCli(object):
return True
def update(self):
for podcast in api.get_podcasts():
print 'Updating', podcast.title
podcast.update()
print 'Done.'
return True
def pending(self):
count = 0
for podcast in api.get_podcasts():
podcast_printed = False
for episode in podcast.get_episodes():
if episode.is_new:
if not podcast_printed:
print podcast.title
podcast_printed = True
print ' ', episode.title
count += 1
print count, 'episodes pending.'
return True
def download(self):
count = 0
for podcast in api.get_podcasts():
podcast_printed = False
for episode in podcast.get_episodes():
if episode.is_new:
if not podcast_printed:
print podcast.title
podcast_printed = True
print ' ', episode.title
episode.download()
count += 1
print count, 'episodes downloaded.'
return True
# -------------------------------------------------------------------
def _error(self, *args):

View file

@ -27,7 +27,7 @@ import gpodder
from gpodder import util
from gpodder import libpodcasts
from gpodder.dbsqlite import db
from gpodder import download
class Podcast(object):
"""API interface of gPodder podcasts
@ -69,6 +69,14 @@ class Podcast(object):
self._podcast.delete()
self._podcast = None
def update(self):
"""Updates this podcast by downloading the feed
Downloads the podcast feed (using the feed cache), and
adds new episodes and updated information to the database.
"""
self._podcast.update()
class Episode(object):
@ -94,6 +102,16 @@ class Episode(object):
self.is_downloaded = (self._episode.state == db.STATE_DOWNLOADED)
self.is_deleted = (self._episode.state == db.STATE_DELETED)
def download(self):
"""Downloads the episode to a local file
This will run the download in the same thread, so be sure
to call this method from a worker thread in case you have
a GUI running as a frontend."""
task = download.DownloadTask(self._episode)
task.status = download.DownloadTask.QUEUED
task.run()
def get_podcasts():
"""Get a list of Podcast objects