fix image handling from mastodon

This commit is contained in:
Morgan McMillian 2022-06-21 17:01:28 -07:00
parent ed3b288dc0
commit cea73a38d6
2 changed files with 7 additions and 8 deletions

View file

@ -21,7 +21,7 @@ dr = False
@click.option('--prime', is_flag=True) @click.option('--prime', is_flag=True)
@click.option('--debug', is_flag=True) @click.option('--debug', is_flag=True)
@click.option('--dryrun', 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): def main(ctx, db, prime, debug, dryrun):
global dr global dr
@ -138,10 +138,9 @@ def pnutpost(entry, source, token):
} }
} }
raw = [crosspost] raw = [crosspost]
for link in entry.links: for media in entry.media_content:
if link.rel == "enclosure": if media["medium"] == "image":
if "image" in link.type: raw.append(embed_image(media["url"]))
raw.append(embed_image(link))
try: try:
rx = re.compile('<.*?>') rx = re.compile('<.*?>')
@ -170,7 +169,7 @@ def pnutpost(entry, source, token):
def embed_image(link): def embed_image(link):
resume_header = {'Range': 'bytes=0-2000000'} 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 = ImageFile.Parser()
p.feed(r.content) p.feed(r.content)
@ -181,7 +180,7 @@ def embed_image(link):
'type': "photo", 'type': "photo",
'width': width, 'width': width,
'height': height, 'height': height,
'url': link.href 'url': link
} }
return {'type': "io.pnut.core.oembed", 'value': embed} return {'type': "io.pnut.core.oembed", 'value': embed}

View file

@ -2,7 +2,7 @@ from setuptools import setup
setup( setup(
name='feedbot', name='feedbot',
version='0.2.0', version='0.2.1',
py_modules=[ py_modules=[
'models', 'models',
'feedbot', 'feedbot',