<commit_before># 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 json
import re
import copy

from svtplay_dl.service import Service, OpenGraphThumbMixin
from svtplay_dl.fetcher.http import HTTP
from svtplay_dl.error import ServiceError


class Vimeo(Service, OpenGraphThumbMixin):
    supported_domains = ['vimeo.com']

    def get(self):
        data = self.get_urldata()

        if self.exclude():
            yield ServiceError("Excluding video")
            return

        match_cfg_url = re.search('data-config-url="([^"]+)" data-fallback-url', data)
        match_clip_page_cfg = re.search( r'vimeo\.clip_page_config\s*=\s*({.+?});', data)

        if match_cfg_url:
            player_url = match_cfg_url.group(1).replace("&amp;", "&")

        elif match_clip_page_cfg:
            page_config = json.loads(match_clip_page_cfg.group(1))
            player_url = page_config["player"]["config_url"]

        else:
            yield ServiceError("Can't find video file for: {0}".format(self.url))
            return

        player_data = self.http.request("get", player_url).text

        if player_data:
            jsondata = json.loads(player_data)
            avail_quality = jsondata["request"]["files"]["progressive"]
            for i in avail_quality:
                yield HTTP(copy.copy(self.options), i["url"], i["height"])<commit_msg>Add support for hls fetching from vimeo<commit_after># 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 json
import re
import copy

from svtplay_dl.service import Service, OpenGraphThumbMixin
from svtplay_dl.fetcher.http import HTTP
from svtplay_dl.error import ServiceError

from svtplay_dl.fetcher.hls import hlsparse


class Vimeo(Service, OpenGraphThumbMixin):
    supported_domains = ['vimeo.com']

    def get(self):
        data = self.get_urldata()

        if self.exclude():
            yield ServiceError("Excluding video")
            return

        match_cfg_url = re.search('data-config-url="([^"]+)" data-fallback-url', data)
        match_clip_page_cfg = re.search( r'vimeo\.clip_page_config\s*=\s*({.+?});', data)

        if match_cfg_url:
            player_url = match_cfg_url.group(1).replace("&amp;", "&")

        elif match_clip_page_cfg:
            page_config = json.loads(match_clip_page_cfg.group(1))
            player_url = page_config["player"]["config_url"]

        else:
            yield ServiceError("Can't find video file for: {0}".format(self.url))
            return

        player_data = self.http.request("get", player_url).text

        if player_data:

            jsondata = json.loads(player_data)

            if ("hls" in jsondata["request"]["files"]) and ("fastly_skyfire" in jsondata["request"]["files"]["hls"]["cdns"]):
                hls_elem = jsondata["request"]["files"]["hls"]["cdns"]["fastly_skyfire"]
                stream = hlsparse(self.options, self.http.request("get", hls_elem["url"]), hls_elem["url"])

                if stream:
                    for n in list(stream.keys()):
                        yield stream[n]

            avail_quality = jsondata["request"]["files"]["progressive"]
            for i in avail_quality:
                yield HTTP(copy.copy(self.options), i["url"], i["height"])

{'fraction_non_alphanumeric': 0.13780918727915195, 'fraction_numerical': 0.004711425206124852, 'mean_word_length': 2.81685393258427, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2623420', 'n_tokens_mistral': 1100, 'n_tokens_neox': 1091, 'n_words': 212}