From 7a2f6b40209ee417b47bf0bc1a5bbf65aba3390e Mon Sep 17 00:00:00 2001 From: somini Date: Sun, 14 Apr 2019 19:26:14 +0100 Subject: [PATCH 1/7] [QPlayBridge]: New Bridge --- bridges/QPlayBridge.php | 72 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 bridges/QPlayBridge.php diff --git a/bridges/QPlayBridge.php b/bridges/QPlayBridge.php new file mode 100644 index 00000000000..fb4dbb9b952 --- /dev/null +++ b/bridges/QPlayBridge.php @@ -0,0 +1,72 @@ + array( + 'program' => array( + 'name' => 'Program Name', + 'type' => 'text', + 'required' => true, + ), + ), + ); + + public function getIcon() { + $html = getSimpleHTMLDOMCached(self::URI) + or returnServerError('Could not load content'); + + return $html->find('head link[rel="apple-touch-icon"]', 0)->getAttribute('href'); + } + + public function getURI() { + $uri = self::URI; + switch ($this->queriedContext) { + case 'Program': + $uri .= '/programs/' . $this->getInput('program'); + } + return $uri; + } + + public function getName() { + switch ($this->queriedContext) { + case 'Program': + $html = getSimpleHTMLDOMCached($this->getURI()) + or returnServerError('Could not load content'); + + return $html->find('h1.program--title', 0)->innertext; + break; + } + + return parent::getName(); + } + + /* This uses the uscreen platform, other sites can adapt this. https://www.uscreen.tv/ */ + public function collectData() { + switch ($this->queriedContext) { + case 'Program': + $program = $this->getInput('program'); + $html = getSimpleHTMLDOMCached($this->getURI()) + or returnServerError('Could not load content'); + + foreach($html->find('.cce--thumbnails-video-chapter') as $element) { + $cid = $element->getAttribute('data-id'); + $item['title'] = $element->find('.cce--chapter-title', 0)->innertext; + $item['content'] = $element->find('.cce--thumbnails-image-block', 0) . $element->find('.cce--chapter-body', 0)->innertext; + $item['uri'] = $this->getURI() . '?cid=' . $cid; + + /* TODO: Suport login credentials? */ + /* # Get direct video URL */ + /* $json_source = getContents(self::URI . '/chapters/' . $cid, array('Cookie: _uscreen2_session=???;')) */ + /* or returnServerError('Could not request chapter JSON'); */ + /* $json = json_decode($json_source); */ + + /* $item['enclosures'] = [$json->fallback]; */ + + $this->items[] = $item; + } + } + } +} From daf8cab2e8aff5a3a85db530fc7ed8541e599e89 Mon Sep 17 00:00:00 2001 From: somini Date: Tue, 30 Apr 2019 17:49:21 +0100 Subject: [PATCH 2/7] [QPlayBridge]: Support Catalogue feed --- bridges/QPlayBridge.php | 65 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/bridges/QPlayBridge.php b/bridges/QPlayBridge.php index fb4dbb9b952..ce5707e5437 100644 --- a/bridges/QPlayBridge.php +++ b/bridges/QPlayBridge.php @@ -12,6 +12,13 @@ class QPlayBridge extends BridgeAbstract { 'required' => true, ), ), + 'Catalog' => array( + 'all_pages' => array( + 'name' => 'All Pages', + 'type' => 'checkbox', + 'defaultValue' => false, + ), + ), ); public function getIcon() { @@ -26,6 +33,10 @@ public function getURI() { switch ($this->queriedContext) { case 'Program': $uri .= '/programs/' . $this->getInput('program'); + break; + case 'Catalog': + $uri .= '/catalog'; + break; } return $uri; } @@ -38,6 +49,9 @@ public function getName() { return $html->find('h1.program--title', 0)->innertext; break; + case 'Catalog': + return self::NAME . ' | Programas'; + break; } return parent::getName(); @@ -67,6 +81,57 @@ public function collectData() { $this->items[] = $item; } + + break; + case 'Catalog': + $json_raw = getContents($this->getCatalogURI(1)) + or returnServerError('Could not load catalog content'); + + $json = json_decode($json_raw); + $total_pages = $json->total_pages; + + foreach($this->parseCatalogPage($json) as $item) { + $this->items[] = $item; + } + + if ($this->getInput('all_pages') == true) { + foreach(range(2, $total_pages) as $page) { + $json_raw = getContents($this->getCatalogURI($page)) + or returnServerError('Could not load catalog content (all pages)'); + + $json = json_decode($json_raw); + + foreach($this->parseCatalogPage($json) as $item) { + $this->items[] = $item; + } + } + } + + break; + } + } + + private function getCatalogURI($page) { + return self::URI . '/catalog.json?page=' . $page; + } + + private function parseCatalogPage($json) { + $items = array(); + + foreach($json->records as $record) { + $item = array(); + + $item['title'] = $record->title; + $item['content'] = $record->description . '
Duration: '.$record->duration.'
'; + $item['timestamp'] = strtotime($record->release_date); + $item['uri'] = self::URI . $record->url; + $item['enclosures'] = array( + $record->main_poster, + ); + + $items[] = $item; } + + return $items; } } From af2d1aedc5ac1e14b0957995b6703dcd1476678e Mon Sep 17 00:00:00 2001 From: somini Date: Fri, 3 May 2019 14:47:50 +0100 Subject: [PATCH 3/7] [QPlayBridge]: Code Review --- bridges/QPlayBridge.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/bridges/QPlayBridge.php b/bridges/QPlayBridge.php index ce5707e5437..01eccd032f2 100644 --- a/bridges/QPlayBridge.php +++ b/bridges/QPlayBridge.php @@ -29,16 +29,12 @@ public function getIcon() { } public function getURI() { - $uri = self::URI; switch ($this->queriedContext) { case 'Program': - $uri .= '/programs/' . $this->getInput('program'); - break; + return self::URI . '/programs/' . $this->getInput('program'); case 'Catalog': - $uri .= '/catalog'; - break; + return self::URI . '/catalog'; } - return $uri; } public function getName() { @@ -48,10 +44,8 @@ public function getName() { or returnServerError('Could not load content'); return $html->find('h1.program--title', 0)->innertext; - break; case 'Catalog': return self::NAME . ' | Programas'; - break; } return parent::getName(); @@ -94,7 +88,7 @@ public function collectData() { $this->items[] = $item; } - if ($this->getInput('all_pages') == true) { + if ($this->getInput('all_pages') === true) { foreach(range(2, $total_pages) as $page) { $json_raw = getContents($this->getCatalogURI($page)) or returnServerError('Could not load catalog content (all pages)'); From 75e93868435d947683aeba5e232fe714b13189b7 Mon Sep 17 00:00:00 2001 From: somini Date: Sat, 4 May 2019 22:35:27 +0100 Subject: [PATCH 4/7] Appease Travis --- bridges/QPlayBridge.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bridges/QPlayBridge.php b/bridges/QPlayBridge.php index 01eccd032f2..781d41b0c90 100644 --- a/bridges/QPlayBridge.php +++ b/bridges/QPlayBridge.php @@ -24,7 +24,7 @@ class QPlayBridge extends BridgeAbstract { public function getIcon() { $html = getSimpleHTMLDOMCached(self::URI) or returnServerError('Could not load content'); - + return $html->find('head link[rel="apple-touch-icon"]', 0)->getAttribute('href'); } @@ -116,7 +116,8 @@ private function parseCatalogPage($json) { $item = array(); $item['title'] = $record->title; - $item['content'] = $record->description . '
Duration: '.$record->duration.'
'; + $item['content'] = $record->description + . '
Duration: ' . $record->duration.'
'; $item['timestamp'] = strtotime($record->release_date); $item['uri'] = self::URI . $record->url; $item['enclosures'] = array( From 2cd86e79a690a542a6b6b49098de7e145ec3d25e Mon Sep 17 00:00:00 2001 From: somini Date: Sat, 4 May 2019 22:37:52 +0100 Subject: [PATCH 5/7] Return the base URI by default --- bridges/QPlayBridge.php | 1 + 1 file changed, 1 insertion(+) diff --git a/bridges/QPlayBridge.php b/bridges/QPlayBridge.php index 781d41b0c90..15fd5d9e0ea 100644 --- a/bridges/QPlayBridge.php +++ b/bridges/QPlayBridge.php @@ -35,6 +35,7 @@ public function getURI() { case 'Catalog': return self::URI . '/catalog'; } + return parent::getURI(); } public function getName() { From 4c5f27520ea3296a703ae1e1b6835e1f0447ddd0 Mon Sep 17 00:00:00 2001 From: somini Date: Wed, 15 May 2019 22:55:08 +0100 Subject: [PATCH 6/7] [QPlayBridge]: Code Review Remove fetching data on `getIcon` --- bridges/QPlayBridge.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/bridges/QPlayBridge.php b/bridges/QPlayBridge.php index 15fd5d9e0ea..28addd4f609 100644 --- a/bridges/QPlayBridge.php +++ b/bridges/QPlayBridge.php @@ -22,10 +22,8 @@ class QPlayBridge extends BridgeAbstract { ); public function getIcon() { - $html = getSimpleHTMLDOMCached(self::URI) - or returnServerError('Could not load content'); - - return $html->find('head link[rel="apple-touch-icon"]', 0)->getAttribute('href'); + # This should be the favicon served on `self::URI` + return 'https://s3.amazonaws.com/unode1/assets/4957/r3T9Lm9LTLmpAEX6FlSA_apple-touch-icon.png'; } public function getURI() { From 36df3f127ad3db633c80823b66c6550c0ec10fdd Mon Sep 17 00:00:00 2001 From: somini Date: Wed, 15 May 2019 22:56:50 +0100 Subject: [PATCH 7/7] [QPlayBridge]: Code Review Appease Travis --- bridges/QPlayBridge.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bridges/QPlayBridge.php b/bridges/QPlayBridge.php index 28addd4f609..f2043267ebc 100644 --- a/bridges/QPlayBridge.php +++ b/bridges/QPlayBridge.php @@ -61,7 +61,8 @@ public function collectData() { foreach($html->find('.cce--thumbnails-video-chapter') as $element) { $cid = $element->getAttribute('data-id'); $item['title'] = $element->find('.cce--chapter-title', 0)->innertext; - $item['content'] = $element->find('.cce--thumbnails-image-block', 0) . $element->find('.cce--chapter-body', 0)->innertext; + $item['content'] = $element->find('.cce--thumbnails-image-block', 0) + . $element->find('.cce--chapter-body', 0)->innertext; $item['uri'] = $this->getURI() . '?cid=' . $cid; /* TODO: Suport login credentials? */ @@ -116,7 +117,7 @@ private function parseCatalogPage($json) { $item['title'] = $record->title; $item['content'] = $record->description - . '
Duration: ' . $record->duration.'
'; + . '
Duration: ' . $record->duration . '
'; $item['timestamp'] = strtotime($record->release_date); $item['uri'] = self::URI . $record->url; $item['enclosures'] = array(