<commit_before># ex:ts=4:sw=4:sts=4:et
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-

# pylint has issues with urlparse: "some types could not be inferred"
# pylint: disable=E1103

from __future__ import absolute_import
import sys
import re
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
from svtplay_dl.fetcher.rtmp import download_rtmp

class Viaplay(Service):
    def handle(self, url):
        return ("tv3play.se" in url) or ("tv6play.se" in url) or ("tv8play.se" in url) or ("tv10play.se" in url)

    def get(self, options, url):
        parse = urlparse(url)
        match = re.search(r'\/play\/(\d+)/?', parse.path)
        if not match:
            log.error("Cant find video file")
            sys.exit(2)
        url = "http://viastream.viasat.tv/PlayProduct/%s" % match.group(1)
        options.other = ""
        data = get_http_data(url)
        xml = ET.XML(data)
        live = xml.find("Product").find("LiveInfo")
        if live is not None:
            live = live.find("Live").text
            if live == "true":
                options.live = True

        filename = xml.find("Product").find("Videos").find("Video").find("Url").text
        subtitle = xml.find("Product").find("SamiFile").text

        if filename[:4] == "http":
            data = get_http_data(filename)
            xml = ET.XML(data)
            filename = xml.find("Url").text

        parse = urlparse(filename)
        match = re.search("^(/[a-z0-9]{0,5})/(.*)", parse.path)
        if not match:
            log.error("Somthing wrong with rtmpparse")
            sys.exit(2)
        filename = "%s://%s%s" % (parse.scheme, parse.hostname, match.group(1))
        path = "-y %s" % match.group(2)
        options.other = "-W http://flvplayer.viastream.viasat.tv/flvplayer/play/swf/player.swf %s" % path
        download_rtmp(options, filename)
        if options.subtitle and subtitle:
            if options.output != "-":
                data = get_http_data(subtitle)
                subtitle_sami(options, data)
<commit_msg>viaplay: they use longer first dirname nowdays<commit_after># ex:ts=4:sw=4:sts=4:et
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-

# pylint has issues with urlparse: "some types could not be inferred"
# pylint: disable=E1103

from __future__ import absolute_import
import sys
import re
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
from svtplay_dl.fetcher.rtmp import download_rtmp

class Viaplay(Service):
    def handle(self, url):
        return ("tv3play.se" in url) or ("tv6play.se" in url) or ("tv8play.se" in url) or ("tv10play.se" in url)

    def get(self, options, url):
        parse = urlparse(url)
        match = re.search(r'\/play\/(\d+)/?', parse.path)
        if not match:
            log.error("Cant find video file")
            sys.exit(2)
        url = "http://viastream.viasat.tv/PlayProduct/%s" % match.group(1)
        options.other = ""
        data = get_http_data(url)
        xml = ET.XML(data)
        live = xml.find("Product").find("LiveInfo")
        if live is not None:
            live = live.find("Live").text
            if live == "true":
                options.live = True

        filename = xml.find("Product").find("Videos").find("Video").find("Url").text
        subtitle = xml.find("Product").find("SamiFile").text

        if filename[:4] == "http":
            data = get_http_data(filename)
            xml = ET.XML(data)
            filename = xml.find("Url").text

        parse = urlparse(filename)
        match = re.search("^(/[a-z0-9]{0,20})/(.*)", parse.path)
        if not match:
            log.error("Somthing wrong with rtmpparse")
            sys.exit(2)
        filename = "%s://%s%s" % (parse.scheme, parse.hostname, match.group(1))
        path = "-y %s" % match.group(2)
        options.other = "-W http://flvplayer.viastream.viasat.tv/flvplayer/play/swf/player.swf %s" % path
        download_rtmp(options, filename)
        if options.subtitle and subtitle:
            if options.output != "-":
                data = get_http_data(subtitle)
                subtitle_sami(options, data)

{'fraction_non_alphanumeric': 0.14205312922107158, 'fraction_numerical': 0.011031067086897793, 'mean_word_length': 2.4522144522144522, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 14}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2866449', 'n_tokens_mistral': 1485, 'n_tokens_neox': 1448, 'n_words': 338}