ryelogheat / xpbot

Analyze a media file, identify the TMDB/IMDB, and generate all the necessary info to upload a torrent to a private tracker using the UNIT3D codebase
55 stars 27 forks source link

RuntimeError: Unexpected response: {'files': [{'error': 'image has been banned', 'error_code': 107, 'url': '', 'thumbnail_url':... #28

Closed Ruke805 closed 3 years ago

Ruke805 commented 3 years ago

I'm getting these errors when the program tries to upload the screenshots:

Uploading to imgbox
┌─────────────────────────────── Traceback (most recent call last) ────────────────────────────────┐
│ C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\pyimgbox\_gallery.py:263 │
│ in _upload_image                                                                                 │
│                                                                                                  │
│   260 │   │   │   log.debug('POST response: %s', response)                                       │
│   261 │   │   │   try:                                                                           │
│   262 │   │   │   │   info = response['files'][0]                                                │
│ > 263 │   │   │   │   image_url = info['original_url']                                           │
│   264 │   │   │   │   thumbnail_url = info['thumbnail_url']                                      │
│   265 │   │   │   │   web_url = info['url']                                                      │
│   266 │   │   │   except (KeyError, IndexError, TypeError) as e:                                 │
└──────────────────────────────────────────────────────────────────────────────────────────────────┘
KeyError: 'original_url'

The above exception was the direct cause of the following exception:

┌─────────────────────────────── Traceback (most recent call last) ────────────────────────────────┐
│ C:\Users\Desktop\xpbot-master\auto_upload.py:1871 in <module>                              │
│                                                                                                  │
│   1868 │   │   │   │   │   │   │   │   │     upload_media_import=torrent_info["raw_video_file"]  │
│   1869 │   │   │   │   │   │   │   │   │     torrent_title_import=torrent_info["title"],         │
│   1870 │   │   │   │   │   │   │   │   │     base_path=working_folder,                           │
│ > 1871 │   │   │   │   │   │   │   │   │     discord_url=discord_url                             │
│   1872 │   │   │   │   │   │   │   │   │     ))                                                  │
│   1873 │   if os.path.exists(f'{working_folder}/temp_upload/bbcode_images.txt'):                 │
│   1874 │   │   torrent_info["bbcode_images"] = f'{working_folder}/temp_upload/bbcode_images.txt  │
│                                                                                                  │
│ C:\Users\Desktop\xpbot-master\images\upload_screenshots.py:238 in take_upload_screens      │
│                                                                                                  │
│   235 │   │   # Now we start the actual upload process                                           │
│   236 │   │   for host_site, host_api in upload_to_host_dict.items():                            │
│   237 │   │   │   # Call the function that actually uploads the images                           │
│ > 238 │   │   │   upload_status = upload_screens(img_host=host_site, api_key=host_api, working   │
│   239 │   │   │   # Check "thumbs_links_dict" to verify images have uploaded and we have all t   │
│   240 │   │   │                                                                                  │
│   241 │   │   │   # if upload_status is equal to "failed" then we simply skip everything below   │
│                                                                                                  │
│ C:\Users\Desktop\xpbot-master\images\upload_screenshots.py:167 in upload_screens           │
│                                                                                                  │
│   164 │   │                                                                                      │
│   165 │   │   # Python 3.6 friendly alternative                                                  │
│   166 │   │   loop = asyncio.get_event_loop()                                                    │
│ > 167 │   │   loop.run_until_complete(imgbox_upload(list_of_images))                             │
│   168 │   │                                                                                      │
│   169 │   │   logging.info(f"imgbox edit_url: {edit_url[0]}")  # log the edit url                │
│                                                                                                  │
│ C:\Users\AppData\Local\Programs\Python\Python37\lib\asyncio\base_events.py:587 in          │
│ run_until_complete                                                                               │
│                                                                                                  │
│    584 │   │   if not future.done():                                                             │
│    585 │   │   │   raise RuntimeError('Event loop stopped before Future completed.')             │
│    586 │   │                                                                                     │
│ >  587 │   │   return future.result()                                                            │
│    588 │                                                                                         │
│    589 │   def stop(self):                                                                       │
│    590 │   │   """Stop running the event loop.                                                   │
│                                                                                                  │
│ C:\Users\Desktop\xpbot-master\images\upload_screenshots.py:139 in imgbox_upload            │
│                                                                                                  │
│   136 │   if img_host == "imgbox":                                                               │
│   137 │   │   async def imgbox_upload(list_of_filepath):                                         │
│   138 │   │   │   async with pyimgbox.Gallery(title=torrent_title, thumb_width=350) as gallery   │
│ > 139 │   │   │   │   async for submission in gallery.add(list_of_filepath):                     │
│   140 │   │   │   │   │   if not submission['success']:                                          │
│   141 │   │   │   │   │   │   logging.error(f"{submission['filename']}: {submission['error']}"   │
│   142 │   │   │   │   │   │   return "failed"                                                    │
│                                                                                                  │
│ C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\pyimgbox\_gallery.py:303 │
│ in add                                                                                           │
│                                                                                                  │
│   300 │   │   Yield Submission objects asynchronously.                                           │
│   301 │   │   """                                                                                │
│   302 │   │   for filepath, filetuple, error in self._prepare(*filepaths):                       │
│ > 303 │   │   │   yield await self._upload_image(filepath, filetuple, error)                     │
│   304 │                                                                                          │
│   305 │   def __repr__(self):                                                                    │
│   306 │   │   return (                                                                           │
│                                                                                                  │
│ C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\pyimgbox\_gallery.py:268 │
│ in _upload_image                                                                                 │
│                                                                                                  │
│   265 │   │   │   │   web_url = info['url']                                                      │
│   266 │   │   │   except (KeyError, IndexError, TypeError) as e:                                 │
│   267 │   │   │   │   log.debug('Unexpected response: %r', response)                             │
│ > 268 │   │   │   │   raise RuntimeError(f'Unexpected response: {response!r}') from e            │
│   269 │   │   │   return Submission(                                                             │
│   270 │   │   │   │   filepath=filepath,                                                         │
│   271 │   │   │   │   image_url=image_url,                                                       │
└──────────────────────────────────────────────────────────────────────────────────────────────────┘
RuntimeError: Unexpected response: {'files': [{'error': 'image has been banned', 'error_code': 107, 'url': '', 'thumbnail_url': '', 'delete_url': '',
'delete_type': 'DELETE', 'name': 'M.C. Escher', 'size': 0}]}

I made a test with another file and worked, but with this one, I had this problem.

ryelogheat commented 3 years ago

In final lines of the log you posted, you can see it says image has been banned so this seems to be an issue with the image you are uploading & imgbox. This can happen if you upload the same image repeatedly (if you are testing out the bot just set the num_of_screenshots to 0)

ryelogheat commented 3 years ago

I'll close the issue now & add some better error for image uploads in the future.

Though keep in mind there isn't any way for me to work around the issue you are having (imgbox banned specific image). You can try some stuff like compressing the image or just taking a screenshot at a different frame (increase/decrease the num_of_screenshots value to change when screenshots are taken)

Ruke805 commented 3 years ago

In final lines of the log you posted, you can see it says image has been banned so this seems to be an issue with the image you are uploading & imgbox. This can happen if you upload the same image repeatedly (if you are testing out the bot just set the _num_ofscreenshots to 0)

That is weird, I saw this error but I tried the same torrent with BHD and for some reason worked well, but with BLU I got this error.

I tried again with imgbb, I generated the API, but I don't know if I configurated it correctly in the config file. I could not find something in the Wiki in how to configure the imgbb API, I put it this way: imgbb_api_key= # https://api.imgbb.com/xxxxxxxxxxxxxx but did not work. It takes the screenshots but does not upload them, and no error message appears, just an empty text in the bbcode_images.txt

ryelogheat commented 3 years ago

It might have just been a temporarily ban that expired between the time you uploaded to BHD & BLU

As for the imgbb api key, lets assume your API key is 329dc601aeqcc8bc3f9015487da6p00f you'll want to format it like so in config.env imgbb_api_key=329dc601aeqcc8bc3f9015487da6p00f

I think you may have accidentally add the API Key to the comment on that line :smile: tbh it is a bit dumb of me to include comments inline with the actual key so you can just delete the whole line and paste in the example I posted earlier ^^

Let me know if that helps or if you need more help :+1:

Ruke805 commented 3 years ago

Nice, now worked. I thought I need to combine it with the API URL, but just the key is enough. Thanks!

One last thing, I've noticed some dedupe false positives with names completely different, in some cases, I had to edit the config.env and put 100% of similarity to complete the upload.

Take a look:

image

I've tested with BLU

ryelogheat commented 3 years ago

I just pushed a small update https://github.com/ryelogheat/xpbot/commit/d583713784970875ed7a1f6a912f4e1f9b959b5c can you get those changes on your local copy and let me know how it goes

(In linux I would just cd in the xpbot folder and type git pull but I'm not sure if its the same in windows)

The change I want you to try out is a small edit in the blutopia.json file (site_templates), see this link for specifics https://github.com/ryelogheat/xpbot/commit/d583713784970875ed7a1f6a912f4e1f9b959b5c#diff-07137d0fd8f93f759a0f55951e356db7bde95427064652d0f5bf74baee4dca26R140

ryelogheat commented 3 years ago

Actually wait, I forgot another small issue that I have yet to fix. It won't work atm

ryelogheat commented 3 years ago

The problem is that UNIT3D updated the url parameters you need to pass when searching via an IMDB ID (Went from imdb=0111161 to imdbId=0111161)

Also notice how the tt is missing from those ^^ IDs? Normally you see IMDB IDs like this https://www.imdb.com/title/tt0111161 but BLU & basically all other UNIT3D sites want the tt removed. Currently I'm not doing that so the dupe check basically is useless on anything other than BHD atm (BHD doesn't have any issues with the tt)

give me a few minutes & I'll update the project with something that should work :smile:

Ruke805 commented 3 years ago

Nice, take your time ^^

ryelogheat commented 3 years ago

OK it should be fixed now https://github.com/ryelogheat/xpbot/commit/43765d9867399e5596f9697e2c414054429eb910 :sweat_smile:

Now update your copy of the bot & let me know how it goes (Keep the bot in manual mode for the first time you test it so you'll get prompted if you want to continue the upload or not)

Ruke805 commented 3 years ago

Hi, I don't know If I did right to update the program. I downloaded the code and replaced the files, but now I'm getting this error with screenshots:

Taking 6 screenshots
┌─────────────────────────────── Traceback (most recent call last) ────────────────────────────────┐
│ C:\Users\Desktop\xpbot-master\auto_upload.py:1871 in <module>                              │
│                                                                                                  │
│   1868 │   │   │   │   │   │   │   │   │     upload_media_import=torrent_info["raw_video_file"]  │
│   1869 │   │   │   │   │   │   │   │   │     torrent_title_import=torrent_info["title"],         │
│   1870 │   │   │   │   │   │   │   │   │     base_path=working_folder,                           │
│ > 1871 │   │   │   │   │   │   │   │   │     discord_url=discord_url                             │
│   1872 │   │   │   │   │   │   │   │   │     ))                                                  │
│   1873 │   if os.path.exists(f'{working_folder}/temp_upload/bbcode_images.txt'):                 │
│   1874 │   │   torrent_info["bbcode_images"] = f'{working_folder}/temp_upload/bbcode_images.txt  │
│                                                                                                  │
│ C:\Users\ Desktop\xpbot-master\images\upload_screenshots.py:185 in take_upload_screens      │
│                                                                                                  │
│   182 │   # Verify that at least 1 image host is enabled so we don't waste time taking unneede   │
│   183 │   upload_to_host_dict = {}                                                               │
│   184 │   for host in range(1, 5):  # current number of image hosts available (4)                │
│ > 185 │   │   if len(os.getenv(f'img_host_{host}')) != 0:                                        │
│   186 │   │   │   if len(os.getenv(f"{os.getenv(f'img_host_{host}')}_api_key")) == 0:            │
│   187 │   │   │   │                                                                              │
│   188 │   │   │   │   console.print(f"Can't upload to [bold]{os.getenv(f'img_host_{host}')}[/b   │
└──────────────────────────────────────────────────────────────────────────────────────────────────┘
TypeError: object of type 'NoneType' has no len()
ryelogheat commented 3 years ago

Make sure your config.env looks like this (Check for typos & make sure all 4 options (both hosts & api info) are in your config.env even if they aren't being used) config

Ruke805 commented 3 years ago

I see, you've updated the config.env too, I kept mine the same, that's why was not working. I had this error #27 again, so I edited the py file as you said, and now worked well. No more false dupe.

Thanks for the job!