mirror of
https://github.com/spaam/svtplay-dl.git
synced 2024-11-27 21:54:17 +01:00
Isolate py3/2.7 conditional imports to own modules
This commit is contained in:
parent
119a49b0d2
commit
bd1ae14e53
@ -6,14 +6,10 @@ import os
|
||||
import re
|
||||
|
||||
from svtplay_dl.utils import get_http_data, select_quality
|
||||
from svtplay_dl.utils.io import StringIO
|
||||
from svtplay_dl.output import progressbar, progress_stream, ETA
|
||||
from svtplay_dl.log import log
|
||||
|
||||
if sys.version_info > (3, 0):
|
||||
from io import BytesIO as StringIO
|
||||
else:
|
||||
from StringIO import StringIO
|
||||
|
||||
def download_hls(options, url, baseurl=None):
|
||||
data = get_http_data(url)
|
||||
globaldata, files = parsem3u(data)
|
||||
|
@ -7,11 +7,7 @@ import re
|
||||
|
||||
from svtplay_dl.output import progress # FIXME use progressbar() instead
|
||||
from svtplay_dl.log import log
|
||||
|
||||
if sys.version_info > (3, 0):
|
||||
from urllib.request import urlopen, Request, HTTPError
|
||||
else:
|
||||
from urllib2 import urlopen, Request, HTTPError
|
||||
from svtplay_dl.utils.urllib import urlopen, Request, HTTPError
|
||||
|
||||
def download_http(options, url):
|
||||
""" Get the stream from HTTP """
|
||||
|
@ -5,17 +5,13 @@ import sys
|
||||
import re
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
from svtplay_dl.utils.urllib import urlparse, parse_qs
|
||||
from svtplay_dl.service import Service
|
||||
from svtplay_dl.utils import get_http_data
|
||||
from svtplay_dl.log import log
|
||||
from svtplay_dl.fetcher.rtmp import download_rtmp
|
||||
from svtplay_dl.fetcher.http import download_http
|
||||
|
||||
if sys.version_info > (3, 0):
|
||||
from urllib.parse import urlparse, parse_qs
|
||||
else:
|
||||
from urlparse import urlparse, parse_qs
|
||||
|
||||
class Aftonbladet(Service):
|
||||
def handle(self, url):
|
||||
return "aftonbladet.se" in url
|
||||
|
@ -10,10 +10,7 @@ from svtplay_dl.utils import get_http_data, select_quality
|
||||
from svtplay_dl.log import log
|
||||
from svtplay_dl.fetcher.rtmp import download_rtmp
|
||||
|
||||
if sys.version_info > (3, 0):
|
||||
from urllib.parse import quote_plus
|
||||
else:
|
||||
from urllib import quote_plus
|
||||
from svtplay_dl.utils.urllib import quote_plus
|
||||
|
||||
class Expressen(Service):
|
||||
def handle(self, url):
|
||||
|
@ -3,12 +3,9 @@
|
||||
from __future__ import absolute_import
|
||||
import sys
|
||||
import re
|
||||
if sys.version_info > (3, 0):
|
||||
from urllib.parse import urlparse
|
||||
else:
|
||||
from urlparse import urlparse
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
from svtplay_dl.utils.urllib import urlparse
|
||||
from svtplay_dl.service import Service
|
||||
from svtplay_dl.utils import get_http_data, select_quality
|
||||
from svtplay_dl.log import log
|
||||
|
@ -3,12 +3,9 @@
|
||||
from __future__ import absolute_import
|
||||
import sys
|
||||
import re
|
||||
if sys.version_info > (3, 0):
|
||||
from urllib.parse import urlparse
|
||||
else:
|
||||
from urlparse import urlparse
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
from svtplay_dl.utils.urllib import urlparse
|
||||
from svtplay_dl.service import Service
|
||||
from svtplay_dl.utils import get_http_data, select_quality, check_redirect
|
||||
from svtplay_dl.log import log
|
||||
|
@ -5,11 +5,7 @@ import sys
|
||||
import re
|
||||
import json
|
||||
|
||||
if sys.version_info > (3, 0):
|
||||
from http.cookiejar import CookieJar, Cookie
|
||||
else:
|
||||
from cookielib import CookieJar, Cookie
|
||||
|
||||
from svtplay_dl.utils.urllib import CookieJar, Cookie
|
||||
from svtplay_dl.service import Service
|
||||
from svtplay_dl.utils import get_http_data, select_quality, subtitle_json
|
||||
from svtplay_dl.log import log
|
||||
|
@ -2,11 +2,8 @@ from __future__ import absolute_import
|
||||
import sys
|
||||
import re
|
||||
import json
|
||||
if sys.version_info > (3, 0):
|
||||
from urllib.parse import urlparse
|
||||
else:
|
||||
from urlparse import urlparse
|
||||
|
||||
from svtplay_dl.utils.urllib import urlparse
|
||||
from svtplay_dl.service import Service
|
||||
from svtplay_dl.utils import get_http_data
|
||||
|
||||
|
@ -5,17 +5,12 @@ import sys
|
||||
import re
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
from svtplay_dl.utils.urllib import urlparse, parse_qs, unquote_plus
|
||||
from svtplay_dl.service import Service
|
||||
from svtplay_dl.utils import get_http_data
|
||||
from svtplay_dl.log import log
|
||||
from svtplay_dl.fetcher.http import download_http
|
||||
|
||||
if sys.version_info > (3, 0):
|
||||
from urllib.parse import urlparse, parse_qs, unquote_plus
|
||||
else:
|
||||
from urlparse import urlparse, parse_qs
|
||||
from urllib import unquote_plus
|
||||
|
||||
class Sr(Service):
|
||||
def handle(self, url):
|
||||
return "sverigesradio.se" in url
|
||||
|
@ -5,17 +5,13 @@ import sys
|
||||
import re
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
from svtplay_dl.utils.urllib import urlparse, parse_qs
|
||||
from svtplay_dl.service import Service
|
||||
from svtplay_dl.utils import get_http_data, select_quality, subtitle_smi
|
||||
from svtplay_dl.log import log
|
||||
from svtplay_dl.fetcher.rtmp import download_rtmp
|
||||
from svtplay_dl.fetcher.hds import download_hds
|
||||
|
||||
if sys.version_info > (3, 0):
|
||||
from urllib.parse import urlparse, parse_qs
|
||||
else:
|
||||
from urlparse import urlparse, parse_qs
|
||||
|
||||
class Tv4play(Service):
|
||||
def handle(self, url):
|
||||
return ("tv4play.se" in url) or ("tv4.se" in url)
|
||||
|
@ -3,12 +3,9 @@
|
||||
from __future__ import absolute_import
|
||||
import sys
|
||||
import re
|
||||
if sys.version_info > (3, 0):
|
||||
from urllib.parse import urlparse
|
||||
else:
|
||||
from urlparse import urlparse
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
from svtplay_dl.utils.urllib import urlparse
|
||||
from svtplay_dl.service import Service
|
||||
from svtplay_dl.utils import get_http_data, subtitle_sami
|
||||
from svtplay_dl.log import log
|
||||
|
@ -8,15 +8,9 @@ import re
|
||||
import xml.etree.ElementTree as ET
|
||||
import json
|
||||
|
||||
if sys.version_info > (3, 0):
|
||||
from urllib.request import build_opener, HTTPCookieProcessor, HTTPRedirectHandler
|
||||
from urllib.error import HTTPError, URLError
|
||||
from urllib.response import addinfourl
|
||||
from http.cookiejar import CookieJar
|
||||
else:
|
||||
from urllib2 import HTTPError, URLError, build_opener, HTTPCookieProcessor, HTTPRedirectHandler
|
||||
from urllib import addinfourl
|
||||
from cookielib import CookieJar
|
||||
from svtplay_dl.utils.urllib import build_opener, HTTPCookieProcessor, \
|
||||
HTTPRedirectHandler, HTTPError, URLError, \
|
||||
addinfourl, CookieJar
|
||||
|
||||
log = logging.getLogger('svtplay_dl')
|
||||
progress_stream = sys.stderr
|
14
lib/svtplay_dl/utils/io.py
Normal file
14
lib/svtplay_dl/utils/io.py
Normal file
@ -0,0 +1,14 @@
|
||||
# ex:ts=4:sw=4:sts=4:et
|
||||
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
||||
|
||||
# Pylint does not seem to handle conditional imports
|
||||
# pylint: disable=F0401
|
||||
# pylint: disable=W0611
|
||||
|
||||
from __future__ import absolute_import
|
||||
import sys
|
||||
|
||||
if sys.version_info > (3, 0):
|
||||
from io import BytesIO as StringIO
|
||||
else:
|
||||
from StringIO import StringIO
|
24
lib/svtplay_dl/utils/urllib.py
Normal file
24
lib/svtplay_dl/utils/urllib.py
Normal file
@ -0,0 +1,24 @@
|
||||
# ex:ts=4:sw=4:sts=4:et
|
||||
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
||||
|
||||
# Pylint does not seem to handle conditional imports
|
||||
# pylint: disable=F0401
|
||||
# pylint: disable=W0611
|
||||
|
||||
from __future__ import absolute_import
|
||||
import sys
|
||||
|
||||
if sys.version_info > (3, 0):
|
||||
# pylint: disable=E0611
|
||||
from urllib.parse import unquote_plus, quote_plus, urlparse, parse_qs
|
||||
from urllib.request import urlopen, Request, build_opener, \
|
||||
HTTPCookieProcessor, HTTPRedirectHandler
|
||||
from urllib.error import HTTPError, URLError
|
||||
from urllib.response import addinfourl
|
||||
from http.cookiejar import CookieJar, Cookie
|
||||
else:
|
||||
from urllib import addinfourl, unquote_plus, quote_plus
|
||||
from urlparse import urlparse, parse_qs
|
||||
from urllib2 import urlopen, Request, HTTPError, URLError, build_opener, \
|
||||
HTTPCookieProcessor, HTTPRedirectHandler
|
||||
from cookielib import CookieJar, Cookie
|
Loading…
Reference in New Issue
Block a user