Exemple #1
0
    def GET_mediaembed(self, link, credentials):
        if request.host != g.media_domain:
            # don't serve up untrusted content except on our
            # specifically untrusted domain
            abort(404)

        if link.subreddit_slow.type == "private":
            expected_mac = hmac.new(g.secrets["media_embed"], link._id36,
                                    hashlib.sha1).hexdigest()
            if not constant_time_compare(credentials or "", expected_mac):
                abort(404)

        if not c.secure:
            media_object = link.media_object
        else:
            media_object = link.secure_media_object

        if not media_object:
            abort(404)
        elif isinstance(media_object, dict):
            # otherwise it's the new style, which is a dict(type=type, **args)
            media_embed = get_media_embed(media_object)
            content = media_embed.content

        c.allow_framing = True

        return MediaEmbedBody(body = content).render()
Exemple #2
0
 def thing_attr(self, thing, attr):
     from r2.lib.media import get_media_embed
     if attr in ("media_embed", "secure_media_embed"):
         media_object = getattr(thing, attr.replace("_embed", "_object"))
         if media_object and not isinstance(media_object, basestring):
             media_embed = get_media_embed(media_object)
             if media_embed:
                 return {
                     "scrolling": media_embed.scrolling,
                     "width": media_embed.width,
                     "height": media_embed.height,
                     "content": media_embed.content,
                 }
         return {}
     elif attr == "clicked":
         # this hasn't been used in years.
         return False
     elif attr == "editted" and not isinstance(thing.editted, bool):
         return (time.mktime(thing.editted.astimezone(pytz.UTC).timetuple())
                 - time.timezone)
     elif attr == 'subreddit':
         return thing.subreddit.name
     elif attr == 'subreddit_id':
         return thing.subreddit._fullname
     elif attr == 'selftext':
         if not thing.expunged:
             return thing.selftext
         else:
             return ''
     elif attr == 'selftext_html':
         if not thing.expunged:
             return safemarkdown(thing.selftext)
         else:
             return safemarkdown(_("[removed]"))
     return ThingJsonTemplate.thing_attr(self, thing, attr)
Exemple #3
0
    def GET_mediaembed(self, link, credentials):
        if request.host != g.media_domain:
            # don't serve up untrusted content except on our
            # specifically untrusted domain
            abort(404)

        if link.subreddit_slow.type in Subreddit.private_types:
            expected_mac = hmac.new(g.secrets["media_embed"], link._id36,
                                    hashlib.sha1).hexdigest()
            if not constant_time_compare(credentials or "", expected_mac):
                abort(404)

        if not c.secure:
            media_object = link.media_object
        else:
            media_object = link.secure_media_object

        if not media_object:
            abort(404)
        elif isinstance(media_object, dict):
            # otherwise it's the new style, which is a dict(type=type, **args)
            media_embed = get_media_embed(media_object)
            content = media_embed.content

        c.allow_framing = True

        return MediaEmbedBody(body = content).render()
Exemple #4
0
 def thing_attr(self, thing, attr):
     from r2.lib.media import get_media_embed
     if attr in ("media_embed", "secure_media_embed"):
         media_object = getattr(thing, attr.replace("_embed", "_object"))
         if media_object and not isinstance(media_object, basestring):
             media_embed = get_media_embed(media_object)
             if media_embed:
                 return {
                     "scrolling": media_embed.scrolling,
                     "width": media_embed.width,
                     "height": media_embed.height,
                     "content": media_embed.content,
                 }
         return {}
     elif attr == "clicked":
         # this hasn't been used in years.
         return False
     elif attr == "editted" and not isinstance(thing.editted, bool):
         return (time.mktime(thing.editted.astimezone(pytz.UTC).timetuple())
                 - time.timezone)
     elif attr == 'subreddit':
         return thing.subreddit.name
     elif attr == 'subreddit_id':
         return thing.subreddit._fullname
     elif attr == 'selftext':
         if not thing.expunged:
             return thing.selftext
         else:
             return ''
     elif attr == 'selftext_html':
         if not thing.expunged:
             return safemarkdown(thing.selftext)
         else:
             return safemarkdown(_("[removed]"))
     return ThingJsonTemplate.thing_attr(self, thing, attr)
Exemple #5
0
 def thing_attr(self, thing, attr):
     from r2.lib.media import get_media_embed
     if attr == "media_embed":
        if (thing.media_object and
            not isinstance(thing.media_object, basestring)):
            media_embed = get_media_embed(thing.media_object)
            if media_embed:
                return dict(scrolling = media_embed.scrolling,
                            width = media_embed.width,
                            height = media_embed.height,
                            content = media_embed.content)
        return dict()
     elif attr == "editted" and not isinstance(thing.editted, bool):
         return (time.mktime(thing.editted.astimezone(pytz.UTC).timetuple())
                 - time.timezone)
     elif attr == 'subreddit':
         return thing.subreddit.name
     elif attr == 'subreddit_id':
         return thing.subreddit._fullname
     elif attr == 'selftext':
         if not thing.expunged:
             return thing.selftext
         else:
             return ''
     elif attr == 'selftext_html':
         if not thing.expunged:
             return safemarkdown(thing.selftext)
         else:
             return safemarkdown(_("[removed]"))
     return ThingJsonTemplate.thing_attr(self, thing, attr)
Exemple #6
0
    def GET_mediaembed(self, link):
        if request.host != g.media_domain:
            # don't serve up untrusted content except on our
            # specifically untrusted domain
            abort(404)

        if not link or not link.media_object:
            abort(404)
        elif isinstance(link.media_object, dict):
            # otherwise it's the new style, which is a dict(type=type, **args)
            media_embed = get_media_embed(link.media_object)
            content = media_embed.content

        return MediaEmbedBody(body=content).render()
Exemple #7
0
    def GET_mediaembed(self, link):
        if request.host != g.media_domain:
            # don't serve up untrusted content except on our
            # specifically untrusted domain
            abort(404)

        if not link or not link.media_object:
            abort(404)
        elif isinstance(link.media_object, dict):
            # otherwise it's the new style, which is a dict(type=type, **args)
            media_embed = get_media_embed(link.media_object)
            content = media_embed.content

        return MediaEmbedBody(body = content).render()
Exemple #8
0
def get_live_media_embed(media_object):
    if media_object['type'] == "twitter.com":
        return _TwitterScraper.media_embed(media_object)
    if media_object["type"] == "embedly-card":
        return _EmbedlyCardFallbackScraper.media_embed(media_object)
    return get_media_embed(media_object)
def get_live_media_embed(media_object):
    if media_object['type'] == "twitter.com":
        return _TwitterScraper.media_embed(media_object)
    if media_object["type"] == "embedly-card":
        return _EmbedlyCardFallbackScraper.media_embed(media_object)
    return get_media_embed(media_object)