1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-12-01 07:34:16 +01:00
svtplay-dl/lib/svtplay_dl/service/vg.py

57 lines
2.2 KiB
Python
Raw Normal View History

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
2014-08-18 22:21:44 +02:00
from svtplay_dl.utils import get_http_data, 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
from svtplay_dl.log import log
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):
2014-12-08 23:07:02 +01:00
error, data = self.get_urldata()
if error:
2014-11-26 16:01:45 +01:00
log.error("Can't get the page")
return
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:
2014-10-06 23:21:43 +02:00
log.error("Can't find video file for: %s", self.url)
return
2014-08-17 10:55:05 +02:00
videoid = match.group(1)
2014-12-08 23:07:02 +01:00
error, data = get_http_data("http://svp.vg.no/svp/api/v1/vgtv/assets/%s?appName=vgtv-website" % videoid)
if error:
log.error("Cant get video info")
return
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):
options.output = "%s/%s" % (directory, title)
else:
options.output = title
2014-08-17 10:55:05 +02:00
if "hds" in jsondata["streamUrls"]:
parse = urlparse(jsondata["streamUrls"]["hds"])
manifest = "%s://%s%s?%s&hdcore=3.3.0" % (parse.scheme, parse.netloc, parse.path, parse.query)
streams = hdsparse(copy.copy(options), manifest)
if streams:
for n in list(streams.keys()):
yield streams[n]
2014-08-17 10:55:05 +02:00
if "hls" in jsondata["streamUrls"]:
streams = hlsparse(jsondata["streamUrls"]["hls"])
for n in list(streams.keys()):
yield HLS(copy.copy(options), streams[n], n)
if "mp4" in jsondata["streamUrls"]:
yield HTTP(copy.copy(options), jsondata["streamUrls"]["mp4"])