Skip to content

Commit

Permalink
Fix ard hoster
Browse files Browse the repository at this point in the history
  • Loading branch information
iNaD committed Mar 15, 2019
1 parent 3a96072 commit 54b6db7
Show file tree
Hide file tree
Showing 7 changed files with 1,440 additions and 22 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.2",
"version": "0.4.3",
"autoload": {
"psr-4": {
"TheiNaD\\DSMediatheken\\": "src/"
Expand Down
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.2",
"version": "0.4.3",
"authentication": "no",
"module": "SynoFileHostingMediathek.php",
"class": "TheiNaD\\DSMediatheken\\SynoFileHostingMediathek",
Expand Down
56 changes: 37 additions & 19 deletions src/Mediatheken/ARD.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ public function getDownloadInfo($url, $username = '', $password = '')
$result = new Result();

$pageContent = $this->getPageContent($url);

if ($pageContent === null) {
$this->getLogger()->log(sprintf('could not retrieve page content from %s', $url));
return null;
}

$documentId = $this->getDocumentId($pageContent);
$documentId = $this->getDocumentIdFromUrl($url);
if ($documentId === null) {
$documentId = $this->getDocumentId($pageContent);
}

if ($documentId === null) {
$this->getLogger()->log('no documentId found in ' . $url);
return null;
Expand Down Expand Up @@ -72,13 +75,14 @@ private function getPageContent($url)
return $this->getTools()->curlRequest($url);
}

private function getDocumentId($pageContent)
private function getDocumentIdFromUrl($url)
{
if (preg_match('#"contentId":([0-9]+)#i', $pageContent, $match) !== 1) {
return null;
}
return $this->getTools()->pregMatchDefault('#documentId=([0-9]+)#i', $url, null);
}

return $match[1];
private function getDocumentId($pageContent)
{
return $this->getTools()->pregMatchDefault('#"contentId":([0-9]+)#i', $pageContent, null);
}

private function getApiData($documentId)
Expand Down Expand Up @@ -126,11 +130,34 @@ private function getQualityFromStreamUrl($stream)
private function addTitle($pageContent, Result $result)
{
$videoMeta = $this->getVideoMeta($pageContent);
if ($videoMeta !== null) {
return $this->addTitleFromVideoMeta($result, $videoMeta);
}

$titleTag = $this->getTools()->pregMatchDefault('#<title>(.*?)</title>#i', $pageContent, null);
if ($titleTag === null) {
return $result;
}

if ($videoMeta === null) {
$splitted = explode('|', $titleTag);
$episode = trim($splitted[0]);
$title = isset($splitted[1]) ? trim($splitted[1]) : null;

if ($title === null) {
$result->setTitle($episode);
return $result;
}

$title = str_replace('Video zu ', '', $title);

$result->setTitle($title);
$result->setEpisodeTitle($episode);

return $result;
}

private function addTitleFromVideoMeta(Result $result, $videoMeta)
{
$show = $this->getShowFromMeta($videoMeta);
$clipTitle = $this->getClipTitleFromMeta($videoMeta);

Expand All @@ -143,7 +170,6 @@ private function addTitle($pageContent, Result $result)
private function getVideoMeta($pageContent)
{
\preg_match_all('#<script>(.*?)<\/script>#si', $pageContent, $scriptTags);

if (count($scriptTags) === 0) {
return null;
}
Expand All @@ -161,19 +187,11 @@ private function getVideoMeta($pageContent)

private function getShowFromMeta($videoMeta)
{
if (preg_match('#"show":"(.*?)"#i', $videoMeta, $match) !== 1) {
return null;
}

return $match[1];
return $this->getTools()->pregMatchDefault('#"show":"(.*?)"#i', $videoMeta, null);
}

private function getClipTitleFromMeta($videoMeta)
{
if (preg_match('#"clipTitle":"(.*?)"#i', $videoMeta, $match) !== 1) {
return null;
}

return $match[1];
return $this->getTools()->pregMatchDefault('#"clipTitle":"(.*?)"#i', $videoMeta, null);
}
}
2 changes: 1 addition & 1 deletion src/SynoFileHostingMediathek.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* All public functions are required by Synology Download Station.
*
* @author Daniel Gehn <[email protected]>
* @version 0.4.2
* @version 0.4.3
* @copyright 2017-2019 Daniel Gehn
* @license http://opensource.org/licenses/MIT Licensed under MIT License
*/
Expand Down
33 changes: 33 additions & 0 deletions tests/ARDTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,37 @@ public function testDownloadInfoCanBeRetrievedFromValidUrlWhereResultHasMissingP
$this->assertEquals('die story', $result->getTitle());
$this->assertEquals('Wolfgang Bosbach - vom Loslassen eines Gefesselten', $result->getEpisodeTitle());
}

public function testDownloadInfoCanBeRetrievedFromValidUrlContainingDocumentId(): void
{
$VALID_DOWNLOAD_URL =
'http://mediathek.daserste.de/Die-Sendung-mit-der-Maus/MausSpezial-Frankreich-Maus/'.
'Video?bcastId=1458&documentId=61013370';
$API_URL = 'http://www.ardmediathek.de/play/media/61013370';
$MEDIA_FILE_URL =
'http://wdrmedien-a.akamaihd.net/medp/ondemand/weltweit/fsk0/187/1872647/1872647_21969608.mp4';

$logger = $this->createMock(Logger::class);
$curl = $this->createMock(Curl::class);
$tools = new Tools($logger, $curl);

$curl->expects($this->exactly(2))
->method('request')
->withConsecutive(
[$this->equalTo($VALID_DOWNLOAD_URL)],
[$this->equalTo($API_URL)]
)
->willReturnOnConsecutiveCalls(
$this->getFixture('ard/docIdInUrl/videoPage.html'),
$this->getFixture('ard/docIdInUrl/apiResponse.json')
);

$ard = new ARD($logger, $tools);
$result = $ard->getDownloadInfo($VALID_DOWNLOAD_URL);

$this->assertInstanceOf(Result::class, $result);
$this->assertEquals($MEDIA_FILE_URL, $result->getUri());
$this->assertEquals('Die Sendung mit der Maus', $result->getTitle());
$this->assertEquals('MausSpezial: Frankreich-Maus', $result->getEpisodeTitle());
}
}
1 change: 1 addition & 0 deletions tests/fixtures/ard/docIdInUrl/apiResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"_type":"video","_isLive":false,"_defaultQuality":["auto",2,4,3,1,0],"_previewImage":"https://img.ardmediathek.de/standard/00/61/01/34/38/-1774185891/16x9/960?mandant=ard","_subtitleUrl":"https://www.ardmediathek.de/subtitle/290401","_subtitleOffset":0,"_mediaArray":[{"_plugin":1,"_mediaStreamArray":[{"_quality":"auto","_server":"","_cdn":"flashls","_stream":"//wdradaptiv-vh.akamaihd.net/i/medp/ondemand/weltweit/fsk0/187/1872647/,1872647_21969609,1872647_21969604,1872647_21969606,1872647_21969607,1872647_21969605,1872647_21969608,.mp4.csmil/master.m3u8"},{"_quality":0,"_server":"","_cdn":"akamai","_stream":"//wdrmedien-a.akamaihd.net/medp/ondemand/weltweit/fsk0/187/1872647/1872647_21969605.mp4"},{"_quality":1,"_stream":["//wdrmedien-a.akamaihd.net/medp/ondemand/weltweit/fsk0/187/1872647/1872647_21969609.mp4","//wdrmedien-a.akamaihd.net/medp/ondemand/weltweit/fsk0/187/1872647/1872647_21969607.mp4"]},{"_quality":2,"_stream":["//wdrmedien-a.akamaihd.net/medp/ondemand/weltweit/fsk0/187/1872647/1872647_21969604.mp4","//wdrmedien-a.akamaihd.net/medp/ondemand/weltweit/fsk0/187/1872647/1872647_21969606.mp4"]},{"_quality":3,"_server":"","_cdn":"akamai","_width":1280,"_height":720,"_stream":"//wdrmedien-a.akamaihd.net/medp/ondemand/weltweit/fsk0/187/1872647/1872647_21969608.mp4"}]}],"_alternativeMediaArray":[],"_sortierArray":[1],"_duration":1755,"_dvrEnabled":false,"_geoblocked":false}
Loading

0 comments on commit 54b6db7

Please sign in to comment.