From ea0b38ad4a505f154af0d2cac64dae8b88e7267a Mon Sep 17 00:00:00 2001 From: Arthur Date: Sun, 1 Dec 2013 09:10:03 -0500 Subject: [PATCH] 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;