2014-08-17 10:55:05 +02:00
|
|
|
from __future__ import absolute_import
|
|
|
|
import re
|
|
|
|
import json
|
|
|
|
import copy
|
2014-08-18 22:21:44 +02:00
|
|
|
import os
|
2014-08-17 10:55:05 +02:00
|
|
|
|
|
|
|
from svtplay_dl.service import Service, OpenGraphThumbMixin
|
2014-12-08 23:07:02 +01:00
|
|
|
from svtplay_dl.utils.urllib import urlparse
|
2015-08-30 00:06:20 +02:00
|
|
|
from svtplay_dl.utils import filenamify
|
2014-08-17 10:55:05 +02:00
|
|
|
from svtplay_dl.fetcher.http import HTTP
|
|
|
|
from svtplay_dl.fetcher.hds import hdsparse
|
|
|
|
from svtplay_dl.fetcher.hls import HLS, hlsparse
|
2015-09-06 14:19:10 +02:00
|
|
|
from svtplay_dl.error import ServiceError
|
2014-08-17 10:55:05 +02:00
|
|
|
|
2015-09-15 20:10:32 +02:00
|
|
|
|
2014-08-17 10:55:05 +02:00
|
|
|
class Vg(Service, OpenGraphThumbMixin):
|
2014-08-18 22:21:44 +02:00
|
|
|
supported_domains = ['vg.no', 'vgtv.no']
|
2014-08-17 10:55:05 +02:00
|
|
|
|
|
|
|
def get(self, options):
|
2015-08-30 00:06:20 +02:00
|
|
|
data = self.get_urldata()
|
2014-12-08 23:07:02 +01:00
|
|
|
match = re.search(r'data-videoid="([^"]+)"', data)
|
2014-08-17 10:55:05 +02:00
|
|
|
if not match:
|
2014-08-18 22:21:44 +02:00
|
|
|
parse = urlparse(self.url)
|
|
|
|
match = re.search(r'video/(\d+)/', parse.fragment)
|
|
|
|
if not match:
|
2015-09-06 14:19:10 +02:00
|
|
|
yield ServiceError("Can't find video file for: %s" % self.url)
|
2014-10-06 23:21:43 +02:00
|
|
|
return
|
2014-08-17 10:55:05 +02:00
|
|
|
videoid = match.group(1)
|
2015-08-31 23:45:28 +02:00
|
|
|
data = self.http.request("get", "http://svp.vg.no/svp/api/v1/vgtv/assets/%s?appName=vgtv-website" % videoid).text
|
2014-08-17 10:55:05 +02:00
|
|
|
jsondata = json.loads(data)
|
|
|
|
|
2014-08-18 22:21:44 +02:00
|
|
|
if options.output_auto:
|
|
|
|
directory = os.path.dirname(options.output)
|
|
|
|
title = "%s" % jsondata["title"]
|
|
|
|
title = filenamify(title)
|
|
|
|
if len(directory):
|
2015-08-24 23:02:18 +02:00
|
|
|
options.output = os.path.join(directory, title)
|
2014-08-18 22:21:44 +02:00
|
|
|
else:
|
|
|
|
options.output = title
|
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-08-17 10:55:05 +02:00
|
|
|
if "hds" in jsondata["streamUrls"]:
|
2015-08-31 19:45:15 +02:00
|
|
|
streams = hdsparse(copy.copy(options), self.http.request("get", jsondata["streamUrls"]["hds"], params={"hdcore": "3.7.0"}).text, jsondata["streamUrls"]["hds"])
|
2014-10-12 23:31:02 +02:00
|
|
|
if streams:
|
|
|
|
for n in list(streams.keys()):
|
|
|
|
yield streams[n]
|
2014-08-17 10:55:05 +02:00
|
|
|
if "hls" in jsondata["streamUrls"]:
|
2015-08-31 23:45:28 +02:00
|
|
|
streams = hlsparse(jsondata["streamUrls"]["hls"], self.http.request("get", jsondata["streamUrls"]["hls"]).text)
|
2014-08-17 10:55:05 +02:00
|
|
|
for n in list(streams.keys()):
|
|
|
|
yield HLS(copy.copy(options), streams[n], n)
|
|
|
|
if "mp4" in jsondata["streamUrls"]:
|
2015-04-28 23:19:35 +02:00
|
|
|
yield HTTP(copy.copy(options), jsondata["streamUrls"]["mp4"])
|