drice73 wrote:
最近看楓林網和sug...(恕刪)
1073 IMAPS 裡面有個 PlayItemUrl 網路播放的語法
直接播放為
PlayItemUrl(Youtube影像網址); 這很順暢 , 負載相當低 , 不影響遙控器操作
若是
PlayItemUrl(http://127.0.0.1:8081/xxx/youtube.video.php);
http://127.0.0.1:8081/xxx/youtube.video.php 為播放機處理 , 這就會處在當機的邊緣 ,
原因是 youtube.video.php 使用RAM的上限是 128MB , 1073開機後所剩RAM不超過25MB
通常RAM都會用到掛
如果將 /opt/etc/php.ini 上限設為 64MB 或 32MB , 這樣PHP Youtube解析會變得非常慢 , 取檔更慢 , 跟掛了也差不多情況
如何改善
1.想辦法寫一個程式取代 Youtube影像網址 , 如 movie= GetUrl(Youtube網址解析); PlayItemUrl(movie);
2.修改 youtube.video.php , 跑到最後將程式終止 改為 wget / curl /msdl 獲取Youtube影片
至於Youtube解析程式 , 其實未必要透過 PHP 來處理
例如小弟慣用 Perl 取得 Youtube 影片網址
sub URLEncode {my $theURL = $_[0];$theURL =~ tr/+/ /;$theURL =~ s/%([a-fA-F0-9]{2,2})/chr(hex($1))/eg;$theURL =~ s/<!--(.|\n)*-->//g;return $theURL;}
sub yutgg {my $theURL = $_[0];$theURL=~ s/%25/%/g;$theURL=~ s/%3A/:/g;$theURL=~ s/%2F/\//g;$theURL=~ s/%3F/\?/g;$theURL=~ s/%3D/\=/g;$theURL=~ s/%252C/%2C/g;$theURL=~ s/%26/\?/g;$theURL=~ s/%26/\?/g;return $theURL;}
if ($action eq "gettube") {
$tubeurl=$FORM{'tubeurl'};$tubeurl =~ s/@@@@/=/;system("/opt/bin/curl -s -o /tmp/tube.txt \"$tubeurl\"");open(FILE,"/tmp/tube.txt");
@cima=<FILE>;close(FILE);@cima = grep(/url_encoded_fmt_stream_map=url%3D/../url%3D/, @cima);
@cima=URLEncode(@cima);my @aszbb = split(/url=(.+?),/,$cima[0]);
foreach $line(@aszbb) {($ggb)=split(/url=(.+?),/,$line);if($ggb =~ /itag=37/ || $ggb =~ /itag=22/ || $ggb =~ /itag=18/){$ggb=yutgg($ggb);$ggb =~ s/%3B(.*?)$//g;push (@rsscc, "$ggb");}}
print @rsscc[0];exit;
}
或者是media-translate常用的 Shell Script
vid_url=`echo "${QUERY_STRING}" | /opt/bin/awk -F, '{print $1}'`
tmp_file=/tmp/$$.html
USERAGENT="Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; InfoPath.2)"
host_response=`/opt/bin/wget -q -O ${tmp_file} ${vid_url} 2>&1`
fmt_url_map=`grep -i 'url_encoded_fmt_stream_map=' ${tmp_file} | sed -n '1p'`
if [ -z "$fmt_url_map" ]; then
fmt_url_map=`grep -i 'fmt_url_map=' ${TMPFILE} | sed '1p'`
fmt_url_map=`echo "$fmt_url_map" | unidecode | unescapeXML | /opt/bin/awk '{match($0, /&fmt_url_map=([^&]*)&/, arr);print arr[1];}' | urldecode`
else
fmt_url_map=`echo "$fmt_url_map" | unidecode | unescapeXML | /opt/bin/awk '{match($0, /&url_encoded_fmt_stream_map=url%3D([^&]*)&/, arr);print arr[1];}' | urldecode | urldecode`
fi
if echo "$fmt_url_map" | grep -qs ",url="; then
#22 / HD720
[ -n "$hdc" ] && stream_url=`echo $fmt_url_map | awk 'BEGIN{RS=",url="} /itag=22/{print $0}' | sed 's/;.*//'`
#18 / MEDIUM (default)
[ -z "$stream_url" ] && stream_url=`echo $fmt_url_map | /opt/bin/awk 'BEGIN{RS=",url="} /itag=18/{print $0}' | sed 's/;.*//'`
else
#22 / HD720
[ -n "$hdc" ] && stream_url=`echo $fmt_url_map | /opt/bin/awk '{match($0,/.*22\|([^,]+),?/,arr);print arr[1]}'`
#18 / MEDIUM (default)
[ -z "$stream_url" ] && stream_url=`echo $fmt_url_map | /opt/bin/awk '{match($0,/.*18\|([^,]+),?/,arr);print arr[1]}'`
fi
rm -rf ${tmp_file}
exec /opt/bin/wget -q -O - "${stream_url}"
或者是透過 PHP 只取得 Youtube 影片網址 , 交由PlayItemUrl播放
<?php
$file=$_GET["file"];
if(preg_match('/youtube\.com\/(v\/|watch\?v=)([\w\-]+)/', $file, $match)) {;
$id = $match[2];
$link="http://www.youtube.com/watch?v=".$id;
$html=file_get_contents($link);
$html = urldecode($html);
$h=explode('fmt_stream_map',$html);
$html=urldecode($h[1]);
$videos = explode('url=', $html);
for ($i=0;$i<count($videos);$i++) {
$t1=explode(";", $videos[$i]);
$link=$t1[0];
$t1=explode("itag=",$link);
$t2=explode("&",$t1[1]);
$tip=$t2[0];
if ($tip=="37") break;
if ($tip=="22") break;
if ($tip=="18") break;
}
}
print $link;
?>
比較速度及效能
速度 Perl > PHP > ShellScript
效能 Perl > ShellScript > PHP
isakira wrote:
應該會與BSMI釋出...(恕刪)
MOD頻道表出不來的問題已經查出來了,請isakira兄移駕了解,感謝!(466F)
http://www.mobile01.com/topicdetail.php?f=347&t=2136027&p=47#34220511#34220511#34220511
內文搜尋

X