1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-30 15:14:14 +01:00

remove a bunch of is_py. time for py3.

This commit is contained in:
Johan Andersson 2018-01-13 20:27:40 +01:00
parent bdf33167d3
commit b8c1163852
20 changed files with 40 additions and 152 deletions

View File

@ -11,7 +11,7 @@ from optparse import OptionParser
from svtplay_dl.error import UIException from svtplay_dl.error import UIException
from svtplay_dl.log import log from svtplay_dl.log import log
from svtplay_dl.utils import select_quality, list_quality, is_py2, ensure_unicode from svtplay_dl.utils import select_quality, list_quality, ensure_unicode
from svtplay_dl.service import service_handler, Generic from svtplay_dl.service import service_handler, Generic
from svtplay_dl.fetcher import VideoRetriever from svtplay_dl.fetcher import VideoRetriever
from svtplay_dl.subtitle import subtitle from svtplay_dl.subtitle import subtitle
@ -210,9 +210,6 @@ def get_media(url, options):
log.error("That site is not supported. Make a ticket or send a message") log.error("That site is not supported. Make a ticket or send a message")
sys.exit(2) sys.exit(2)
if is_py2:
url = ensure_unicode(url)
if options.all_episodes: if options.all_episodes:
get_all_episodes(stream, copy.copy(options), url) get_all_episodes(stream, copy.copy(options), url)
else: else:

View File

@ -9,7 +9,6 @@ import copy
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
from svtplay_dl.output import progressbar, progress_stream, ETA, output from svtplay_dl.output import progressbar, progress_stream, ETA, output
from svtplay_dl.utils import is_py2_old, is_py2
from svtplay_dl.utils.urllib import urlparse from svtplay_dl.utils.urllib import urlparse
from svtplay_dl.error import UIException from svtplay_dl.error import UIException
from svtplay_dl.fetcher import VideoRetriever from svtplay_dl.fetcher import VideoRetriever
@ -17,17 +16,9 @@ from svtplay_dl.error import ServiceError
log = logging.getLogger('svtplay_dl') log = logging.getLogger('svtplay_dl')
if is_py2:
def bytes(string=None, encoding="ascii"):
if string is None:
return ""
return string
def _chr(temp): def _chr(temp):
return temp return chr(temp)
else:
def _chr(temp):
return chr(temp)
class HDSException(UIException): class HDSException(UIException):
@ -53,17 +44,11 @@ def hdsparse(options, res, manifest):
streams[0] = ServiceError("Can't read HDS playlist. {0}".format(res.status_code)) streams[0] = ServiceError("Can't read HDS playlist. {0}".format(res.status_code))
return streams return streams
data = res.text data = res.text
if is_py2 and isinstance(data, unicode):
data = data.encode("utf-8")
xml = ET.XML(data) xml = ET.XML(data)
if is_py2_old: bootstrapIter = xml.iter("{http://ns.adobe.com/f4m/1.0}bootstrapInfo")
bootstrapIter = xml.getiterator("{http://ns.adobe.com/f4m/1.0}bootstrapInfo") mediaIter = xml.iter("{http://ns.adobe.com/f4m/1.0}media")
mediaIter = xml.getiterator("{http://ns.adobe.com/f4m/1.0}media")
else:
bootstrapIter = xml.iter("{http://ns.adobe.com/f4m/1.0}bootstrapInfo")
mediaIter = xml.iter("{http://ns.adobe.com/f4m/1.0}media")
if xml.find("{http://ns.adobe.com/f4m/1.0}drmAdditionalHeader") is not None: if xml.find("{http://ns.adobe.com/f4m/1.0}drmAdditionalHeader") is not None:
streams[0] = ServiceError("HDS DRM protected content.") streams[0] = ServiceError("HDS DRM protected content.")

View File

@ -5,7 +5,6 @@ import subprocess
import shlex import shlex
from svtplay_dl.log import log from svtplay_dl.log import log
from svtplay_dl.utils import is_py2
from svtplay_dl.fetcher import VideoRetriever from svtplay_dl.fetcher import VideoRetriever
from svtplay_dl.output import output from svtplay_dl.output import output
@ -30,10 +29,7 @@ class RTMP(VideoRetriever):
if self.options.silent: if self.options.silent:
args.append("-q") args.append("-q")
if self.options.other: if self.options.other:
if is_py2: args += shlex.split(self.options.other)
args += shlex.split(self.options.other.encode("utf-8"))
else:
args += shlex.split(self.options.other)
if self.options.verbose: if self.options.verbose:
args.append("-V") args.append("-V")

View File

@ -5,10 +5,9 @@ import sys
import time import time
import re import re
import os import os
import platform
from datetime import timedelta from datetime import timedelta
from svtplay_dl.utils import is_py2, filenamify, decode_html_entities, ensure_unicode from svtplay_dl.utils import filenamify, decode_html_entities, ensure_unicode
from svtplay_dl.utils.terminal import get_terminal_size from svtplay_dl.utils.terminal import get_terminal_size
from svtplay_dl.log import log from svtplay_dl.log import log
@ -117,12 +116,6 @@ def progressbar(total, pos, msg=""):
def filename(stream): def filename(stream):
if stream.options.output:
if is_py2:
if platform.system() == "Windows":
stream.options.output = stream.options.output.decode("latin1")
else:
stream.options.output = stream.options.output.decode("utf-8")
if not stream.options.output or os.path.isdir(stream.options.output): if not stream.options.output or os.path.isdir(stream.options.output):
data = ensure_unicode(stream.get_urldata()) data = ensure_unicode(stream.get_urldata())
if data is None: if data is None:

View File

@ -6,7 +6,7 @@ import re
from requests import post, codes, Timeout from requests import post, codes, Timeout
from svtplay_dl.log import log from svtplay_dl.log import log
from svtplay_dl.utils import which, is_py3, run_program from svtplay_dl.utils import which, run_program
class postprocess(object): class postprocess(object):
@ -31,7 +31,7 @@ class postprocess(object):
txt = '\r\n'.join(lines[2:]) txt = '\r\n'.join(lines[2:])
return txt return txt
if platform.system() == "Windows" and is_py3: if platform.system() == "Windows":
fd = open(self, encoding="utf8") fd = open(self, encoding="utf8")
else: else:
fd = open(self) fd = open(self)

View File

@ -3,7 +3,7 @@
from __future__ import absolute_import from __future__ import absolute_import
import re import re
from svtplay_dl.utils.urllib import urlparse from svtplay_dl.utils.urllib import urlparse
from svtplay_dl.utils import download_thumbnail, is_py2, HTTP from svtplay_dl.utils import download_thumbnail, HTTP
import logging import logging
@ -58,8 +58,6 @@ class Service(object):
def exclude(self): def exclude(self):
if self.options.exclude: if self.options.exclude:
for i in self.options.exclude: for i in self.options.exclude:
if is_py2:
i = i.decode("utf-8")
if i in self.options.output: if i in self.options.output:
return True return True
return False return False
@ -67,8 +65,6 @@ class Service(object):
def exclude2(self, filename): def exclude2(self, filename):
if self.options.exclude: if self.options.exclude:
for i in self.options.exclude: for i in self.options.exclude:
if is_py2:
i = i.decode("utf-8")
if i in filename: if i in filename:
return True return True
return False return False

View File

@ -8,10 +8,9 @@ import random
from svtplay_dl.service import Service from svtplay_dl.service import Service
from svtplay_dl.fetcher.hls import hlsparse from svtplay_dl.fetcher.hls import hlsparse
from svtplay_dl.subtitle import subtitle
from svtplay_dl.utils.urllib import urlparse from svtplay_dl.utils.urllib import urlparse
from svtplay_dl.error import ServiceError from svtplay_dl.error import ServiceError
from svtplay_dl.utils import filenamify, is_py2 from svtplay_dl.utils import filenamify
from svtplay_dl.log import log from svtplay_dl.log import log
@ -104,12 +103,7 @@ class Dplay(Service):
season = jsondata["data"]["attributes"]["seasonNumber"] season = jsondata["data"]["attributes"]["seasonNumber"]
episode = jsondata["data"]["attributes"]["episodeNumber"] episode = jsondata["data"]["attributes"]["episodeNumber"]
name = jsondata["data"]["attributes"]["name"] name = jsondata["data"]["attributes"]["name"]
if is_py2: show = filenamify(show)
show = filenamify(show).encode("latin1")
name = filenamify(name).encode("latin1")
else:
show = filenamify(show)
return filenamify("{0}.s{1:02d}e{2:02d}.{3}".format(show, int(season), int(episode), name)) return filenamify("{0}.s{1:02d}e{2:02d}.{3}".format(show, int(season), int(episode), name))
def find_all_episodes(self, options): def find_all_episodes(self, options):

View File

@ -13,7 +13,7 @@ from svtplay_dl.fetcher.hds import hdsparse
from svtplay_dl.subtitle import subtitle from svtplay_dl.subtitle import subtitle
from svtplay_dl.error import ServiceError from svtplay_dl.error import ServiceError
from svtplay_dl.utils.urllib import urlparse, urljoin from svtplay_dl.utils.urllib import urlparse, urljoin
from svtplay_dl.utils import is_py3
class Dr(Service, OpenGraphThumbMixin): class Dr(Service, OpenGraphThumbMixin):
@ -80,27 +80,24 @@ class Dr(Service, OpenGraphThumbMixin):
newstyle = '_' in encpath newstyle = '_' in encpath
if newstyle: if newstyle:
encbasepath = encpath.split('_')[0] encbasepath = encpath.split('_')[0]
path = base64.b64decode(encbasepath + '===').decode('latin1') if is_py3 else base64.b64decode(encbasepath + '===') path = base64.b64decode(encbasepath + '===').decode('latin1')
else: else:
path = base64.b64decode(encpath + '===').decode('latin1') if is_py3 else base64.b64decode(encpath + '===') path = base64.b64decode(encpath + '===').decode('latin1')
if '/view/' in path: if '/view/' in path:
continue continue
params = 'offset=0&limit=1000' params = 'offset=0&limit=1000'
if newstyle: if newstyle:
encparams = base64.b64encode(params.encode('latin1')).decode('latin1').rstrip('=') if is_py3 else \ encparams = base64.b64encode(params.encode('latin1')).decode('latin1').rstrip('=')
base64.b64encode(params).rstrip('=')
encpath = '{0}_{1}'.format(encbasepath, encparams) encpath = '{0}_{1}'.format(encbasepath, encparams)
else: else:
path = '{0}?{1}'.format(urlparse(path).path, params) path = '{0}?{1}'.format(urlparse(path).path, params)
encpath = base64.b64encode(path.encode('latin1')).decode('latin1').rstrip('=') if is_py3 else \ encpath = base64.b64encode(path.encode('latin1')).decode('latin1').rstrip('=')
base64.b64encode(path).rstrip('=')
url = urljoin('https://www.dr.dk/tv/partial/', url = urljoin('https://www.dr.dk/tv/partial/',
'{0}/{1}'.format(enccomp, encpath)) '{0}/{1}'.format(enccomp, encpath))
data = self.http.request('get', url).content.decode('latin1') if is_py3 else \ data = self.http.request('get', url).content.decode('latin1')
self.http.request('get', url).content
matches = re.findall(r'"program-link" href="([^"]+)">', data) matches = re.findall(r'"program-link" href="([^"]+)">', data)
episodes = [urljoin('https://www.dr.dk/', url) for url in matches] episodes = [urljoin('https://www.dr.dk/', url) for url in matches]

View File

@ -7,7 +7,6 @@ import xml.etree.ElementTree as ET
from svtplay_dl.utils.urllib import urlparse from svtplay_dl.utils.urllib import urlparse
from svtplay_dl.service import Service from svtplay_dl.service import Service
from svtplay_dl.utils import is_py2_old
from svtplay_dl.log import log from svtplay_dl.log import log
from svtplay_dl.fetcher.rtmp import RTMP from svtplay_dl.fetcher.rtmp import RTMP
from svtplay_dl.error import ServiceError from svtplay_dl.error import ServiceError
@ -40,10 +39,7 @@ class Hbo(Service):
data = self.http.request("get", url).content data = self.http.request("get", url).content
xml = ET.XML(data) xml = ET.XML(data)
ss = xml.find("videos") ss = xml.find("videos")
if is_py2_old: sa = list(ss.iter("size"))
sa = list(ss.getiterator("size"))
else:
sa = list(ss.iter("size"))
for i in sa: for i in sa:
videourl = i.find("tv14").find("path").text videourl = i.find("tv14").find("path").text

View File

@ -5,7 +5,6 @@ import json
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
from svtplay_dl.service import Service, OpenGraphThumbMixin from svtplay_dl.service import Service, OpenGraphThumbMixin
from svtplay_dl.utils import is_py2_old
from svtplay_dl.error import ServiceError from svtplay_dl.error import ServiceError
from svtplay_dl.log import log from svtplay_dl.log import log
from svtplay_dl.fetcher.rtmp import RTMP from svtplay_dl.fetcher.rtmp import RTMP
@ -88,10 +87,7 @@ class Mtvnn(Service, OpenGraphThumbMixin):
content = self.http.request("get", contenturl).content content = self.http.request("get", contenturl).content
xml = ET.XML(content) xml = ET.XML(content)
ss = xml.find("video").find("item") ss = xml.find("video").find("item")
if is_py2_old: sa = list(ss.iter("rendition"))
sa = list(ss.getiterator("rendition"))
else:
sa = list(ss.iter("rendition"))
for i in sa: for i in sa:
yield RTMP(self.options, i.find("src").text, i.attrib["bitrate"]) yield RTMP(self.options, i.find("src").text, i.attrib["bitrate"])

View File

@ -6,7 +6,6 @@ import copy
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
from svtplay_dl.service import Service from svtplay_dl.service import Service
from svtplay_dl.utils import is_py2_old
from svtplay_dl.fetcher.http import HTTP from svtplay_dl.fetcher.http import HTTP
from svtplay_dl.error import ServiceError from svtplay_dl.error import ServiceError
@ -27,10 +26,7 @@ class Mtvservices(Service):
data = data[start:] data = data[start:]
xml = ET.XML(data) xml = ET.XML(data)
ss = xml.find("video").find("item") ss = xml.find("video").find("item")
if is_py2_old: sa = list(ss.iter("rendition"))
sa = list(ss.getiterator("rendition"))
else:
sa = list(ss.iter("rendition"))
if self.exclude(): if self.exclude():
yield ServiceError("Excluding video") yield ServiceError("Excluding video")

View File

@ -11,7 +11,7 @@ from svtplay_dl.log import log
from svtplay_dl.fetcher.hds import hdsparse from svtplay_dl.fetcher.hds import hdsparse
from svtplay_dl.fetcher.hls import hlsparse from svtplay_dl.fetcher.hls import hlsparse
from svtplay_dl.fetcher.dash import dashparse from svtplay_dl.fetcher.dash import dashparse
from svtplay_dl.utils import ensure_unicode, filenamify, is_py2, decode_html_entities from svtplay_dl.utils import ensure_unicode, filenamify, decode_html_entities
from svtplay_dl.subtitle import subtitle from svtplay_dl.subtitle import subtitle
from svtplay_dl.utils.urllib import urlparse, parse_qs from svtplay_dl.utils.urllib import urlparse, parse_qs
@ -140,10 +140,7 @@ class OppetArkiv(Service, OpenGraphThumbMixin):
def outputfilename(self, data, filename, raw): def outputfilename(self, data, filename, raw):
directory = os.path.dirname(filename) directory = os.path.dirname(filename)
if is_py2: id = hashlib.sha256(data["programVersionId"].encode("utf-8")).hexdigest()[:7]
id = hashlib.sha256(data["programVersionId"]).hexdigest()[:7]
else:
id = hashlib.sha256(data["programVersionId"].encode("utf-8")).hexdigest()[:7]
datatitle = re.search('data-title="([^"]+)"', self.get_urldata()) datatitle = re.search('data-title="([^"]+)"', self.get_urldata())
if not datatitle: if not datatitle:
@ -151,8 +148,7 @@ class OppetArkiv(Service, OpenGraphThumbMixin):
datat = decode_html_entities(datatitle.group(1)) datat = decode_html_entities(datatitle.group(1))
name = self.name(datat) name = self.name(datat)
episode = self.seasoninfo(datat) episode = self.seasoninfo(datat)
if is_py2:
name = name.encode("utf8")
if episode: if episode:
title = "{0}.{1}-{2}-svtplay".format(name, episode, id) title = "{0}.{1}-{2}-svtplay".format(name, episode, id)
else: else:

View File

@ -6,7 +6,6 @@ import copy
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
from svtplay_dl.service import Service, OpenGraphThumbMixin from svtplay_dl.service import Service, OpenGraphThumbMixin
from svtplay_dl.utils import is_py2_old
from svtplay_dl.error import ServiceError from svtplay_dl.error import ServiceError
from svtplay_dl.fetcher.rtmp import RTMP from svtplay_dl.fetcher.rtmp import RTMP
@ -50,10 +49,7 @@ class Qbrick(Service, OpenGraphThumbMixin):
xml = ET.XML(data) xml = ET.XML(data)
server = xml.find("head").find("meta").attrib["base"] server = xml.find("head").find("meta").attrib["base"]
streams = xml.find("body").find("switch") streams = xml.find("body").find("switch")
if is_py2_old: sa = list(streams.iter("video"))
sa = list(streams.getiterator("video"))
else:
sa = list(streams.iter("video"))
for i in sa: for i in sa:
self.options.other = "-y '{0}'".format(i.attrib["src"]) self.options.other = "-y '{0}'".format(i.attrib["src"])

View File

@ -8,7 +8,6 @@ from svtplay_dl.service import Service
from svtplay_dl.fetcher.hls import hlsparse from svtplay_dl.fetcher.hls import hlsparse
from svtplay_dl.error import ServiceError from svtplay_dl.error import ServiceError
from svtplay_dl.utils.urllib import urlparse from svtplay_dl.utils.urllib import urlparse
from svtplay_dl.utils import is_py2
class Solidtango(Service): class Solidtango(Service):
@ -55,8 +54,6 @@ class Solidtango(Service):
yield ServiceError("Can't find video info. if there is a video on the page. its a bug.") yield ServiceError("Can't find video info. if there is a video on the page. its a bug.")
return return
xmldoc = data.text xmldoc = data.text
if is_py2 and isinstance(xmldoc, unicode):
xmldoc = xmldoc.encode("utf8")
xml = ET.XML(xmldoc) xml = ET.XML(xmldoc)
elements = xml.findall(".//manifest") elements = xml.findall(".//manifest")
streams = hlsparse(self.options, self.http.request("get", elements[0].text), elements[0].text) streams = hlsparse(self.options, self.http.request("get", elements[0].text), elements[0].text)

View File

@ -10,7 +10,7 @@ from operator import itemgetter
from svtplay_dl.log import log from svtplay_dl.log import log
from svtplay_dl.service import Service, OpenGraphThumbMixin from svtplay_dl.service import Service, OpenGraphThumbMixin
from svtplay_dl.utils import filenamify, is_py2 from svtplay_dl.utils import filenamify
from svtplay_dl.utils.urllib import urlparse, urljoin, parse_qs from svtplay_dl.utils.urllib import urlparse, urljoin, parse_qs
from svtplay_dl.fetcher.hds import hdsparse from svtplay_dl.fetcher.hds import hdsparse
from svtplay_dl.fetcher.hls import hlsparse from svtplay_dl.fetcher.hls import hlsparse
@ -249,10 +249,7 @@ class Svtplay(Service, OpenGraphThumbMixin):
vid = str(data["programVersionId"]) vid = str(data["programVersionId"])
else: else:
vid = str(data["id"]) vid = str(data["id"])
if is_py2: id = hashlib.sha256(vid.encode("utf-8")).hexdigest()[:7]
id = hashlib.sha256(vid).hexdigest()[:7]
else:
id = hashlib.sha256(vid.encode("utf-8")).hexdigest()[:7]
if name == other: if name == other:
other = None other = None

View File

@ -10,7 +10,7 @@ from datetime import datetime, timedelta
from svtplay_dl.utils.urllib import urlparse, parse_qs, quote_plus from svtplay_dl.utils.urllib import urlparse, parse_qs, quote_plus
from svtplay_dl.service import Service, OpenGraphThumbMixin from svtplay_dl.service import Service, OpenGraphThumbMixin
from svtplay_dl.utils import is_py2_old, is_py2, filenamify from svtplay_dl.utils import filenamify
from svtplay_dl.fetcher.hls import hlsparse from svtplay_dl.fetcher.hls import hlsparse
from svtplay_dl.fetcher.rtmp import RTMP from svtplay_dl.fetcher.rtmp import RTMP
from svtplay_dl.fetcher.hds import hdsparse from svtplay_dl.fetcher.hds import hdsparse
@ -65,10 +65,7 @@ class Tv4play(Service, OpenGraphThumbMixin):
return return
xml = ET.XML(data.content) xml = ET.XML(data.content)
ss = xml.find("items") ss = xml.find("items")
if is_py2_old: sa = list(ss.iter("item"))
sa = list(ss.getiterator("item"))
else:
sa = list(ss.iter("item"))
if xml.find("live").text: if xml.find("live").text:
self.options.live = (xml.find("live").text != "false") self.options.live = (xml.find("live").text != "false")
@ -118,10 +115,7 @@ class Tv4play(Service, OpenGraphThumbMixin):
data = self.http.request("get", url, cookies=self.cookies).content data = self.http.request("get", url, cookies=self.cookies).content
xml = ET.XML(data) xml = ET.XML(data)
ss = xml.find("items") ss = xml.find("items")
if is_py2_old: sa = list(ss.iter("item"))
sa = list(ss.getiterator("item"))
else:
sa = list(ss.iter("item"))
for i in sa: for i in sa:
if i.find("mediaFormat").text == "mp4": if i.find("mediaFormat").text == "mp4":
parse = urlparse(i.find("url").text) parse = urlparse(i.find("url").text)
@ -173,8 +167,6 @@ class Tv4play(Service, OpenGraphThumbMixin):
else: else:
show = parse.path[parse.path.find("/", 1) + 1:] show = parse.path[parse.path.find("/", 1) + 1:]
if show and not re.search("%", show): if show and not re.search("%", show):
if is_py2 and isinstance(show, unicode):
show = show.encode("utf-8")
show = quote_plus(show) show = quote_plus(show)
return show return show

View File

@ -2,7 +2,7 @@ import xml.etree.ElementTree as ET
import json import json
import re import re
from svtplay_dl.log import log from svtplay_dl.log import log
from svtplay_dl.utils import is_py2, is_py3, decode_html_entities, HTTP from svtplay_dl.utils import decode_html_entities, HTTP
from svtplay_dl.utils.io import StringIO from svtplay_dl.utils.io import StringIO
from svtplay_dl.output import output from svtplay_dl.output import output
from requests import __build__ as requests_version from requests import __build__ as requests_version
@ -58,7 +58,7 @@ class subtitle(object):
self.save_file(data, "srt") self.save_file(data, "srt")
def save_file(self, data, subtype): def save_file(self, data, subtype):
if platform.system() == "Windows" and is_py3: if platform.system() == "Windows":
file_d = output(self.options, subtype, mode="wt", encoding="utf-8") file_d = output(self.options, subtype, mode="wt", encoding="utf-8")
else: else:
file_d = output(self.options, subtype, mode="wt") file_d = output(self.options, subtype, mode="wt")
@ -68,19 +68,12 @@ class subtitle(object):
file_d.close() file_d.close()
def raw(self, subdata): def raw(self, subdata):
if is_py2: return subdata.text
data = subdata.text.encode("utf-8")
else:
data = subdata.text
return data
def tt(self, subdata): def tt(self, subdata):
i = 1 i = 1
data = "" data = ""
if is_py2: subs = subdata.text
subs = subdata.text.encode("utf8")
else:
subs = subdata.text
subdata = re.sub(' xmlns="[^"]+"', '', subs, count=1) subdata = re.sub(' xmlns="[^"]+"', '', subs, count=1)
tree = ET.XML(subdata) tree = ET.XML(subdata)
@ -108,8 +101,7 @@ class subtitle(object):
data = tt_text(node, data) data = tt_text(node, data)
data += "\n" data += "\n"
i += 1 i += 1
if is_py2:
data = data.encode("utf8")
return data return data
def json(self, subdata): def json(self, subdata):
@ -118,18 +110,13 @@ class subtitle(object):
subs = "" subs = ""
for i in data: for i in data:
subs += "%s\n%s --> %s\n" % (number, timestr(int(i["startMillis"])), timestr(int(i["endMillis"]))) subs += "%s\n%s --> %s\n" % (number, timestr(int(i["startMillis"])), timestr(int(i["endMillis"])))
if is_py2: subs += "%s\n\n" % i["text"]
subs += "%s\n\n" % i["text"].encode("utf-8")
else:
subs += "%s\n\n" % i["text"]
number += 1 number += 1
return subs return subs
def sami(self, subdata): def sami(self, subdata):
text = subdata.text text = subdata.text
if is_py2:
text = text.encode("utf8")
text = re.sub(r'&', '&', text) text = re.sub(r'&', '&', text)
tree = ET.fromstring(text) tree = ET.fromstring(text)
subt = tree.find("Font") subt = tree.find("Font")
@ -147,17 +134,12 @@ class subtitle(object):
if int(n) > 0 and i.text: if int(n) > 0 and i.text:
subs += "%s\n" % decode_html_entities(i.text) subs += "%s\n" % decode_html_entities(i.text)
if is_py2:
subs = subs.encode('utf8')
subs = re.sub('&', r'&', subs) subs = re.sub('&', r'&', subs)
return subs return subs
def smi(self, subdata): def smi(self, subdata):
if requests_version < 0x20300: if requests_version < 0x20300:
if is_py2: subdata = subdata.content.decode("latin")
subdata = subdata.content
else:
subdata = subdata.content.decode("latin")
else: else:
subdata.encoding = "ISO-8859-1" subdata.encoding = "ISO-8859-1"
subdata = subdata.text subdata = subdata.text
@ -187,8 +169,6 @@ class subtitle(object):
data = text.group(1) data = text.group(1)
recomp = re.compile(r'\r') recomp = re.compile(r'\r')
text = bad_char.sub('-', recomp.sub('', subs)) text = bad_char.sub('-', recomp.sub('', subs))
if is_py2 and isinstance(text, unicode):
return text.encode("utf-8")
return text return text
def wrst(self, subdata): def wrst(self, subdata):
@ -258,8 +238,6 @@ class subtitle(object):
srt += sub.strip() srt += sub.strip()
srt += "\n" srt += "\n"
srt = decode_html_entities(srt) srt = decode_html_entities(srt)
if is_py2:
return srt.encode("utf-8")
return srt return srt

View File

@ -21,10 +21,6 @@ from requests.packages.urllib3.util.retry import Retry
from svtplay_dl import error from svtplay_dl import error
is_py2 = (sys.version_info[0] == 2)
is_py3 = (sys.version_info[0] == 3)
is_py2_old = (sys.version_info < (2, 7))
# Used for UA spoofing in get_http_data() # Used for UA spoofing in get_http_data()
FIREFOX_UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.3' FIREFOX_UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.3'
@ -192,7 +188,7 @@ def ensure_unicode(s):
Ensure string is a unicode string. If it isn't it assumed it is Ensure string is a unicode string. If it isn't it assumed it is
utf-8 and decodes it to a unicode string. utf-8 and decodes it to a unicode string.
""" """
if (is_py2 and isinstance(s, str)) or (is_py3 and isinstance(s, bytes)): if isinstance(s, bytes):
s = s.decode('utf-8', 'replace') s = s.decode('utf-8', 'replace')
return s return s

View File

@ -7,9 +7,4 @@
# pylint: disable=E0611 # pylint: disable=E0611
from __future__ import absolute_import from __future__ import absolute_import
from svtplay_dl.utils import is_py2 from io import StringIO
if is_py2:
from StringIO import StringIO
else:
from io import StringIO

View File

@ -10,9 +10,4 @@
# pylint: disable=import-error # pylint: disable=import-error
from __future__ import absolute_import from __future__ import absolute_import
from svtplay_dl.utils import is_py2 from urllib.parse import quote, unquote_plus, quote_plus, urlparse, parse_qs, urljoin
if is_py2:
from urllib import quote, unquote_plus, quote_plus
from urlparse import urlparse, parse_qs, urljoin
else:
from urllib.parse import quote, unquote_plus, quote_plus, urlparse, parse_qs, urljoin