Skip to content

Commit

Permalink
Issue #22.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander F committed Feb 23, 2017
1 parent 65f8f4f commit c76c0ca
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
TYPE_GIF = 'gif'
CONTENT_GIF = 'image/gif'
CONTENT_MP4 = 'video/mp4'
TYPE_TEXT = 'text'
TYPE_OTHER = 'other'
TYPE_ALBUM = 'album'


TEMP_FOLDER = 'tmp'
Expand Down Expand Up @@ -69,7 +72,7 @@ def what_is_inside(url):

if submission.is_self is True:
# Self submission with text
return 'text', None, None
return TYPE_TEXT, None, None

if urlparse(url).netloc == 'imgur.com':
# Imgur
Expand All @@ -78,14 +81,14 @@ def what_is_inside(url):
path_parts = urlparse(url).path.split('/')
if path_parts[1] == 'gallery':
# TODO: gallary handling
return 'other', url, None
return TYPE_OTHER, url, None
elif path_parts[1] == 'topic':
# TODO: topic handling
return 'other', url, None
return TYPE_OTHER, url, None
elif path_parts[1] == 'a':
# An imgur album
album = imgur_client.get_album(path_parts[2])
story = {}
story = dict()
for num, img in enumerate(album.images):
number = num + 1
what = TYPE_IMG
Expand All @@ -100,7 +103,10 @@ def what_is_inside(url):
'what': what,
'ext': ext
}
return 'album', story, None
if len(story) == 1:
logging.warning('Album to common img.')
return story[1]['what'], story[1]['url'], story[1]['ext']
return TYPE_ALBUM, story, None
else:
# Just imgur img
img = imgur_client.get_image(path_parts[1].split('.')[0])
Expand All @@ -113,7 +119,7 @@ def what_is_inside(url):
# return 'gif', img.link, 'gif'
return TYPE_GIF, img.gifv[:-1], 'gif'
else:
return 'other', url, None
return TYPE_OTHER, url, None


def download_file(url, filename):
Expand All @@ -137,7 +143,6 @@ def md5_sum_from_url(url):
try:
r = requests.get(url, stream=True)
except InvalidSchema:
logging.error('Invalid Schema!')
return None
chunk_counter = 0
hash_store = hashlib.md5()
Expand Down

0 comments on commit c76c0ca

Please sign in to comment.