def _format_description(self, channel, total, deleted, new, downloaded, unplayed): title_markup = html.escape(channel.title) if channel._update_error is not None: description_markup = html.escape( _('ERROR: %s') % channel._update_error) elif not channel.pause_subscription: description_markup = html.escape( util.get_first_line(util.remove_html_tags(channel.description)) or ' ') else: description_markup = html.escape(_('Subscription paused')) d = [] if new: d.append('<span weight="bold">') d.append(title_markup) if new: d.append('</span>') if channel._update_error is not None: return ''.join( d + ['\n', '<span weight="bold">', description_markup, '</span>']) elif description_markup.strip(): return ''.join(d + ['\n', '<small>', description_markup, '</small>']) else: return ''.join(d)
def from_feedparser_entry( entry, channel): episode=podcastItem( channel) episode.title=entry.get( 'title', util.get_first_line( util.remove_html_tags( entry.get( 'summary', '')))) episode.link=entry.get( 'link', '') episode.description=util.remove_html_tags( entry.get( 'summary', entry.get( 'link', entry.get( 'title', '')))) episode.guid=entry.get( 'id', '') if entry.get( 'updated_parsed', None): episode.pubDate=util.updated_parsed_to_rfc2822( entry.updated_parsed) if episode.title == '': log( 'Warning: Episode has no title, adding anyways.. (Feed Is Buggy!)', sender=episode) enclosure=None if hasattr(entry, 'enclosures') and len(entry.enclosures) > 0: enclosure=entry.enclosures[0] if len(entry.enclosures) > 1: for e in entry.enclosures: if hasattr( e, 'href') and hasattr( e, 'length') and hasattr( e, 'type') and (e.type.startswith('audio/') or e.type.startswith('video/')): if util.normalize_feed_url(e.href) is not None: log( 'Selected enclosure: %s', e.href, sender=episode) enclosure=e break episode.url=util.normalize_feed_url( enclosure.get( 'href', '')) elif hasattr(entry, 'link'): extension=util.file_extension_from_url(entry.link) file_type=util.file_type_by_extension(extension) if file_type is not None: log('Adding episode with link to file type "%s".', file_type, sender=episode) episode.url=entry.link if not episode.url: raise ValueError( 'Episode has an invalid URL') if not episode.pubDate: metainfo=episode.get_metainfo() if 'pubdate' in metainfo: episode.pubDate=metainfo['pubdate'] if hasattr( enclosure, 'length'): try: episode.length=int(enclosure.length) except: episode.length=-1 # For episodes with a small length amount, try to find it via HTTP HEAD if episode.length <= 100: metainfo=episode.get_metainfo() if 'length' in metainfo: episode.length=metainfo['length'] if hasattr( enclosure, 'type'): episode.mimetype=enclosure.type if episode.title == '': ( filename, extension )=os.path.splitext( os.path.basename( episode.url)) episode.title=filename return episode
def _format_description(self, channel, total, deleted, \ new, downloaded, unplayed): title_markup = xml.sax.saxutils.escape(channel.title) description_markup = xml.sax.saxutils.escape(util.get_first_line(channel.description) or ' ') d = [] if new: d.append('<span weight="bold">') d.append(title_markup) if new: d.append('</span>') return ''.join(d+['\n', '<small>', description_markup, '</small>'])
def channels_to_model(channels): new_model=gtk.ListStore(str, str, str, gtk.gdk.Pixbuf, int, gtk.gdk.Pixbuf, str) for channel in channels: (count_available, count_downloaded, count_new, count_unplayed)=channel.get_episode_stats() new_iter=new_model.append() new_model.set(new_iter, 0, channel.url) new_model.set(new_iter, 1, channel.title) title_markup=saxutils.escape(channel.title) description_markup=saxutils.escape(util.get_first_line(channel.description)) description='%s\n<small>%s</small>' % (title_markup, description_markup) if channel.parse_error is not None: description='<span foreground="#ff0000">%s</span>' % description new_model.set(new_iter, 6, channel.parse_error) else: new_model.set(new_iter, 6, '') new_model.set(new_iter, 2, description) if count_unplayed > 0 or count_downloaded > 0: new_model.set(new_iter, 3, draw.draw_pill_pixbuf(str(count_unplayed), str(count_downloaded))) if count_new > 0: new_model.set( new_iter, 4, pango.WEIGHT_BOLD) else: new_model.set( new_iter, 4, pango.WEIGHT_NORMAL) channel_cover_found=False if os.path.exists( channel.cover_file) and os.path.getsize(channel.cover_file) > 0: try: new_model.set( new_iter, 5, gtk.gdk.pixbuf_new_from_file_at_size( channel.cover_file, 32, 32)) channel_cover_found=True except: exctype, value=sys.exc_info()[:2] log( 'Could not convert icon file "%s", error was "%s"', channel.cover_file, value ) util.delete_file(channel.cover_file) if not channel_cover_found: iconsize=gtk.icon_size_from_name('channel-icon') if not iconsize: iconsize=gtk.icon_size_register('channel-icon',32,32) icon_theme=gtk.icon_theme_get_default() globe_icon_name='applications-internet' try: new_model.set( new_iter, 5, icon_theme.load_icon(globe_icon_name, iconsize, 0)) except: log( 'Cannot load "%s" icon (using an old or incomplete icon theme?)', globe_icon_name) new_model.set( new_iter, 5, None) return new_model
def _format_description(self, channel, total, deleted, \ new, downloaded, unplayed): title_markup = xml.sax.saxutils.escape(channel.title) if channel.feed_update_enabled: description_markup = xml.sax.saxutils.escape( util.get_first_line(channel.description) or ' ') else: description_markup = xml.sax.saxutils.escape( _('Subscription paused')) d = [] if new: d.append('<span weight="bold">') d.append(title_markup) if new: d.append('</span>') return ''.join(d + ['\n', '<small>', description_markup, '</small>'])
def _format_description(self, channel, total, deleted, new, downloaded, unplayed): title_markup = cgi.escape(channel.title) if not channel.pause_subscription: description_markup = cgi.escape(util.get_first_line(channel.description) or ' ') else: description_markup = cgi.escape(_('Subscription paused')) d = [] if new: d.append('<span weight="bold">') d.append(title_markup) if new: d.append('</span>') if description_markup.strip(): return ''.join(d + ['\n', '<small>', description_markup, '</small>']) else: return ''.join(d)
def _format_description(self, channel, total, deleted, \ new, downloaded, unplayed): title_markup = cgi.escape(channel.title) if not channel.pause_subscription: description_markup = cgi.escape(util.get_first_line(channel.description) or ' ') else: description_markup = cgi.escape(_('Subscription paused')) d = [] if new: d.append('<span weight="bold">') d.append(title_markup) if new: d.append('</span>') if description_markup.strip(): return ''.join(d+['\n', '<small>', description_markup, '</small>']) else: return ''.join(d)
def _description(self): return convert(util.get_first_line(self._podcast.description))