All forum posts are answered by the Flashloaded Support Technicians. Posts are usually answered within 1 business day

- All forum posts/threads must first be approved by the moderator before they appear in the live forum.
- If you need to upload a file, please use the attachment feature. These files are only visible to you and the members of the Flashloaded support team so your files and information will remain safe and hidden from others. In order to upload an attachment, you must be the owner of the thread.
  #1  
Old 03-30-2009, 01:08 AM
anjanesh anjanesh is offline
Registered User
 
Join Date: Mar 2009
Posts: 8
Using RegExp in getVideoId.php

For some YouTube videos, the getVideoId.php doesnt retrieve the video_id & tag_t values.
For example http://www.youtube.com/watch?v=AIzbwV7on6Q
Code:
XML Parsing Error: not well-formed
Location: getVideoId.php?method=videoId&noCache=0%2E6937495740130544&url=http%3A%2F%2Fwww%2Eyoutube%2Ecom%2Fwatch%3Fv%3DAIzbwV7on6Q
Line Number 3, Column 91:		var additionalStatsHonorsUrl = '/watch_ajax?v=AIzbwV7on6Q&action_get_statistics_and_data=1&l=EN';
--------------------------------------------------------------------------------------------------------^
I replaced the the string functions with RegExp (preg_match) and it works.
PHP Code:
<?php
    $url 
trim($_REQUEST['url']);

    
$ch curl_init();

    
curl_setopt($chCURLOPT_URL$url);
    
curl_setopt($chCURLOPT_HEADERfalse);
    
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);

    
$info curl_exec($ch);

    
preg_match('#"video_id":.*?"(.*?)"#is'$info$matches);
    
$video_id $matches[1];

    
preg_match('#"t":.*?"(.*?)"#is'$info$matches);
    
$tag_t $matches[1];

    
/*
    $pos1 = strpos($info, '"video_id": "');
    $pos2 = strpos($info, '"t": "');

    $video_id = substr($info, $pos1 + 13);
        $video_id = substr($video_id, 0, strpos($video_id, '", '));

        $tag_t = substr($info, $pos2 + 6);
        $tag_t = substr($tag_t, 0, strpos($tag_t, '", '));
        * */

        
$response  '<video>';
        
$response .= '<id>' $video_id '</id>';
        
$response .= '<t>' $tag_t '</t>';
        
$response .= '</video>';

    
header("Content-type: text/xml");

    echo 
$response;

        
curl_close($ch);
?>
Reply With Quote
  #2  
Old 03-30-2009, 01:01 PM
Patrick - FL TEAM Patrick - FL TEAM is offline
Flashloaded Support Team
 
Join Date: Mar 2008
Posts: 6,906
Re: Using RegExp in getVideoId.php

Thank you for this new information. We will keep this in mind and we are sure other users will find this information valuable.

Thanks.
Reply With Quote
  #3  
Old 03-30-2009, 03:04 PM
Joel - FL TEAM Joel - FL TEAM is offline
Administrator
 
Join Date: May 2003
Posts: 4,661
Re: Using RegExp in getVideoId.php

We've just updated the php version of the proxy file with this code in case other users encounter the same problem. Thanks again for posting this.
Reply With Quote
  #4  
Old 03-31-2009, 02:10 AM
anjanesh anjanesh is offline
Registered User
 
Join Date: Mar 2009
Posts: 8
Re: Using RegExp in getVideoId.php

If json is enabled (default on PHP 5.2.0 and above), its best to use json_decode to decode the JavaScript variables.
PHP Code:
<?php

    $url 
trim($_REQUEST['url']);

    
$ch curl_init();

    
curl_setopt($chCURLOPT_URL$url);
    
curl_setopt($chCURLOPT_HEADERfalse);
    
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);

    
$info curl_exec($ch);

    if (!
preg_match('#var swfArgs = (\{.*?\})#is'$info$matches))
    {
        echo 
"Check the YouTube URL : {$_REQUEST['url']} <br/>\n";
        die(
"Couldnt detect swfArgs");
    }

    if (
function_exists(json_decode)) # >= PHP 5.2.0
    
{
        
$swfArgs json_decode($matches[1]);
        
$video_id $swfArgs->video_id;
        
$tag_t $swfArgs->t;
    }
    else
    {
        
preg_match('#"video_id":.*?"(.*?)"#is'$matches[1], $submatches);
        
$video_id $submatches[1];

        
preg_match('#"t":.*?"(.*?)"#is'$matches[1], $submatches);
        
$tag_t $submatches[1];
    }

    
$response  '<video>';
    
$response .= '<id>' $video_id '</id>';
    
$response .= '<t>' $tag_t '</t>';
    
$response .= '</video>';

    
header("Content-type: text/xml");

    echo 
$response;

    
curl_close($ch);
?>
Reply With Quote
  #5  
Old 03-31-2009, 03:07 PM
Joel - FL TEAM Joel - FL TEAM is offline
Administrator
 
Join Date: May 2003
Posts: 4,661
Re: Using RegExp in getVideoId.php

Thanks so much for this information and for suggesting this change. We've applied it to the php proxy file. We really appreciate your input on this
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 06:12 PM.


Powered by vBulletin®
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
© All Rights Reserved to FFF WEB MEDIA INC.