Posted By

navjotjsingh on 11/07/08


Tagged

wordpress YouTube


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

lilumi
wanderlusts


Download Links for Youtube in Wordpress Single Post


 / Published in: PHP
 

  1. function str_between($string, $start, $end){ $string = " ".$string;
  2. $ini = strpos($string,$start); if ($ini == 0) return ""; $ini +=
  3. strlen($start); $len = strpos($string,$end,$ini) - $ini; return
  4. substr($string,$ini,$len); }
  5. function get_youtube_download_link($url){
  6. if( $url !== "")
  7. {
  8. $youtube_link = $url;
  9. //$url = get_post_meta($post->ID, 'url', true);
  10. if ( file_get_contents($youtube_link) !== "")
  11. {
  12. $youtube_page = file_get_contents($youtube_link);
  13. $v_id = str_between($youtube_page, "&video_id=", "&");
  14. $t_id = str_between($youtube_page, "&t=", "&");
  15. $flv_link = "http://www.youtube.com/get_video?video_id=$v_id&t=$t_id";
  16. $hq_flv_link = "http://www.youtube.com/get_video?video_id=$v_id&t=$t_id&fmt=6";
  17. $mp4_link = "http://www.youtube.com/get_video?video_id=$v_id&t=$t_id&fmt=18";
  18. $threegp_link =
  19. "http://www.youtube.com/get_video?video_id=$v_id&t=$t_id&fmt=17";
  20. echo "\t\tDownload (right-click > save as):\n\t\t";
  21. echo "<a href=\"$flv_link\">FLV</a>\n\t\t";
  22. echo "<a href=\"$hq_flv_link\">HQ FLV (if available)</a>\n\t\t";
  23. echo "<a href=\"$mp4_link\">MP4</a>\n\t\t";
  24. echo "<a href=\"$threegp_link\">3GP</a><br><br>\n";
  25. }
  26. }
  27. }

Report this snippet  

You need to login to post a comment.