Skip to content

Commit bb95959

Browse files
committed
Fixed gallery detection; Added album support.
1 parent 655d67b commit bb95959

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

imageresolver/plugins/imgur.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,26 @@ def get_image(self, url, **kwargs):
1111
logger = logging.getLogger('ImageResolver')
1212
logger.debug('Resolving using plugin ' + str(os.path.basename(__file__)) + ' ' + str(url))
1313
parsed = urlparse(url)
14-
if parsed.path[1:6] == 'gallery':
14+
15+
if parsed.path[1:8] == 'gallery':
16+
logger.debug('Detected imgur gallery.')
1517
r = requests.get(url)
1618
if r.status_code == 200:
1719
soup = BeautifulSoup(r.text)
18-
tags = soup.find_all('div', {'id':'1','class':'album-image'})
19-
for tag in tags:
20-
image = re.findall('i\.imgur.com\/.*\.\w+', str(tag))
21-
if len(image) >= 1:
22-
return 'http://' + image[0]
20+
tag = soup.find('div', {'id':'1','class':'album-image'})
21+
image = re.findall('i\.imgur.com\/.*\.\w+', str(tag))
22+
if len(image) >= 1:
23+
return 'http://' + image[0]
24+
25+
elif parsed.path[0:3] == '/a/':
26+
logger.debug('Detected imgur album.')
27+
r = requests.get(url)
28+
if r.status_code == 200:
29+
soup = BeautifulSoup(r.text)
30+
tag = soup.find('meta',{'name':'twitter:image0:src'})
31+
if tag:
32+
return tag['content']
33+
2334
else:
2435
parsed = urlparse(url)
2536
if re.search('imgur.com(:80)*', parsed.netloc) and os.path.basename(parsed.path):

0 commit comments

Comments
 (0)