Sample code: extract URLs from feed.

2 views
Skip to first unread message

Mr-Yellow

unread,
Dec 5, 2007, 1:29:31 AM12/5/07
to AdultATOM
Atomlib works well in PHP for giving you an associative array, from
that array here is the basic logic for extracting info on the content/
links contained.

foreach ($contents->entries as $entry) {
$flvthumb_url = array();
$flv_url = array();
$flv_length = array();
$flv_title = array();

$mpgthumb_url = array();
$mpg_url = array();
$mpg_length = array();
$mpg_title = array();

$flv_cnt = 0;
$mpg_cnt = 0;

$twotwofiveseven_url = '';
$sponsor_url = '';
$sponsor_title = '';
$buy_title = '';
$buy_image = '';
$buy_url = '';

$video_id = md5($entry->id);
$title = $entry->title[1];
$description = $entry->content[1];

foreach ($entry->links as $link) {

// 2257
if ($link['title'] == "2257") {
$twotwofiveseven_url = $link['href'];

// MPEGs
} else if ($link['type'] == "video/mpeg" &&
$link['rel']=="enclosure") {
$mpg_length[$mpg_cnt] = $link['length'];
$mpg_length[$mpg_cnt] = sec2time($mpg_length[$mpg_cnt]);
if ($mpg_length[$mpg_cnt]["minutes"]>0) {
$mpg_length[$mpg_cnt] = $mpg_length[$mpg_cnt]["minutes"]."m ".
$mpg_length[$mpg_cnt]["seconds"]."s";
} else {
$mpg_length[$mpg_cnt] = $mpg_length[$mpg_cnt]["seconds"]."s";
}
$mpg_url[$mpg_cnt] = $link['href'];
$mpg_title[$mpg_cnt] = $link['title'];
$mpgthumb_url[$x] = '';
$mpg_cnt++;

// FLVs
} else if ($link['type'] == "video/x-flv" &&
$link['rel']=="enclosure") {
$flv_length[$flv_cnt] = $link['length'];
$flv_length[$flv_cnt] = sec2time($flv_length[$flv_cnt]);
if ($flv_length[$flv_cnt]["minutes"]>0) {
$flv_length[$flv_cnt] = $flv_length[$flv_cnt]["minutes"]."m ".
$flv_length[$flv_cnt]["seconds"]."s";
} else {
$flv_length[$flv_cnt] = $flv_length[$flv_cnt]["seconds"]."s";
}
$flv_url[$flv_cnt] = $link['href'];
$flv_title[$flv_cnt] = $link['title'];
$flvthumb_url[$x] = '';
$flv_cnt++;

// Sponsor Link
} else if ($link['type'] == "text/html" &&
$link['rel']=="alternate") {
$sponsor_url = $link['href'];
$sponsor_title = $link['title'];

// Buy DVD Link
} else if (preg_match('/Buy DVD/i',$link['title']) && $buy_url==''
&& $link['type'] == "text/html" && $link['rel']=="related") {
$buy_title = $link['title'];
$buy_url = $link['href'];
}
}

// Match Images to Links
foreach ($entry->links as $link) {
for ($x=0;$x<$flv_cnt;$x++) {
if ('image['.$flv_title[$x].']' == $link['title'] && $link['type']
== "image/jpeg" && $link['rel']=="related") {
$flvthumb_url[$x] = $link['href'];
}
}
for ($x=0;$x<$mpg_cnt;$x++) {
if ('image['.$mpg_title[$x].']' == $link['title'] && $link['type']
== "image/jpeg" && $link['rel']=="related") {
$mpgthumb_url[$x] = $link['href'];
}
}
if ('image['.$buy_title.']' == $link['title'] && $link['type'] ==
"image/jpeg" && $link['rel']=="related") {
$buy_image = $link['href'];
}
}


................... etc

-Ben

Mr-Yellow

unread,
Dec 5, 2007, 9:17:43 PM12/5/07
to AdultATOM
// Other Links
} else {
if (substr($link['title'], 0, 5) != 'image') {
$other_url[$other_cnt] = $link['href'];
$other_title[$other_cnt] = $link['title'];
$other_cnt++;
}
}

Mr-Yellow

unread,
Dec 10, 2007, 12:36:21 AM12/10/07
to AdultATOM
// XSPF Playlist
} else if ($link['title']=='playlist' && $link['type'] == "text/xml"
&& $link['rel']=="related") {
$playlist_url = $link['href'];
Reply all
Reply to author
Forward
0 new messages