xchewtoyx / calibre-comicvine

Comicvine calibre metadata source for comic-books and Graphic Novels
MIT License
31 stars 11 forks source link

Update to python 3 and calibre 5 #11

Open jbbandos opened 2 years ago

jbbandos commented 2 years ago

Hello, this is just a quick hack but allows your plugin to work on Calibre 5 / Python 3. Can you merge it to your repository? Thank you

kborghs commented 2 years ago

Hi, Thanks for the upgrade to calibre 5. However, when I try to use it, I get the following error:

calibre, version 5.40.0
ERROR: No matches found: <p>Failed to find any books that match your search. Try making the search <b>less specific</b>. For example, use only the author's last name and a single distinctive word from the title.<p>To see the full log, click "Show details".

Running identify query with parameters: 
{'title': 'Ascendance of A Bookworm', 'authors': ['Miya Kazuki'], 'identifiers': {'comicvine-volume': '121126'}, 'timeout': 30} 
Using plugins: Comicvine (0, 13, 3) 
The log from individual plugins is below 

********** Comicvine (0, 13, 3) ********** 
Found 0 results 
Downloading from Comicvine took 1.224926471710205 
We have a Volume(121126)
Searching for ['ascendance', 'of', 'bookworm'] #None
Looking up volume: 121126
Looking up volume: 121126
Plugin Comicvine failed
Traceback (most recent call last):
  File "calibre\ebooks\metadata\sources\identify.py", line 47, in run
  File "calibre_plugins.comicvine.source", line 159, in identify
  File "calibre_plugins.comicvine.utils", line 218, in find_title
  File "calibre_plugins.comicvine.utils", line 88, in retry_function
  File "calibre_plugins.comicvine.utils", line 142, in find_volumes
  File "calibre_plugins.comicvine.pycomicvine._init", line 225, in __new_
  File "calibre_plugins.comicvine.pycomicvine._init", line 972, in __init_
  File "calibre_plugins.comicvine.pycomicvine._init", line 375, in __init_
  File "calibre_plugins.comicvine.pycomicvine._init_", line 362, in _request_object
  File "calibre_plugins.comicvine.pycomicvine._init_", line 192, in _request
  File "urllib\request.py", line 222, in urlopen
  File "urllib\request.py", line 531, in open
  File "urllib\request.py", line 640, in http_response
  File "urllib\request.py", line 563, in error
  File "urllib\request.py", line 502, in _call_chain
  File "urllib\request.py", line 755, in http_error_302
  File "urllib\request.py", line 531, in open
  File "urllib\request.py", line 640, in http_response
  File "urllib\request.py", line 569, in error
  File "urllib\request.py", line 502, in _call_chain
  File "urllib\request.py", line 649, in http_error_default
urllib.error.HTTPError: HTTP Error 403: Forbidden 

**************************** 
The identify phase took 1.23 seconds 
The longest time (1.224926) was taken by: Comicvine 
Merging results from different sources 
We have 0 merged results, merging took: 0.00 seconds

Somebody has an idea what this can be?

dertasiu commented 2 years ago

@kborghs I've just discovered what it is causing. It seems that comicvine API is returning a 403 HTTP status code when the user agent is the default in python. I've just tried to change it and set a browser user agent and it works again. Around line 193 in the pycomicvine/init.py file:

r = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0 (X11; U; Linux i686) Gecko/20071127 Firefox/2.0.0.11'})

if timeout == None:
    response_raw = json.loads(urllib.request.urlopen(r).read())
else:
    response_raw = json.loads(urllib.request.urlopen(
            r,
            timeout=timeout
        ).read())
jbbandos commented 2 years ago

@kborghs - did you configure the plugin with a valid API key? You need to create an account at comicvine and get an API key. @dertasiu - that will work until comicvine's api decides that user agent is doing too many queries and blocks it for some time.

dertasiu commented 2 years ago

@jbbandos Yes. I forgot to put in my message that changing the user agent was a temporary solution.

jbbandos commented 2 years ago

I've been able to reproduce this, even with a perfectly valid API key. I'll try to fix it now. @kborghs - do you mind (re)opening this issue on my comicvine fork - https://github.com/jbbandos/calibre-comicvine ? Thanks!

jbbandos commented 2 years ago

@kborghs @dertasiu - I've done a quick fix based on the user agent, apparently comicvine is blacklisting a few user agents, including the default python one. I'll push a release soon.