From f4ffeb37539a142aea763a92d1122cdbcd8c6c9b Mon Sep 17 00:00:00 2001 From: Tadas Juozapaitis Date: Mon, 7 Apr 2014 16:58:08 +0300 Subject: [PATCH] refactoring and adding youtube parser --- README.md | 34 +++++ src/LinkPreview/LinkPreview.php | 72 ++--------- src/LinkPreview/Model/VideoLink.php | 77 +++++++++++ src/LinkPreview/Parser/GeneralParser.php | 52 +++++++- src/LinkPreview/Parser/ParserInterface.php | 27 +++- src/LinkPreview/Parser/YoutubeParser.php | 141 +++++++++++++++++++++ src/LinkPreview/Reader/GeneralReader.php | 2 +- src/LinkPreview/Reader/ReaderInterface.php | 1 - 8 files changed, 340 insertions(+), 66 deletions(-) create mode 100644 src/LinkPreview/Model/VideoLink.php create mode 100644 src/LinkPreview/Parser/YoutubeParser.php diff --git a/README.md b/README.md index b107628..0818775 100644 --- a/README.md +++ b/README.md @@ -62,9 +62,43 @@ GitHub is the best place to build software together. Over 4 million people use G https://github.global.ssl.fastly.net/images/modules/open_graph/github-octocat.png ``` +```php +$linkPreview = new LinkPreview('https://www.youtube.com/watch?v=8ZcmTl_1ER8'); +$parsed = $linkPreview->getParsed(); +foreach ($parsed as $parserName => $link) { + echo $parserName . PHP_EOL . PHP_EOL; + + echo $link->getUrl() . PHP_EOL; + echo $link->getRealUrl() . PHP_EOL; + echo $link->getTitle() . PHP_EOL; + echo $link->getDescription() . PHP_EOL; + echo $link->getImage() . PHP_EOL; + echo $link->getVideoId() . PHP_EOL; + echo $link->getEmbedCode() . PHP_EOL; +} +``` + + +**Output** + +``` +youtube + +https://www.youtube.com/watch?v=8ZcmTl_1ER8 +http://gdata.youtube.com/feeds/api/videos/8ZcmTl_1ER8?v=2&alt=jsonc +Epic sax guy 10 hours +I had to remove my original one so I reuploaded this with much better quality. +(If you want it sound like previous one, try setting quality to 240p) +Yeah, I know that video sucks compared to original but no can do :( +http://i1.ytimg.com/vi/8ZcmTl_1ER8/hqdefault.jpg +8ZcmTl_1ER8 +