def _info(self, media, podcast_slugs=None, include_embed=False): """Return a JSON-ready dict for the given media instance""" if media.podcast_id: media_url = url_for(controller='/media', action='view', slug=media.slug, podcast_slug=media.podcast.slug, qualified=True) else: media_url = url_for(controller="/media", action="view", slug=media.slug, qualified=True) if media.podcast_id is None: podcast_slug = None elif podcast_slugs: podcast_slug = podcast_slugs[media.podcast_id] else: podcast_slug = DBSession.query(Podcast.slug)\ .filter_by(id=media.podcast_id).scalar() thumbs = {} for size in config['thumb_sizes'][media._thumb_dir].iterkeys(): thumbs[size] = thumb(media, size, qualified=True) info = dict( id = media.id, slug = media.slug, url = media_url, title = media.title, author = media.author.name, type = media.type, podcast = podcast_slug, description = media.description, description_plain = media.description_plain, comment_count = media.comment_count_published, publish_on = unicode(media.publish_on), likes = media.likes, views = media.views, thumbs = thumbs, categories = dict((c.slug, c.name) for c in list(media.categories)), ) if include_embed: info['embed'] = unicode(helpers.embed_player(media)) return info
def _info(self, media, podcast_slugs=None, include_embed=False): """ Return a **media_info** dict--a JSON-ready dict for describing a media instance. :rtype: JSON-ready dict :returns: The returned dict has the following fields: author (unicode) The name of the :attr:`author <mediacore.model.media.Media.author>` of the media instance. categories (dict of unicode) A JSON-ready dict representing the categories the media instance is in. Keys are the unique :attr:`slugs <mediacore.model.podcasts.Podcast.slug>` for each category, values are the human-readable :attr:`title <mediacore.model.podcasts.podcast.Title>` of that category. id (int) The numeric unique :attr:`id <mediacore.model.media.Media.id>` of the media instance. slug (unicode) The more human readable unique identifier (:attr:`slug <mediacore.model.media.Media.slug>`) of the media instance. url (unicode) A permalink (HTTP) to the MediaCore view page for the media instance. embed (unicode) HTML code that can be used to embed the video in another site. title (unicode) The :attr:`title <mediacore.model.media.Media.title>` of the media instance. type (string, one of ['%s', '%s']) The :attr:`type <mediacore.model.media.Media.type>` of the media instance podcast (unicode or None) The :attr:`slug <mediacore.model.podcasts.Podcast.slug>` of the :class:`podcast <mediacore.model.podcasts.Podcast>` that the media instance has been published under, or None description (unicode) An XHTML :attr:`description <mediacore.model.media.Media.description>` of the media instance. description_plain (unicode) A plain text :attr:`description <mediacore.model.media.Media.description_plain>` of the media instance. comment_count (int) The number of published comments on the media instance. publish_on (unicode) The date of publishing in "YYYY-MM-DD HH:MM:SS" (ISO 8601) format. e.g. "2010-02-16 15:06:49" likes (int) The number of :attr:`like votes <mediacore.model.media.Media.likes>` that the media instance has received. views (int) The number of :attr:`views <mediacore.model.media.Media.views>` that the media instance has received. thumbs (dict) A dict of dicts containing URLs, width and height of different sizes of thumbnails. The default sizes are 's', 'm' and 'l'. Using medium for example:: medium_url = thumbs['m']['url'] medium_width = thumbs['m']['x'] medium_height = thumbs['m']['y'] """ if media.podcast_id: media_url = url_for(controller='/media', action='view', slug=media.slug, podcast_slug=media.podcast.slug, qualified=True) else: media_url = url_for_media(media, qualified=True) if media.podcast_id is None: podcast_slug = None elif podcast_slugs: podcast_slug = podcast_slugs[media.podcast_id] else: podcast_slug = DBSession.query(Podcast.slug)\ .filter_by(id=media.podcast_id).scalar() thumbs = {} for size in config['thumb_sizes'][media._thumb_dir].iterkeys(): thumbs[size] = thumb(media, size, qualified=True) info = dict( id=media.id, slug=media.slug, url=media_url, title=media.title, author=media.author.name, type=media.type, podcast=podcast_slug, description=media.description, description_plain=media.description_plain, comment_count=media.comment_count_published, publish_on=unicode(media.publish_on), likes=media.likes, views=media.views, thumbs=thumbs, categories=dict((c.slug, c.name) for c in list(media.categories)), ) if include_embed: info['embed'] = unicode(helpers.embed_player(media)) return info
def _info(self, media, podcast_slugs=None, include_embed=False): """ Return a **media_info** dict--a JSON-ready dict for describing a media instance. :rtype: JSON-ready dict :returns: The returned dict has the following fields: author (unicode) The name of the :attr:`author <mediacore.model.media.Media.author>` of the media instance. categories (dict of unicode) A JSON-ready dict representing the categories the media instance is in. Keys are the unique :attr:`slugs <mediacore.model.podcasts.Podcast.slug>` for each category, values are the human-readable :attr:`title <mediacore.model.podcasts.podcast.Title>` of that category. id (int) The numeric unique :attr:`id <mediacore.model.media.Media.id>` of the media instance. slug (unicode) The more human readable unique identifier (:attr:`slug <mediacore.model.media.Media.slug>`) of the media instance. url (unicode) A permalink (HTTP) to the MediaCore view page for the media instance. embed (unicode) HTML code that can be used to embed the video in another site. title (unicode) The :attr:`title <mediacore.model.media.Media.title>` of the media instance. type (string, one of ['%s', '%s']) The :attr:`type <mediacore.model.media.Media.type>` of the media instance podcast (unicode or None) The :attr:`slug <mediacore.model.podcasts.Podcast.slug>` of the :class:`podcast <mediacore.model.podcasts.Podcast>` that the media instance has been published under, or None description (unicode) An XHTML :attr:`description <mediacore.model.media.Media.description>` of the media instance. description_plain (unicode) A plain text :attr:`description <mediacore.model.media.Media.description_plain>` of the media instance. comment_count (int) The number of published comments on the media instance. publish_on (unicode) The date of publishing in "YYYY-MM-DD HH:MM:SS" (ISO 8601) format. e.g. "2010-02-16 15:06:49" likes (int) The number of :attr:`like votes <mediacore.model.media.Media.likes>` that the media instance has received. views (int) The number of :attr:`views <mediacore.model.media.Media.views>` that the media instance has received. thumbs (dict) A dict of dicts containing URLs, width and height of different sizes of thumbnails. The default sizes are 's', 'm' and 'l'. Using medium for example:: medium_url = thumbs['m']['url'] medium_width = thumbs['m']['x'] medium_height = thumbs['m']['y'] """ if media.podcast_id: media_url = url_for( controller="/media", action="view", slug=media.slug, podcast_slug=media.podcast.slug, qualified=True ) else: media_url = url_for(controller="/media", action="view", slug=media.slug, qualified=True) if media.podcast_id is None: podcast_slug = None elif podcast_slugs: podcast_slug = podcast_slugs[media.podcast_id] else: podcast_slug = DBSession.query(Podcast.slug).filter_by(id=media.podcast_id).scalar() thumbs = {} for size in config["thumb_sizes"][media._thumb_dir].iterkeys(): thumbs[size] = thumb(media, size, qualified=True) info = dict( id=media.id, slug=media.slug, url=media_url, title=media.title, author=media.author.name, type=media.type, podcast=podcast_slug, description=media.description, description_plain=media.description_plain, comment_count=media.comment_count_published, publish_on=unicode(media.publish_on), likes=media.likes, views=media.views, thumbs=thumbs, categories=dict((c.slug, c.name) for c in list(media.categories)), ) if include_embed: info["embed"] = unicode(helpers.embed_player(media)) return info