2006-02-04 18:29:17 +01:00
|
|
|
|
2006-04-07 22:22:30 +02:00
|
|
|
|
|
|
|
#
|
|
|
|
# gPodder (a media aggregator / podcast client)
|
|
|
|
# Copyright (C) 2005-2006 Thomas Perl <thp at perli.net>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
2006-02-04 18:29:17 +01:00
|
|
|
#
|
2006-04-07 22:22:30 +02:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
# MA 02110-1301, USA.
|
2006-02-04 18:29:17 +01:00
|
|
|
#
|
|
|
|
|
|
|
|
#
|
|
|
|
# liblocaldb.py -- access routines to the local podcast database
|
|
|
|
# thomas perl <thp@perli.net> 20060204
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
|
|
|
import gtk
|
|
|
|
import gobject
|
|
|
|
|
|
|
|
from libgpodder import gPodderLib
|
2006-12-06 21:25:26 +01:00
|
|
|
from libgpodder import gPodderChannelReader
|
2006-11-17 15:26:10 +01:00
|
|
|
from liblogger import log
|
2006-02-04 18:29:17 +01:00
|
|
|
|
|
|
|
class localDB( object):
|
|
|
|
def __init__( self):
|
2006-12-06 21:25:26 +01:00
|
|
|
self.__channel_list = None
|
|
|
|
|
|
|
|
def get_channel_list( self):
|
|
|
|
if self.__channel_list != None:
|
|
|
|
return self.__channel_list
|
|
|
|
|
|
|
|
self.__channel_list = []
|
|
|
|
self.available_channels = gPodderChannelReader().read()
|
|
|
|
|
|
|
|
for channel in self.available_channels:
|
|
|
|
local = channel.localdb_channel
|
|
|
|
if len( local):
|
|
|
|
self.__channel_list.append( local)
|
2006-03-29 13:33:56 +02:00
|
|
|
|
2006-12-06 21:25:26 +01:00
|
|
|
return self.__channel_list
|
|
|
|
|
|
|
|
channel_list = property(fget=get_channel_list)
|
|
|
|
|
|
|
|
|
|
|
|
def get_channel( self, url):
|
|
|
|
for channel in self.channel_list:
|
|
|
|
if channel.url == url:
|
|
|
|
return channel
|
2006-02-04 18:29:17 +01:00
|
|
|
|
2006-12-06 21:25:26 +01:00
|
|
|
return None
|
|
|
|
|
|
|
|
def get_podcast( self, url):
|
|
|
|
for channel in self.channel_list:
|
|
|
|
for episode in channel:
|
|
|
|
if episode.url == url:
|
|
|
|
return episode
|
2006-02-04 18:29:17 +01:00
|
|
|
|
2006-12-06 21:25:26 +01:00
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
def get_tree_model( self, url):
|
2006-12-08 21:58:30 +01:00
|
|
|
# Try to add downloaded items (TODO: remove at some point in the future)
|
|
|
|
to_be_added = []
|
|
|
|
for episode in self.get_channel( url):
|
|
|
|
to_be_added.append( episode.url)
|
|
|
|
if to_be_added:
|
|
|
|
gPodderLib().history_mark_downloaded( to_be_added)
|
|
|
|
|
2006-12-09 01:41:58 +01:00
|
|
|
return self.get_channel( url).items_liststore( False)
|
2006-02-04 18:29:17 +01:00
|
|
|
|
2006-12-06 21:25:26 +01:00
|
|
|
def get_model( self):
|
2006-02-04 18:29:17 +01:00
|
|
|
new_model = gtk.ListStore( gobject.TYPE_STRING, gobject.TYPE_STRING)
|
|
|
|
|
2006-12-06 21:25:26 +01:00
|
|
|
for channel in self.channel_list:
|
2006-04-08 12:12:05 +02:00
|
|
|
new_iter = new_model.append()
|
|
|
|
new_model.set( new_iter, 0, channel.url)
|
|
|
|
new_model.set( new_iter, 1, channel.title)
|
2006-02-04 18:29:17 +01:00
|
|
|
|
|
|
|
return new_model
|
2006-04-08 16:40:19 +02:00
|
|
|
|
|
|
|
|
2006-12-06 21:25:26 +01:00
|
|
|
def get_filename_by_podcast( self, url, podcast_url):
|
|
|
|
return self.get_channel( url).getPodcastFilename( podcast_url)
|
2006-03-29 13:33:56 +02:00
|
|
|
|
|
|
|
def clear_cache( self):
|
2006-12-06 21:25:26 +01:00
|
|
|
self.__channel_list = None
|
|
|
|
|
2006-02-04 18:29:17 +01:00
|
|
|
|