fix image handling from mastodon
This commit is contained in:
parent
ed3b288dc0
commit
cea73a38d6
2 changed files with 7 additions and 8 deletions
13
feedbot.py
13
feedbot.py
|
@ -21,7 +21,7 @@ dr = False
|
|||
@click.option('--prime', is_flag=True)
|
||||
@click.option('--debug', is_flag=True)
|
||||
@click.option('--dryrun', is_flag=True)
|
||||
@click.version_option(version='0.2.0')
|
||||
@click.version_option(version='0.2.1')
|
||||
def main(ctx, db, prime, debug, dryrun):
|
||||
global dr
|
||||
|
||||
|
@ -138,10 +138,9 @@ def pnutpost(entry, source, token):
|
|||
}
|
||||
}
|
||||
raw = [crosspost]
|
||||
for link in entry.links:
|
||||
if link.rel == "enclosure":
|
||||
if "image" in link.type:
|
||||
raw.append(embed_image(link))
|
||||
for media in entry.media_content:
|
||||
if media["medium"] == "image":
|
||||
raw.append(embed_image(media["url"]))
|
||||
|
||||
try:
|
||||
rx = re.compile('<.*?>')
|
||||
|
@ -170,7 +169,7 @@ def pnutpost(entry, source, token):
|
|||
|
||||
def embed_image(link):
|
||||
resume_header = {'Range': 'bytes=0-2000000'}
|
||||
r = requests.get(link.href, stream=True, headers=resume_header)
|
||||
r = requests.get(link, stream=True, headers=resume_header)
|
||||
|
||||
p = ImageFile.Parser()
|
||||
p.feed(r.content)
|
||||
|
@ -181,7 +180,7 @@ def embed_image(link):
|
|||
'type': "photo",
|
||||
'width': width,
|
||||
'height': height,
|
||||
'url': link.href
|
||||
'url': link
|
||||
}
|
||||
return {'type': "io.pnut.core.oembed", 'value': embed}
|
||||
|
||||
|
|
2
setup.py
2
setup.py
|
@ -2,7 +2,7 @@ from setuptools import setup
|
|||
|
||||
setup(
|
||||
name='feedbot',
|
||||
version='0.2.0',
|
||||
version='0.2.1',
|
||||
py_modules=[
|
||||
'models',
|
||||
'feedbot',
|
||||
|
|
Loading…
Reference in a new issue