2014-12-18 00:08:31 +01:00
|
|
|
# ex:ts=4:sw=4:sts=4:et
|
|
|
|
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
|
|
|
from __future__ import absolute_import
|
|
|
|
import re
|
|
|
|
import json
|
|
|
|
import copy
|
|
|
|
|
|
|
|
from svtplay_dl.service import Service, OpenGraphThumbMixin
|
|
|
|
from svtplay_dl.utils.urllib import unquote_plus
|
|
|
|
from svtplay_dl.fetcher.http import HTTP
|
2015-09-06 14:19:10 +02:00
|
|
|
from svtplay_dl.error import ServiceError
|
2014-12-18 00:08:31 +01:00
|
|
|
|
|
|
|
class Youplay(Service, OpenGraphThumbMixin):
|
|
|
|
supported_domains = ['www.affarsvarlden.se']
|
|
|
|
|
|
|
|
def get(self, options):
|
2015-08-30 00:06:20 +02:00
|
|
|
data = self.get_urldata()
|
2014-12-18 00:08:31 +01:00
|
|
|
|
2014-12-22 17:41:40 +01:00
|
|
|
if self.exclude(options):
|
2015-09-06 23:04:48 +02:00
|
|
|
yield ServiceError("Excluding video")
|
2014-12-22 17:41:40 +01:00
|
|
|
return
|
|
|
|
|
2014-12-18 00:08:31 +01:00
|
|
|
match = re.search(r'script async defer src="(//content.youplay.se[^"]+)"', data)
|
|
|
|
if not match:
|
2015-09-06 14:19:10 +02:00
|
|
|
yield ServiceError("Cant find video info for %s" % self.url)
|
2014-12-18 00:08:31 +01:00
|
|
|
return
|
|
|
|
|
2015-08-31 19:45:15 +02:00
|
|
|
data = self.http.request("get", "http:%s" % match.group(1)).content
|
2014-12-22 10:20:37 +01:00
|
|
|
match = re.search(r'decodeURIComponent\("([^"]+)"\)\)', data)
|
2014-12-18 00:08:31 +01:00
|
|
|
if not match:
|
2015-09-06 14:19:10 +02:00
|
|
|
yield ServiceError("Can't decode video info")
|
2014-12-18 00:08:31 +01:00
|
|
|
return
|
|
|
|
data = unquote_plus(match.group(1))
|
2014-12-22 10:20:37 +01:00
|
|
|
match = re.search(r"videoData = ({[^;]+});", data)
|
2014-12-18 00:08:31 +01:00
|
|
|
if not match:
|
2015-09-06 14:19:10 +02:00
|
|
|
yield ServiceError("Cant find video info for %s" % self.url)
|
2014-12-18 00:08:31 +01:00
|
|
|
return
|
|
|
|
# fix broken json.
|
2014-12-22 10:20:37 +01:00
|
|
|
regex = re.compile(r"\s(\w+):")
|
2014-12-18 00:08:31 +01:00
|
|
|
data = regex.sub(r"'\1':", match.group(1))
|
|
|
|
data = data.replace("'", "\"")
|
|
|
|
j = re.sub(r"{\s*(\w)", r'{"\1', data)
|
2014-12-26 02:04:29 +01:00
|
|
|
j = j.replace("\n", "")
|
2014-12-18 00:08:31 +01:00
|
|
|
j = re.sub(r'",\s*}', '"}', j)
|
2014-12-26 02:04:29 +01:00
|
|
|
jsondata = json.loads(j)
|
2014-12-18 00:08:31 +01:00
|
|
|
for i in jsondata["episode"]["sources"]:
|
|
|
|
match = re.search(r"mp4_(\d+)", i)
|
|
|
|
if match:
|
|
|
|
yield HTTP(copy.copy(options), jsondata["episode"]["sources"][i], match.group(1))
|