Skip to content

Commit

Permalink
Update DreiSat to use ZDF Api
Browse files Browse the repository at this point in the history
  • Loading branch information
iNaD committed Oct 3, 2019
1 parent ae38426 commit 8ff6959
Show file tree
Hide file tree
Showing 19 changed files with 2,221 additions and 796 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"homepage": "https://theinad.com",
"license": "MIT",
"name": "theinad/mediathek",
"version": "0.4.4",
"version": "0.5.0",
"autoload": {
"psr-4": {
"TheiNaD\\DSMediatheken\\": "src/"
Expand Down
240 changes: 149 additions & 91 deletions composer.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/INFO
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "mediathek",
"hostprefix": "zdf.de,3sat.de,ardmediathek.de,mediathek.daserste.de,mediathek.rbb-online.de,wdr.de,one.ard.de,arte.tv,kika.de,ndr.de,mdr.de",
"displayname": "ÖR Mediatheken",
"version": "0.4.4",
"version": "0.5.0",
"authentication": "no",
"module": "SynoFileHostingMediathek.php",
"class": "TheiNaD\\DSMediatheken\\SynoFileHostingMediathek",
Expand Down
2 changes: 1 addition & 1 deletion src/Mediatheken/ARD.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ARD extends Mediathek
private static $API_BASE_URL = 'http://www.ardmediathek.de/play/media/';
private static $VALID_QUALITIES = [0, 1, 2, 3, 4];

protected static $supportMatcher = ['ardmediathek.de', 'mediathek.daserste.de'];
protected static $SUPPORT_MATCHER = ['ardmediathek.de', 'mediathek.daserste.de'];

public function getDownloadInfo($url, $username = '', $password = '')
{
Expand Down
2 changes: 1 addition & 1 deletion src/Mediatheken/Arte.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Arte extends Mediathek
'vo'
];

protected static $supportMatcher = 'arte.tv';
protected static $SUPPORT_MATCHER = 'arte.tv';

protected $language = 'de';
protected $languageShortLibelle = 'de';
Expand Down
184 changes: 3 additions & 181 deletions src/Mediatheken/DreiSat.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,191 +2,13 @@

namespace TheiNaD\DSMediatheken\Mediatheken;

use TheiNaD\DSMediatheken\Utils\Mediathek;
use TheiNaD\DSMediatheken\Utils\Result;

/**
* @author Daniel Gehn <[email protected]>
* @copyright 2017-2019 Daniel Gehn
* @license http://opensource.org/licenses/MIT Licensed under MIT License
*/
class DreiSat extends Mediathek
class DreiSat extends ZDF
{

private static $DREISAT_XML_SERVICE_PATTERN =
'http://www.3sat.de/mediathek/xmlservice/web/beitragsDetails?ak=web&id={id}&ak=web';

/**
* Facets containing this type will be completely ignored.
*
* @var array
*/
private static $UNSUPPORTED_FACETS = [
'restriction_useragent',
];
/**
* Maps Qualities to ratings.
*
* A higher rating means the quality is preferred.
* A rating of -1 means the quality will be ignored.
*
* @var array
*/
private static $QUALITY_RATING = [
'low' => 0,
'med' => 1,
'high' => 2,
'veryhigh' => 3,
];
protected static $supportMatcher = '3sat.de';

public function getDownloadInfo($url, $username = '', $password = '')
{
$objectId = $this->getObjectId($url);
if ($objectId === null) {
$this->getLogger()->log('Couldn\'t identify object id in ' . $url);
return null;
}

$this->getLogger()->log('ID is ' . $objectId);
$this->getLogger()->log(
sprintf(
'Getting XML data from %s',
str_replace(
'{id}',
$objectId,
self::$DREISAT_XML_SERVICE_PATTERN
)
)
);
$rawXML =
$this->getTools()->curlRequest(str_replace(
'{id}',
$objectId,
self::$DREISAT_XML_SERVICE_PATTERN
));
if ($rawXML === null) {
$this->getLogger()->log('Failed to retrieve xml data.');
return null;
}

return $this->processXML($rawXML, $url);
}

private function getObjectId($url)
{
if (preg_match('#mediathek\/(?:.*)obj=(\d+)#i', $url, $match) === 1) {
return $match[1];
}
return null;
}

protected function processXML($rawXML, $url)
{
if ($this->isStatusOk($rawXML) === false) {
$this->getLogger()->log('status not ok');
return null;
}

$result = new Result();

$matches = [];
preg_match_all('#<formitaet basetype="(.*?)".*?>(.*?)</formitaet>#is', $rawXML, $matches);
foreach ($matches[1] as $index => $basetype) {
if (strpos($basetype, 'mp4_http') !== false) {
$formitaet = $matches[2][$index];
if ($this->isFacetSupported($formitaet) === false) {
continue;
}

$quality = $this->getQuality($formitaet);
$bitrate = $this->getBitrate($formitaet);

if ($quality >= $result->getQualityRating() && $bitrate > $result->getBitrateRating()) {
$result = new Result();
$result->setQualityRating($quality);
$result->setBitrateRating($bitrate);
$result->setUri($this->getUrl($formitaet));
}
}
}

if (!$result->hasUri()) {
$this->getLogger()->log('No format found');
return null;
}

$result->setTitle($this->getTitle($rawXML));
$result->setEpisodeTitle($this->getEpisodeTitle($rawXML));
$result->setUri($this->getTools()->addProtocolFromUrlIfMissing($result->getUri(), $url));

return $result;
}

private function isStatusOk($rawXML)
{
$match = [];
if (preg_match('#<statuscode>(.*?)</statuscode>#i', $rawXML, $match) == 1) {
return $match[1] === 'ok';
}
return false;
}

private function isFacetSupported($formitaet)
{
$match = [];
if (preg_match('#<facet>(.*?)</facet>#is', $formitaet, $match) == 1) {
if (!in_array($match[1], self::$UNSUPPORTED_FACETS)) {
return true;
}
}

return false;
}

private function getQuality($formitaet)
{
$match = [];
if (preg_match('#<quality>(.*?)</quality>#is', $formitaet, $match) == 1) {
return self::$QUALITY_RATING[$match[1]];
}

return -1;
}

private function getBitrate($formitaet)
{
$match = [];
if (preg_match('#<videoBitrate>(.*?)</videoBitrate>#is', $formitaet, $match) == 1) {
return $match[1];
}
return -1;
}

private function getUrl($formitaet)
{
$match = [];
if (preg_match('#<url>(.*?)</url>#is', $formitaet, $match) == 1) {
return trim($match[1]);
}
return null;
}

private function getTitle($rawXML)
{
$match = [];
if (preg_match('#<originChannelTitle>(.*?)<\/originChannelTitle>#i', $rawXML, $match) == 1) {
return $match[1];
}
return null;
}

private function getEpisodeTitle($rawXML)
{
$match = [];
if (preg_match('#<title>(.*?)<\/title>#i', $rawXML, $match) == 1) {
return $match[1];
}
return null;
}
protected static $API_BASE_URL = 'https://api.3sat.de';
protected static $SUPPORT_MATCHER = '3sat.de';
}
2 changes: 1 addition & 1 deletion src/Mediatheken/KiKa.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
class KiKa extends Mediathek
{
protected static $supportMatcher = ['kika.de'];
protected static $SUPPORT_MATCHER = ['kika.de'];

public function getDownloadInfo($url, $username = '', $password = '')
{
Expand Down
2 changes: 1 addition & 1 deletion src/Mediatheken/MDR.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
class MDR extends Mediathek
{
protected static $supportMatcher = ['mdr.de'];
protected static $SUPPORT_MATCHER = ['mdr.de'];

private static $apiBaseUrl = 'https://www.mdr.de';

Expand Down
2 changes: 1 addition & 1 deletion src/Mediatheken/NDR.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
class NDR extends Mediathek
{
protected static $supportMatcher = ['ndr.de'];
protected static $SUPPORT_MATCHER = ['ndr.de'];

public function getDownloadInfo($url, $username = '', $password = '')
{
Expand Down
2 changes: 1 addition & 1 deletion src/Mediatheken/RBB.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class RBB extends Mediathek
private static $API_BASE_URL = 'http://mediathek.rbb-online.de/play/media/';
private static $VALID_CDNS = ['default', 'akamai'];

protected static $supportMatcher = 'mediathek.rbb-online.de';
protected static $SUPPORT_MATCHER = 'mediathek.rbb-online.de';

public function getDownloadInfo($url, $username = '', $password = '')
{
Expand Down
2 changes: 1 addition & 1 deletion src/Mediatheken/WDR.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class WDR extends Mediathek
{

protected static $supportMatcher = ['wdr.de/mediathek', 'one.ard.de/mediathek'];
protected static $SUPPORT_MATCHER = ['wdr.de/mediathek', 'one.ard.de/mediathek'];

public function getDownloadInfo($url, $username = '', $password = '')
{
Expand Down
Loading

0 comments on commit 8ff6959

Please sign in to comment.