Merge branch 'master' of https://github.com/michael-lazar/rtv
Conflicts: rtv/content.py
This commit is contained in:
@@ -2,6 +2,7 @@ import logging
|
||||
|
||||
import praw
|
||||
import requests
|
||||
import re
|
||||
|
||||
from .exceptions import SubmissionError, SubredditError, AccountError
|
||||
from .helpers import humanize_timestamp, wrap_text, strip_subreddit_url
|
||||
@@ -111,7 +112,7 @@ class BaseContent(object):
|
||||
"selfpost" or "x-post" or a link.
|
||||
"""
|
||||
|
||||
is_selfpost = lambda s: s.startswith('http://www.reddit.com/r/')
|
||||
reddit_link = re.compile("https?://(www\.)?(np\.)?redd(it\.com|\.it)/r/.*")
|
||||
author = getattr(sub, 'author', '[deleted]')
|
||||
name = getattr(author, 'name', '[deleted]')
|
||||
flair = getattr(sub, 'link_flair_text', '')
|
||||
@@ -129,7 +130,19 @@ class BaseContent(object):
|
||||
data['subreddit'] = strip_subreddit_url(sub.permalink)
|
||||
data['flair'] = flair
|
||||
data['url_full'] = sub.url
|
||||
data['url'] = ('selfpost' if is_selfpost(sub.url) else sub.url)
|
||||
|
||||
if data['permalink'].split('/r/')[-1] == data['url_full'].split('/r/')[-1]:
|
||||
data['url_type'] = 'selfpost'
|
||||
data['url'] = 'selfpost'
|
||||
|
||||
elif reddit_link.match(data['url_full']):
|
||||
data['url_type'] = 'x-post'
|
||||
data['url'] = 'x-post via {}'.format(strip_subreddit_url(data['url_full']))
|
||||
|
||||
else:
|
||||
data['url_type'] = 'external'
|
||||
data['url'] = data['url_full']
|
||||
|
||||
data['likes'] = sub.likes
|
||||
data['gold'] = sub.gilded > 0
|
||||
data['nsfw'] = sub.over_18
|
||||
@@ -164,6 +177,7 @@ class SubmissionContent(BaseContent):
|
||||
|
||||
try:
|
||||
with loader():
|
||||
url = url.replace('http:', 'https:')
|
||||
submission = reddit.get_submission(url, comment_sort=order)
|
||||
except (praw.errors.APIException, praw.errors.NotFound):
|
||||
raise SubmissionError(url)
|
||||
|
||||
Reference in New Issue
Block a user