Closed rV4nxZ closed 1 year ago
Hey! @rV4nxZ You'll get a response soon! UwU
I tested on 3.10.11 everything works fine until some of my testing network marked as spam thus captcha were found on r34,
but it should throwing some JSONDecodeError
instead String slices must be integers
Could you tell some moreinfo pls
hi, i have good news, i just discover that this:
async def main():
r34 = Rule34()
img = await r34.search(query="sexy", limit=1)
img = json.loads(img)
urls = [item['file_url'] for item in img if item['file_url'].startswith('https://api-cdn.rule34.xxx/images/')]
print(urls)
asyncio.run(main())
parses the images correctly :D
it only works without the "gacha" tag, works with the "limit" tag
When using gacha method, all returns only 1 object/dict, so your loop statements is no use then
fixed it
img = await r34.search(query="sexy", gacha=True)
if isinstance(img, str):
# if img is a string, parse it as JSON
data = json.loads(img)
urls = [data['file_url']] if data['file_url'].startswith('https://api-cdn.') else []
else:
# if img is a list of image objects, extract the file urls
data = json.loads(img)
urls = [item['file_url'] for item in data if item['file_url'].startswith('https://api-cdn.')]
print(urls)
now i'll try to add it to the parse_image function and use the resolve instead of data = json.loads(img) to follow your code
updated function:
def parse_image_r34(raw_object: dict):
if isinstance(raw_object, str):
data = json.loads(raw_object)
urls = [data['file_url']] if data['file_url'].startswith('https://api-cdn.') else []
else:
data = json.loads(raw_object)
urls = [item['file_url'] for item in data if item['file_url'].startswith('https://api-cdn.')]
output: ['https://api-cdn.rule34.xxx/images/6747/48766c19aac641cae347e3a4180e817a.png']
You can always submit PR if the current flow is a bit clunky on your side
fixed it
img = await r34.search(query="sexy", gacha=True) if isinstance(img, str): # if img is a string, parse it as JSON data = json.loads(img) urls = [data['file_url']] if data['file_url'].startswith('https://api-cdn.') else [] else: # if img is a list of image objects, extract the file urls data = json.loads(img) urls = [item['file_url'] for item in data if item['file_url'].startswith('https://api-cdn.')] print(urls)
now i'll try to add it to the parse_image function and use the resolve instead of data = json.loads(img) to follow your code
What is the point reinventing urls with loop, while img is only single object, there is still make sense if you re-validating them in normal search not gacha
well for me it works for what i need
Describe the bug try: images = [i["file_url"] for i in data]
except: images = [i["file"]["url"] for i in data]
Gives the error. This is yours interpreter.
To Reproduce Steps to reproduce the behavior:
Expected behavior Give me only the url.
Desktop (please complete the following information):
Additional context No.