py3: Port urllib in metadata sources

This commit is contained in:
Kovid Goyal 2019-04-01 15:30:44 +05:30
parent 96f4c4c3a2
commit e0205790b9
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
9 changed files with 43 additions and 14 deletions

View File

@ -12,7 +12,10 @@ try:
except ImportError:
from Queue import Empty, Queue
from threading import Thread
from urlparse import urlparse
try:
from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse
from calibre import as_unicode, browser, random_user_agent
from calibre.ebooks.metadata import check_isbn
@ -579,6 +582,9 @@ class Worker(Thread): # Get details {{{
return sanitize_comments_html(desc)
def parse_comments(self, root, raw):
try:
from urllib.parse import unquote
except ImportError:
from urllib import unquote
ans = ''
ns = tuple(self.selector('#bookDescription_feature_div noscript'))
@ -1048,6 +1054,9 @@ class Amazon(Source):
def create_query(self, log, title=None, authors=None, identifiers={}, # {{{
domain=None, for_amazon=True):
try:
from urllib.parse import urlencode
except ImportError:
from urllib import urlencode
if domain is None:
domain = self.domain

View File

@ -11,6 +11,9 @@ from calibre.ebooks.metadata.sources.base import Source, Option
def get_urls(br, tokens):
try:
from urllib.parse import quote_plus
except ImportError:
from urllib import quote_plus
from mechanize import Request
from lxml import html

View File

@ -178,6 +178,9 @@ class Douban(Source):
# }}}
def create_query(self, log, title=None, authors=None, identifiers={}): # {{{
try:
from urllib.parse import urlencode
except ImportError:
from urllib import urlencode
SEARCH_URL = 'https://api.douban.com/book/subjects?'
ISBN_URL = 'https://api.douban.com/book/subject/isbn/'

View File

@ -234,6 +234,9 @@ class Edelweiss(Source):
# }}}
def create_query(self, log, title=None, authors=None, identifiers={}):
try:
from urllib.parse import urlencode
except ImportError:
from urllib import urlencode
import time
BASE_URL = ('https://www.edelweiss.plus/GetTreelineControl.aspx?'

View File

@ -199,6 +199,9 @@ class GoogleBooks(Source):
# }}}
def create_query(self, log, title=None, authors=None, identifiers={}): # {{{
try:
from urllib.parse import urlencode
except ImportError:
from urllib import urlencode
BASE_URL = 'https://books.google.com/books/feeds/volumes?'
isbn = check_isbn(identifiers.get('isbn', None))

View File

@ -65,6 +65,9 @@ class GoogleImages(Source):
def get_image_urls(self, title, author, log, abort, timeout):
from calibre.utils.cleantext import clean_ascii_chars
try:
from urllib.parse import urlencode
except ImportError:
from urllib import urlencode
import json
from collections import OrderedDict

View File

@ -12,8 +12,7 @@ from datetime import datetime
from threading import Thread
from io import BytesIO
from operator import attrgetter
from urlparse import urlparse
from urllib import quote
from polyglot.urllib import urlparse, quote
from calibre.customize.ui import metadata_plugins, all_metadata_plugins
from calibre.ebooks.metadata import check_issn, authors_to_sort_string

View File

@ -57,12 +57,15 @@ class Ozon(Source):
)
def get_book_url(self, identifiers): # {{{
import urllib2
try:
from urllib.parse import quote
except ImportError:
from urllib import quote
ozon_id = identifiers.get('ozon', None)
res = None
if ozon_id:
# no affiliateId is used in search/detail
url = '{}/context/detail/id/{}'.format(self.ozon_url, urllib2.quote(ozon_id), _get_affiliateId())
url = '{}/context/detail/id/{}'.format(self.ozon_url, quote(ozon_id), _get_affiliateId())
res = ('ozon', ozon_id, url)
return res

View File

@ -8,8 +8,11 @@ import json
import re
import time
from collections import defaultdict, namedtuple
from urllib import quote_plus, urlencode
from urlparse import parse_qs
try:
from urllib.parse import parse_qs, quote_plus, urlencode
except ImportError:
from urlparse import parse_qs
from urllib import quote_plus, urlencode
from lxml import etree