From ea0b38ad4a505f154af0d2cac64dae8b88e7267a Mon Sep 17 00:00:00 2001 From: Arthur Date: Sun, 1 Dec 2013 09:10:03 -0500 Subject: [PATCH 1/4] Attaching the mp4 file to youtube feed --- bridges/YoutubeBridge.php | 40 +++++++++++++++++++++++++++++++++++++++ formats/AtomFormat.php | 4 +++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/bridges/YoutubeBridge.php b/bridges/YoutubeBridge.php index 8d739251..d3373042 100644 --- a/bridges/YoutubeBridge.php +++ b/bridges/YoutubeBridge.php @@ -23,9 +23,49 @@ class YoutubeBridge extends BridgeAbstract{ foreach($html->find('li.channels-content-item') as $element) { + + + $opts = array('http' => + array( + "method" => "GET", + 'header' => "User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)\r\n" + ) + ); + $context = stream_context_create($opts); + + $html_video = file_get_contents('http://www.youtube.com'.$element->find('a',0)->href, false, $context); + + if(!preg_match('/stream_map=(.[^&]*?)&/i',$html_video,$match)) + { + $this->returnError ("Error Locating Downlod URL's", 400); + } + + if(!preg_match('/stream_map=(.[^&]*?)(?:\\\\|&)/i',$html_video,$match)) + { + $this->returnError ("Problem", 400); + } + + $fmt_url = urldecode($match[1]); + + $urls = explode(',',$fmt_url); + + $foundArray = array(); + + foreach($urls as $url) + { + if(preg_match('/itag=([0-9]+)/',$url,$tm) && preg_match('/sig=(.*?)&/', $url , $si) && preg_match('/url=(.*?)&/', $url , $um)) + { + $u = urldecode($um[1]); + $foundArray[$tm[1]] = $u.'&signature='.$si[1]; + } + } + print_r($foundarray); + $video = $foundArray[22]; + $item = new \Item(); $item->uri = 'https://www.youtube.com'.$element->find('a',0)->href; $item->thumbnailUri = 'https:'.$element->find('img',0)->src; + $item->attachment = htmlspecialchars($video); $item->title = trim($element->find('h3',0)->plaintext); $item->content = '
' . $item->title . ''; $this->items[] = $item; diff --git a/formats/AtomFormat.php b/formats/AtomFormat.php index cdd0a9ad..3366dd52 100644 --- a/formats/AtomFormat.php +++ b/formats/AtomFormat.php @@ -1,4 +1,4 @@ -author) ? $uri : $data->author; $entryTitle = is_null($data->title) ? '' : $data->title; $entryUri = is_null($data->uri) ? '' : $data->uri; + $entryAttachment = is_null($data->attachment) ? '' : $data->attachment; $entryTimestamp = is_null($data->timestamp) ? '' : date(DATE_ATOM, $data->timestamp); // We prevent content from closing the CDATA too early. $entryContent = is_null($data->content) ? '' : 'sanitizeHtml(str_replace(']]>','',$data->content)) . ']]>'; @@ -41,6 +42,7 @@ class AtomFormat extends FormatAbstract{ {$entryUri} {$entryTimestamp} {$entryContent} + EOD; From 8325294e654758ef63fa3466d869e34d3c8b6f2d Mon Sep 17 00:00:00 2001 From: Arthur Date: Sun, 1 Dec 2013 10:11:58 -0500 Subject: [PATCH 2/4] Now the feed is always W3C validator compilant, if no timestamps is provided, date of timestamp 0 is set, and timestamp of the whole feed is set to the last added entry --- bridges/YoutubeBridge.php | 1 - formats/AtomFormat.php | 10 ++++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/bridges/YoutubeBridge.php b/bridges/YoutubeBridge.php index d3373042..abbb0d97 100644 --- a/bridges/YoutubeBridge.php +++ b/bridges/YoutubeBridge.php @@ -59,7 +59,6 @@ class YoutubeBridge extends BridgeAbstract{ $foundArray[$tm[1]] = $u.'&signature='.$si[1]; } } - print_r($foundarray); $video = $foundArray[22]; $item = new \Item(); diff --git a/formats/AtomFormat.php b/formats/AtomFormat.php index 3366dd52..7f71e771 100644 --- a/formats/AtomFormat.php +++ b/formats/AtomFormat.php @@ -1,4 +1,4 @@ - getExtraInfos(); $title = htmlspecialchars($extraInfos['name']); $uri = htmlspecialchars($extraInfos['uri']); - + $timestamps = array(); $entries = ''; foreach($this->getDatas() as $data){ $entryName = is_null($data->name) ? $title : $data->name; @@ -26,7 +26,8 @@ class AtomFormat extends FormatAbstract{ $entryTitle = is_null($data->title) ? '' : $data->title; $entryUri = is_null($data->uri) ? '' : $data->uri; $entryAttachment = is_null($data->attachment) ? '' : $data->attachment; - $entryTimestamp = is_null($data->timestamp) ? '' : date(DATE_ATOM, $data->timestamp); + $entryTimestamp = is_null($data->timestamp) ? date(DATE_ATOM, 0) : date(DATE_ATOM, $data->timestamp); + $timestamps[] = (int)$entryTimestamp; // We prevent content from closing the CDATA too early. $entryContent = is_null($data->content) ? '' : 'sanitizeHtml(str_replace(']]>','',$data->content)) . ']]>'; @@ -47,6 +48,7 @@ class AtomFormat extends FormatAbstract{ EOD; } + $update_timestamp = date(DATE_ATOM, max($timestamps)); /* TODO : @@ -62,7 +64,7 @@ EOD; {$title} http{$https}://{$httpHost}{$httpInfo}/ - + {$update_timestamp} {$entries} From e8895b175295488df1d42fbce000b70b0cca89ea Mon Sep 17 00:00:00 2001 From: Arthur Date: Sun, 1 Dec 2013 10:18:35 -0500 Subject: [PATCH 3/4] Added codec of the attached file --- bridges/YoutubeBridge.php | 1 + formats/AtomFormat.php | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/bridges/YoutubeBridge.php b/bridges/YoutubeBridge.php index abbb0d97..3ead3e82 100644 --- a/bridges/YoutubeBridge.php +++ b/bridges/YoutubeBridge.php @@ -65,6 +65,7 @@ class YoutubeBridge extends BridgeAbstract{ $item->uri = 'https://www.youtube.com'.$element->find('a',0)->href; $item->thumbnailUri = 'https:'.$element->find('img',0)->src; $item->attachment = htmlspecialchars($video); + $item->attachmentCodec = "video/mp4"; $item->title = trim($element->find('h3',0)->plaintext); $item->content = '
' . $item->title . ''; $this->items[] = $item; diff --git a/formats/AtomFormat.php b/formats/AtomFormat.php index 7f71e771..b9a69b9a 100644 --- a/formats/AtomFormat.php +++ b/formats/AtomFormat.php @@ -26,6 +26,7 @@ class AtomFormat extends FormatAbstract{ $entryTitle = is_null($data->title) ? '' : $data->title; $entryUri = is_null($data->uri) ? '' : $data->uri; $entryAttachment = is_null($data->attachment) ? '' : $data->attachment; + $entryAttachmentCodec = is_null($data->attachmentCodec) ? '' : $data->attachmentCodec; $entryTimestamp = is_null($data->timestamp) ? date(DATE_ATOM, 0) : date(DATE_ATOM, $data->timestamp); $timestamps[] = (int)$entryTimestamp; // We prevent content from closing the CDATA too early. @@ -43,7 +44,7 @@ class AtomFormat extends FormatAbstract{ {$entryUri} {$entryTimestamp} {$entryContent} - + EOD; From 5e56530861f5d7b99a93550342f12443e92770f9 Mon Sep 17 00:00:00 2001 From: Arthur Date: Sun, 8 Dec 2013 13:54:39 -0500 Subject: [PATCH 4/4] Linked all videos formats from youtube --- bridges/YoutubeBridge.php | 31 ++++++++++++++++++++++++------- formats/AtomFormat.php | 14 ++++++++++---- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/bridges/YoutubeBridge.php b/bridges/YoutubeBridge.php index 3ead3e82..d43dd263 100644 --- a/bridges/YoutubeBridge.php +++ b/bridges/YoutubeBridge.php @@ -37,35 +37,52 @@ class YoutubeBridge extends BridgeAbstract{ if(!preg_match('/stream_map=(.[^&]*?)&/i',$html_video,$match)) { - $this->returnError ("Error Locating Downlod URL's", 400); + //$this->returnError ("Error Locating Downlod URL's", 400); } if(!preg_match('/stream_map=(.[^&]*?)(?:\\\\|&)/i',$html_video,$match)) { - $this->returnError ("Problem", 400); + //$this->returnError ("Problem", 400); } $fmt_url = urldecode($match[1]); $urls = explode(',',$fmt_url); - $foundArray = array(); + $videos = array(); foreach($urls as $url) { if(preg_match('/itag=([0-9]+)/',$url,$tm) && preg_match('/sig=(.*?)&/', $url , $si) && preg_match('/url=(.*?)&/', $url , $um)) { $u = urldecode($um[1]); - $foundArray[$tm[1]] = $u.'&signature='.$si[1]; + $videos[$tm[1]] = $u.'&signature='.$si[1]; } } - $video = $foundArray[22]; + + $codecs = array(); + $codecs[13] = "video/3gpp"; + $codecs[17] = "video/3gpp"; + $codecs[36] = "video/3gpp"; + $codecs[5] = "video/x-flv"; + $codecs[6] = "video/x-flv"; + $codecs[34] = "video/x-flv"; + $codecs[35] = "video/x-flv"; + $codecs[43] = "video/webm"; + $codecs[44] = "video/webm"; + $codecs[45] = "video/webm"; + $codecs[18] = "video/mp4"; + $codecs[22] = "video/mp4"; + $codecs[37] = "video/mp4"; + $codecs[33] = "video/mp4"; $item = new \Item(); $item->uri = 'https://www.youtube.com'.$element->find('a',0)->href; $item->thumbnailUri = 'https:'.$element->find('img',0)->src; - $item->attachment = htmlspecialchars($video); - $item->attachmentCodec = "video/mp4"; + $item->attachments = array(); + foreach ($videos as $key => $value){ + $item->attachments[] = array("URL" => htmlspecialchars($value), "codec" => $codecs[$key]); + } $item->title = trim($element->find('h3',0)->plaintext); $item->content = '
' . $item->title . ''; $this->items[] = $item; diff --git a/formats/AtomFormat.php b/formats/AtomFormat.php index b9a69b9a..b9644d0e 100644 --- a/formats/AtomFormat.php +++ b/formats/AtomFormat.php @@ -21,17 +21,23 @@ class AtomFormat extends FormatAbstract{ $timestamps = array(); $entries = ''; foreach($this->getDatas() as $data){ + $attachments = ''; $entryName = is_null($data->name) ? $title : $data->name; $entryAuthor = is_null($data->author) ? $uri : $data->author; $entryTitle = is_null($data->title) ? '' : $data->title; $entryUri = is_null($data->uri) ? '' : $data->uri; - $entryAttachment = is_null($data->attachment) ? '' : $data->attachment; - $entryAttachmentCodec = is_null($data->attachmentCodec) ? '' : $data->attachmentCodec; + $entryAttachments = is_null($data->attachments) ? array() : $data->attachments; $entryTimestamp = is_null($data->timestamp) ? date(DATE_ATOM, 0) : date(DATE_ATOM, $data->timestamp); $timestamps[] = (int)$entryTimestamp; // We prevent content from closing the CDATA too early. $entryContent = is_null($data->content) ? '' : 'sanitizeHtml(str_replace(']]>','',$data->content)) . ']]>'; - + foreach ($entryAttachments as $key => $attachment){ + $url = $attachment["URL"]; + $codec = $attachment["codec"]; + $attachments .= << +EOD; + } $entries .= << @@ -44,7 +50,7 @@ class AtomFormat extends FormatAbstract{ {$entryUri} {$entryTimestamp} {$entryContent} - + {$attachments} EOD;