<commit_before><?php

/**
 * @author <NAME> <<EMAIL>>
 * @version 0.4a
 * @copyright 2015 <NAME>
 * @license http://opensource.org/licenses/MIT Licensed under MIT License
 */

require_once 'provider.php';

class SynoFileHostingZdfMediathek extends TheiNaDProvider {

    static $QualityPriority = array(
        'veryhigh'  => 2,
        'high'      => 1,
        'low'       => 0,
    );

    static $UnsupportedFacets = array(
        'hbbtv',
    );

    protected $LogPath = '/tmp/zdf-mediathek.log';

    //This function gets the download url
    public function GetDownloadInfo() {

        $this->DebugLog("Getting download url for $this->Url");

        if(strpos($this->Url, 'zdf.de') !== false)
        {
            return $this->zdf();
        }

        if(strpos($this->Url, '3sat.de') !== false)
        {
            return $this->dreisat();
        }

        return FALSE;
    }

    private function dreisat()
    {
        if(preg_match('#mediathek\/(?:.*)obj=(\d+)#i', $this->Url, $match) === 1)
        {
            $id = $match[1];

            $this->DebugLog("ID is $id");

            $this->DebugLog("Getting XML data from http://www.3sat.de/mediathek/xmlservice/web/beitragsDetails?ak=web&id=$id&ak=web");

            $RawXML = $this->curlRequest('http://www.3sat.de/mediathek/xmlservice/web/beitragsDetails?ak=web&id=' . $id . '&ak=web');

            if($RawXML === null)
            {
                return false;
            }

            $this->DebugLog("Processing XML data");

            return $this->processXML($RawXML);
        }

        $this->DebugLog("Couldn't identify id");

        return FALSE;
    }

    private function zdf()
    {
        if(preg_match('#beitrag/video/([0-9]+)#i', $this->Url, $match) === 1)
        {
            $id = $match[1];

            $this->DebugLog("ID is $id");

            $this->DebugLog("Getting XML data from http://zdf.de/ZDFmediathek/xmlservice/web/beitragsDetails?id=$id&ak=web");

            $RawXML = $this->curlRequest('http://zdf.de/ZDFmediathek/xmlservice/web/beitragsDetails?id=' . $id . '&ak=web');

            if($RawXML === null)
            {
                return false;
            }

            $this->DebugLog("Processing XML data");

            return $this->processXML($RawXML);
        }

        $this->DebugLog("Couldn't identify id");

        return FALSE;
    }

    private function processXML($RawXML)
    {
        $match = array();

        preg_match('#<statuscode>(.*?)</statuscode>#i', $RawXML, $match);

        if($match[1] !== 'ok') {
            $this->DebugLog("Status not ok, Statuscode " . $match[1]);
            return ERR_FILE_NO_EXIST;
        }

        $bestFormat = array(
            'quality'   => -1,
            'bitrate'   => -1,
            'url'       => '',
        );<commit_msg>Got rid of private<commit_after><?php

/**
 * @author <NAME> <<EMAIL>>
 * @version 0.4a
 * @copyright 2015 <NAME>
 * @license http://opensource.org/licenses/MIT Licensed under MIT License
 */

require_once 'provider.php';

class SynoFileHostingZdfMediathek extends TheiNaDProvider {

    static $QualityPriority = array(
        'veryhigh'  => 2,
        'high'      => 1,
        'low'       => 0,
    );

    static $UnsupportedFacets = array(
        'hbbtv',
    );

    protected $LogPath = '/tmp/zdf-mediathek.log';

    //This function gets the download url
    public function GetDownloadInfo() {

        $this->DebugLog("Getting download url for $this->Url");

        if(strpos($this->Url, 'zdf.de') !== false)
        {
            return $this->zdf();
        }

        if(strpos($this->Url, '3sat.de') !== false)
        {
            return $this->dreisat();
        }

        return FALSE;
    }

    protected function dreisat()
    {
        if(preg_match('#mediathek\/(?:.*)obj=(\d+)#i', $this->Url, $match) === 1)
        {
            $id = $match[1];

            $this->DebugLog("ID is $id");

            $this->DebugLog("Getting XML data from http://www.3sat.de/mediathek/xmlservice/web/beitragsDetails?ak=web&id=$id&ak=web");

            $RawXML = $this->curlRequest('http://www.3sat.de/mediathek/xmlservice/web/beitragsDetails?ak=web&id=' . $id . '&ak=web');

            if($RawXML === null)
            {
                return false;
            }

            $this->DebugLog("Processing XML data");

            return $this->processXML($RawXML);
        }

        $this->DebugLog("Couldn't identify id");

        return FALSE;
    }

    protected function zdf()
    {
        if(preg_match('#beitrag/video/([0-9]+)#i', $this->Url, $match) === 1)
        {
            $id = $match[1];

            $this->DebugLog("ID is $id");

            $this->DebugLog("Getting XML data from http://zdf.de/ZDFmediathek/xmlservice/web/beitragsDetails?id=$id&ak=web");

            $RawXML = $this->curlRequest('http://zdf.de/ZDFmediathek/xmlservice/web/beitragsDetails?id=' . $id . '&ak=web');

            if($RawXML === null)
            {
                return false;
            }

            $this->DebugLog("Processing XML data");

            return $this->processXML($RawXML);
        }

        $this->DebugLog("Couldn't identify id");

        return FALSE;
    }

    protected function processXML($RawXML)
    {
        $match = array();

        preg_match('#<statuscode>(.*?)</statuscode>#i', $RawXML, $match);

        if($match[1] !== 'ok') {
            $this->DebugLog("Status not ok, Statuscode " . $match[1]);
            return ERR_FILE_NO_EXIST;
        }

        $bestFormat = array(
            'quality'   => -1,
            'bitrate'   => -1,
            'url'       => '',
        );
{'fraction_non_alphanumeric': 0.17081348155990825, 'fraction_numerical': 0.007764249161814011, 'mean_word_length': 1.8859470468431772, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2799980', 'n_tokens_mistral': 1897, 'n_tokens_neox': 1785, 'n_words': 317}