mirror of
https://github.com/myned/modufur.git
synced 2024-12-24 22:27:28 +00:00
Update e621 API endpoints and structure
This commit is contained in:
parent
75698ba127
commit
fc3483fec8
1 changed files with 60 additions and 54 deletions
|
@ -294,14 +294,15 @@ class MsG(cmds.Cog):
|
||||||
ident = ident if not ident.isdigit() else re.search(
|
ident = ident if not ident.isdigit() else re.search(
|
||||||
'show/([0-9]+)', ident).group(1)
|
'show/([0-9]+)', ident).group(1)
|
||||||
post = await u.fetch(f'https://e621.net/posts/{ident}.json', json=True)
|
post = await u.fetch(f'https://e621.net/posts/{ident}.json', json=True)
|
||||||
|
post = post['post']
|
||||||
|
|
||||||
embed = d.Embed(
|
embed = d.Embed(
|
||||||
title=', '.join(post['artist']), url=f'https://e621.net/post/show/{post["id"]}', color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else u.color)
|
title=', '.join(post['tags']['artist']), url=f'https://e621.net/posts/{post["id"]}', color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else u.color)
|
||||||
embed.set_thumbnail(url=post['file_url'])
|
embed.set_thumbnail(url=post['sample']['url'])
|
||||||
embed.set_author(name=f'{post["width"]} x {post["height"]}',
|
embed.set_author(name=f'{post["file"]["width"]} x {post["file"]["height"]}',
|
||||||
url=f'https://e621.net/post?tags=ratio:{post["width"]/post["height"]:.2f}', icon_url=ctx.author.avatar_url)
|
url=f'https://e621.net/posts?tags=ratio:{post["file"]["width"]/post["file"]["height"]:.2f}', icon_url=ctx.author.avatar_url)
|
||||||
embed.set_footer(text=post['score'],
|
embed.set_footer(text=post['score']['total'],
|
||||||
icon_url=self._get_icon(post['score']))
|
icon_url=self._get_icon(post['score']['total']))
|
||||||
|
|
||||||
except exc.MissingArgument:
|
except exc.MissingArgument:
|
||||||
await ctx.send('\N{HEAVY EXCLAMATION MARK SYMBOL} **Invalid url**')
|
await ctx.send('\N{HEAVY EXCLAMATION MARK SYMBOL} **Invalid url**')
|
||||||
|
@ -375,7 +376,7 @@ class MsG(cmds.Cog):
|
||||||
else:
|
else:
|
||||||
raise exc.NotFound
|
raise exc.NotFound
|
||||||
|
|
||||||
await ctx.send(f'**{tempool["name"]}**\nhttps://e621.net/pool/show/{tempool["id"]}')
|
await ctx.send(f'**{tempool["name"]}**\nhttps://e621.net/pools/{tempool["id"]}')
|
||||||
|
|
||||||
except exc.Abort as e:
|
except exc.Abort as e:
|
||||||
await e.message.edit(content='\N{NO ENTRY SIGN}')
|
await e.message.edit(content='\N{NO ENTRY SIGN}')
|
||||||
|
@ -655,13 +656,13 @@ class MsG(cmds.Cog):
|
||||||
else:
|
else:
|
||||||
raise exc.NotFound
|
raise exc.NotFound
|
||||||
|
|
||||||
page = 1
|
for ident in tempool['post_ids']:
|
||||||
while len(posts) < tempool['post_count']:
|
post = await u.fetch(f'https://{booru}.net/posts/{ident}.json', json=True)
|
||||||
posts_request = await u.fetch('https://{}.net/pool/show.json'.format(booru), params={'id': tempool['id'], 'page': page}, json=True)
|
post = post['post']
|
||||||
for post in posts_request['posts']:
|
posts[post['id']] = {'artist': ', '.join(
|
||||||
posts[post['id']] = {'artist': ', '.join(
|
post['tags']['artist']), 'sample_url': post['sample']['url'], 'score': post['score']['total']}
|
||||||
post['artist']), 'file_url': post['file_url'], 'score': post['score']}
|
|
||||||
page += 1
|
await asyncio.sleep(0.5)
|
||||||
|
|
||||||
return pool, posts
|
return pool, posts
|
||||||
|
|
||||||
|
@ -711,15 +712,16 @@ class MsG(cmds.Cog):
|
||||||
raise exc.Timeout
|
raise exc.Timeout
|
||||||
|
|
||||||
request = await u.fetch(f'https://{booru}.net/posts.json?tags={"+".join([order] + tags)}&limit={int(320)}', json=True)
|
request = await u.fetch(f'https://{booru}.net/posts.json?tags={"+".join([order] + tags)}&limit={int(320)}', json=True)
|
||||||
|
if len(request['posts']) == 0:
|
||||||
raise exc.NotFound(' '.join(tags))
|
raise exc.NotFound(' '.join(tags))
|
||||||
if len(request) < limit:
|
if len(request['posts']) < limit:
|
||||||
limit = len(request)
|
limit = len(request['posts'])
|
||||||
|
|
||||||
for post in request:
|
for post in request['posts']:
|
||||||
if 'swf' in post['file_ext'] or 'webm' in post['file_ext']:
|
if 'swf' in post['file']['ext'] or 'webm' in post['file']['ext']:
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
post_tags = post['tags'].split(' ')
|
post_tags = [tag for tags in post['tags'].values() for tag in tags]
|
||||||
for tag in blacklist:
|
for tag in blacklist:
|
||||||
if tag in post_tags:
|
if tag in post_tags:
|
||||||
raise exc.Continue
|
raise exc.Continue
|
||||||
|
@ -727,7 +729,7 @@ class MsG(cmds.Cog):
|
||||||
continue
|
continue
|
||||||
if post['id'] not in posts.keys() and post['id'] not in previous.keys():
|
if post['id'] not in posts.keys() and post['id'] not in previous.keys():
|
||||||
posts[post['id']] = {'artist': ', '.join(
|
posts[post['id']] = {'artist': ', '.join(
|
||||||
post['artist']), 'file_url': post['file_url'], 'score': post['score']}
|
post['tags']['artist']), 'sample_url': post['sample']['url'], 'score': post['score']['total']}
|
||||||
if len(posts) == limit:
|
if len(posts) == limit:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -771,26 +773,28 @@ class MsG(cmds.Cog):
|
||||||
hearted = {}
|
hearted = {}
|
||||||
c = 1
|
c = 1
|
||||||
|
|
||||||
await ctx.trigger_typing()
|
if not args:
|
||||||
|
raise exc.MissingArgument
|
||||||
|
|
||||||
pool, posts = await self._get_pool(ctx, booru='e621', query=query)
|
async with ctx.channel.typing():
|
||||||
keys = list(posts.keys())
|
pool, posts = await self._get_pool(ctx, booru='e621', query=query)
|
||||||
values = list(posts.values())
|
keys = list(posts.keys())
|
||||||
|
values = list(posts.values())
|
||||||
|
|
||||||
embed = d.Embed(
|
embed = d.Embed(
|
||||||
title=values[c - 1]['artist'], url='https://e621.net/post/show/{}'.format(keys[c - 1]), color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else u.color)
|
title=values[c - 1]['artist'], url='https://e621.net/posts/{}'.format(keys[c - 1]), color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else u.color)
|
||||||
embed.set_image(url=values[c - 1]['file_url'])
|
embed.set_image(url=values[c - 1]['sample_url'])
|
||||||
embed.set_author(name=pool['name'],
|
embed.set_author(name=pool['name'],
|
||||||
url='https://e621.net/pool/show?id={}'.format(pool['id']), icon_url=ctx.author.avatar_url)
|
url='https://e621.net/pools/{}'.format(pool['id']), icon_url=ctx.author.avatar_url)
|
||||||
embed.set_footer(text='{} / {}'.format(c, len(posts)),
|
embed.set_footer(text='{} / {}'.format(c, len(posts)),
|
||||||
icon_url=self._get_icon(values[c - 1]['score']))
|
icon_url=self._get_icon(values[c - 1]['score']))
|
||||||
|
|
||||||
paginator = await ctx.send(embed=embed)
|
paginator = await ctx.send(embed=embed)
|
||||||
|
|
||||||
for emoji in ('\N{HEAVY BLACK HEART}', '\N{LEFTWARDS BLACK ARROW}', '\N{NUMBER SIGN}\N{COMBINING ENCLOSING KEYCAP}', '\N{BLACK RIGHTWARDS ARROW}'):
|
for emoji in ('\N{HEAVY BLACK HEART}', '\N{LEFTWARDS BLACK ARROW}', '\N{NUMBER SIGN}\N{COMBINING ENCLOSING KEYCAP}', '\N{BLACK RIGHTWARDS ARROW}'):
|
||||||
await paginator.add_reaction(emoji)
|
await paginator.add_reaction(emoji)
|
||||||
await u.add_reaction(ctx.message, '\N{OCTAGONAL SIGN}')
|
await u.add_reaction(ctx.message, '\N{OCTAGONAL SIGN}')
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
while not self.bot.is_closed():
|
while not self.bot.is_closed():
|
||||||
try:
|
try:
|
||||||
|
@ -811,11 +815,11 @@ class MsG(cmds.Cog):
|
||||||
if c > 1:
|
if c > 1:
|
||||||
c -= 1
|
c -= 1
|
||||||
embed.title = values[c - 1]['artist']
|
embed.title = values[c - 1]['artist']
|
||||||
embed.url = 'https://e621.net/post/show/{}'.format(
|
embed.url = 'https://e621.net/posts/{}'.format(
|
||||||
keys[c - 1])
|
keys[c - 1])
|
||||||
embed.set_footer(text='{} / {}'.format(c, len(posts)),
|
embed.set_footer(text='{} / {}'.format(c, len(posts)),
|
||||||
icon_url=self._get_icon(values[c - 1]['score']))
|
icon_url=self._get_icon(values[c - 1]['score']))
|
||||||
embed.set_image(url=values[c - 1]['file_url'])
|
embed.set_image(url=values[c - 1]['sample_url'])
|
||||||
|
|
||||||
await paginator.edit(content='\N{HEAVY BLACK HEART}' if keys[c - 1] in hearted.keys() else None, embed=embed)
|
await paginator.edit(content='\N{HEAVY BLACK HEART}' if keys[c - 1] in hearted.keys() else None, embed=embed)
|
||||||
else:
|
else:
|
||||||
|
@ -829,11 +833,11 @@ class MsG(cmds.Cog):
|
||||||
c = int(number.content)
|
c = int(number.content)
|
||||||
|
|
||||||
embed.title = values[c - 1]['artist']
|
embed.title = values[c - 1]['artist']
|
||||||
embed.url = 'https://e621.net/post/show/{}'.format(
|
embed.url = 'https://e621.net/posts/{}'.format(
|
||||||
keys[c - 1])
|
keys[c - 1])
|
||||||
embed.set_footer(text='{} / {}'.format(c, len(posts)),
|
embed.set_footer(text='{} / {}'.format(c, len(posts)),
|
||||||
icon_url=self._get_icon(values[c - 1]['score']))
|
icon_url=self._get_icon(values[c - 1]['score']))
|
||||||
embed.set_image(url=values[c - 1]['file_url'])
|
embed.set_image(url=values[c - 1]['sample_url'])
|
||||||
|
|
||||||
if ctx.channel is d.TextChannel:
|
if ctx.channel is d.TextChannel:
|
||||||
with suppress(errext.CheckFailure):
|
with suppress(errext.CheckFailure):
|
||||||
|
@ -845,11 +849,11 @@ class MsG(cmds.Cog):
|
||||||
if c < len(keys):
|
if c < len(keys):
|
||||||
c += 1
|
c += 1
|
||||||
embed.title = values[c - 1]['artist']
|
embed.title = values[c - 1]['artist']
|
||||||
embed.url = 'https://e621.net/post/show/{}'.format(
|
embed.url = 'https://e621.net/posts/{}'.format(
|
||||||
keys[c - 1])
|
keys[c - 1])
|
||||||
embed.set_footer(text='{} / {}'.format(c, len(posts)),
|
embed.set_footer(text='{} / {}'.format(c, len(posts)),
|
||||||
icon_url=self._get_icon(values[c - 1]['score']))
|
icon_url=self._get_icon(values[c - 1]['score']))
|
||||||
embed.set_image(url=values[c - 1]['file_url'])
|
embed.set_image(url=values[c - 1]['sample_url'])
|
||||||
|
|
||||||
await paginator.edit(content='\N{HEAVY BLACK HEART}' if keys[c - 1] in hearted.keys() else None, embed=embed)
|
await paginator.edit(content='\N{HEAVY BLACK HEART}' if keys[c - 1] in hearted.keys() else None, embed=embed)
|
||||||
else:
|
else:
|
||||||
|
@ -865,6 +869,9 @@ class MsG(cmds.Cog):
|
||||||
await paginator.edit(content='\N{HOURGLASS}')
|
await paginator.edit(content='\N{HOURGLASS}')
|
||||||
except UnboundLocalError:
|
except UnboundLocalError:
|
||||||
await ctx.send('\N{HOURGLASS}')
|
await ctx.send('\N{HOURGLASS}')
|
||||||
|
except exc.MissingArgument:
|
||||||
|
await ctx.send('**Missing argument**')
|
||||||
|
await u.add_reaction(ctx.message, '\N{CROSS MARK}')
|
||||||
except exc.NotFound:
|
except exc.NotFound:
|
||||||
await ctx.send('**Pool not found**')
|
await ctx.send('**Pool not found**')
|
||||||
await u.add_reaction(ctx.message, '\N{CROSS MARK}')
|
await u.add_reaction(ctx.message, '\N{CROSS MARK}')
|
||||||
|
@ -914,10 +921,10 @@ class MsG(cmds.Cog):
|
||||||
values = list(posts.values())
|
values = list(posts.values())
|
||||||
|
|
||||||
embed = d.Embed(
|
embed = d.Embed(
|
||||||
title=values[c - 1]['artist'], url='https://{}.net/post/show/{}'.format(booru, keys[c - 1]), color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else u.color)
|
title=values[c - 1]['artist'], url='https://{}.net/posts/{}'.format(booru, keys[c - 1]), color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else u.color)
|
||||||
embed.set_image(url=values[c - 1]['file_url'])
|
embed.set_image(url=values[c - 1]['sample_url'])
|
||||||
embed.set_author(name=' '.join(tags) if tags else order,
|
embed.set_author(name=' '.join(tags) if tags else order,
|
||||||
url='https://{}.net/post?tags={}'.format(booru, ','.join(tags)), icon_url=ctx.author.avatar_url)
|
url='https://{}.net/posts?tags={}'.format(booru, '+'.join(tags) if tags else order), icon_url=ctx.author.avatar_url)
|
||||||
embed.set_footer(text=values[c - 1]['score'],
|
embed.set_footer(text=values[c - 1]['score'],
|
||||||
icon_url=self._get_icon(values[c - 1]['score']))
|
icon_url=self._get_icon(values[c - 1]['score']))
|
||||||
|
|
||||||
|
@ -947,12 +954,12 @@ class MsG(cmds.Cog):
|
||||||
if c > 1:
|
if c > 1:
|
||||||
c -= 1
|
c -= 1
|
||||||
embed.title = values[c - 1]['artist']
|
embed.title = values[c - 1]['artist']
|
||||||
embed.url = 'https://{}.net/post/show/{}'.format(
|
embed.url = 'https://{}.net/posts/{}'.format(
|
||||||
booru,
|
booru,
|
||||||
keys[c - 1])
|
keys[c - 1])
|
||||||
embed.set_footer(text=values[c - 1]['score'],
|
embed.set_footer(text=values[c - 1]['score'],
|
||||||
icon_url=self._get_icon(values[c - 1]['score']))
|
icon_url=self._get_icon(values[c - 1]['score']))
|
||||||
embed.set_image(url=values[c - 1]['file_url'])
|
embed.set_image(url=values[c - 1]['sample_url'])
|
||||||
|
|
||||||
await paginator.edit(content='\N{HEAVY BLACK HEART}' if keys[c - 1] in hearted.keys() else None, embed=embed)
|
await paginator.edit(content='\N{HEAVY BLACK HEART}' if keys[c - 1] in hearted.keys() else None, embed=embed)
|
||||||
else:
|
else:
|
||||||
|
@ -971,12 +978,12 @@ class MsG(cmds.Cog):
|
||||||
if c < len(keys):
|
if c < len(keys):
|
||||||
c += 1
|
c += 1
|
||||||
embed.title = values[c - 1]['artist']
|
embed.title = values[c - 1]['artist']
|
||||||
embed.url = 'https://{}.net/post/show/{}'.format(
|
embed.url = 'https://{}.net/posts/{}'.format(
|
||||||
booru,
|
booru,
|
||||||
keys[c - 1])
|
keys[c - 1])
|
||||||
embed.set_footer(text=values[c - 1]['score'],
|
embed.set_footer(text=values[c - 1]['score'],
|
||||||
icon_url=self._get_icon(values[c - 1]['score']))
|
icon_url=self._get_icon(values[c - 1]['score']))
|
||||||
embed.set_image(url=values[c - 1]['file_url'])
|
embed.set_image(url=values[c - 1]['sample_url'])
|
||||||
|
|
||||||
await paginator.edit(content='\N{HEAVY BLACK HEART}' if keys[c - 1] in hearted.keys() else None, embed=embed)
|
await paginator.edit(content='\N{HEAVY BLACK HEART}' if keys[c - 1] in hearted.keys() else None, embed=embed)
|
||||||
else:
|
else:
|
||||||
|
@ -1044,11 +1051,11 @@ class MsG(cmds.Cog):
|
||||||
posts, order = await self._get_posts(ctx, booru=booru, tags=tags, limit=limit)
|
posts, order = await self._get_posts(ctx, booru=booru, tags=tags, limit=limit)
|
||||||
|
|
||||||
for ident, post in posts.items():
|
for ident, post in posts.items():
|
||||||
embed = d.Embed(title=post['artist'], url='https://{}.net/post/show/{}'.format(booru, ident),
|
embed = d.Embed(title=post['artist'], url='https://{}.net/posts/{}'.format(booru, ident),
|
||||||
color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else u.color)
|
color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else u.color)
|
||||||
embed.set_image(url=post['file_url'])
|
embed.set_image(url=post['sample_url'])
|
||||||
embed.set_author(name=' '.join(tags) if tags else order,
|
embed.set_author(name=' '.join(tags) if tags else order,
|
||||||
url='https://{}.net/post?tags={}'.format(booru, ','.join(tags)), icon_url=ctx.author.avatar_url)
|
url='https://{}.net/posts?tags={}'.format(booru, '+'.join(tags) if tags else order), icon_url=ctx.author.avatar_url)
|
||||||
embed.set_footer(
|
embed.set_footer(
|
||||||
text=post['score'], icon_url=self._get_icon(post['score']))
|
text=post['score'], icon_url=self._get_icon(post['score']))
|
||||||
|
|
||||||
|
@ -1297,8 +1304,7 @@ class MsG(cmds.Cog):
|
||||||
if tags:
|
if tags:
|
||||||
for tag in tags:
|
for tag in tags:
|
||||||
request = await u.fetch(
|
request = await u.fetch(
|
||||||
'https://e621.net/tag_alias/index.json',
|
f'https://e621.net/tag_alias/index.json?aliased_to={tag}&approved=true',
|
||||||
params={'aliased_to': tag, 'approved': 'true'},
|
|
||||||
json=True)
|
json=True)
|
||||||
|
|
||||||
for elem in request:
|
for elem in request:
|
||||||
|
|
Loading…
Reference in a new issue