localdisk

PHP とか Java とか Web とか好きなことを書きます。

調子にのってtube8のflvと3gpのURLを取得してみた

先日作ったServices_YourFileHostが好評だったので、YourFileHost(会社で開いちゃダメ、ゼッタイ)の後継と目されている(と僕が勝手に思っている)、tube8(会社でry)のflvと3gp(iphoneとかで再生できるらしい)のURLを取得できるスクリプトをPHPで書いたよ。

flvのURL取得

<?php
$url = 'http://www.tube8.com/amateur/sexy-gf-cumming-on-camera/174515/';
$html = file_get_contents($url);
$doc = new DOMDocument;
@$doc->loadHTML($html);
$xpath = new DOMXPath($doc);
$embed = $xpath->query('//embed');
$vars = explode('&', $embed->item(0)->getAttribute('flashvars'));
$query = array();
foreach ($vars as $var) {
    list($key, $value) = explode('=', $var);
    $query[$key] = $value;
}
var_dump($query['videoUrl']); //flvのURL

3gpのURL取得

<?php
$url = 'http://www.tube8.com/amateur/sexy-gf-cumming-on-camera/174515/';
$html = file_get_contents($url);
$doc = new DOMDocument;
@$doc->loadHTML($html);
$xpath = new DOMXPath($doc);
$m = $xpath->query('//a');
for($i = 0; $i < $m->length; $i++) {
    $item = $m->item($i);
    if (preg_match('/^http:\/\/.*3gp$/', $item->getAttribute('href'), $match) !== 0) {
        var_dump($match[0]); // 3gpのURL
        return;
    }
}

これはもっと上手く書けそう。気が向いたらclass化してServices_Tube8としてリリースします。