{"id":342,"date":"2012-07-22T23:23:19","date_gmt":"2012-07-22T23:23:19","guid":{"rendered":"http:\/\/garysieling.com\/blog\/?p=342"},"modified":"2012-07-22T23:23:19","modified_gmt":"2012-07-22T23:23:19","slug":"reading-the-youtube-api-from-phantomjs","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/reading-the-youtube-api-from-phantomjs\/","title":{"rendered":"Reading the Youtube API from PhantomJS"},"content":{"rendered":"<p>The following code will retrieve the duration of a video from the Youtube API. The output must be in JSON, because PhantomJS currently doesn&#8217;t handle the XML correctly (from email threads it appears this will be fixed in a future release)<\/p>\n<pre lang=\"javascript\">\naddress = 'http:\/\/gdata.youtube.com\/feeds\/api\/videos\/' + id + '?v=2&alt=json';\npage.open(address, function (status) {\n   var duration = page.evaluate(function(){\n       var data = JSON.parse(document.querySelector(\"pre\").innerText);\n       return data.entry.media$group.media$content[0].duration;\n   });\n     \n   console.log(\"video duration: \" + duration);\n   phantom.exit();\n});\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The following code will retrieve the duration of a video from the Youtube API. The output must be in JSON, because PhantomJS currently doesn&#8217;t handle the XML correctly (from email threads it appears this will be fixed in a future release) address = &#8216;http:\/\/gdata.youtube.com\/feeds\/api\/videos\/&#8217; + id + &#8216;?v=2&#038;alt=json&#8217;; page.open(address, function (status) { var duration = &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.garysieling.com\/blog\/reading-the-youtube-api-from-phantomjs\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Reading the Youtube API from PhantomJS&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[13],"tags":[53,302,426,478,607],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/342"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=342"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/342\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=342"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=342"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=342"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}