okay so here are the modifications i made to my upload.php in order to get the youtube video data working :
those modifications won't break the original hack so you can/have to apply the original hack along with this if you want it fully operational
locate :
if ($CONFIG['read_iptc_data']) {
$iptc = get_IPTC($path_to_image);
}
replace it with :
if (preg_match('/^youtube_(.*)\.jpg$/', $file_set[0], $ytmatches)){
$iptc = array();
$vid = $ytmatches[1];
$xdata = file_get_contents("albums/edit/yt_".$vid.".xml");
// todo: parse the xml properly
preg_match('/<description>(.*)<\/description>/', $xdata, $xmatches);
$iptc['Caption'] = substr($xmatches[1], 0, $CONFIG['max_img_desc_length']);
// todo: parse the xml properly
preg_match('/<tags>(.*)<\/tags>/', $xdata, $xmatches);
$iptc['Keywords'] = explode(" ", $xmatches[1]);
// todo: parse the xml properly
preg_match('/<title>(.*)<\/title>/', $xdata, $xmatches);
$iptc['Title'] = substr($xmatches[1], 0, 255);
} elseif ($CONFIG['read_iptc_data']) {
$iptc = get_IPTC($path_to_image);
}
- OPTIONAL -
Now if you want to fetch more data from youtube (duration, view count, youtube upload time, our update time) you can use the following code.
Unless you make your own modifications to other (theme) scripts that data won't be used at all !
I use the "user4" user picture data field to store that data. The user data field name does not need to be set, it can be left empty so it won't appear on the upload forms or in the picture info table.
Needless to say that if you "user4" field is in use it will mess things up.. Of course you can use any other userX data field if you know how to change that bit of code.. (replace all "user4"/"field4" you see by your "userX"/"fieldX" value)
Locate :
if(!empty($CONFIG['user_field4_name'])) {
there are two of them, you can replace both, but in my case the first one is never used.
Replace it with :
// youtube/video flag
if (preg_match('/^youtube_.*\.jpg$/', $file_set[0])){
// youtube video duration
preg_match('/<length_seconds>([0-9]*)<\/length_seconds>/', $xdata, $xmatches);
$yt_flag_data = $xmatches[1]."|";
// youtube view count
preg_match('/<view_count>([0-9]*)<\/view_count>/', $xdata, $xmatches);
$yt_flag_data .= $xmatches[1]."|";
// youtube upload time
preg_match('/<upload_time>([0-9]*)<\/upload_time>/', $xdata, $xmatches);
$yt_flag_data .= $xmatches[1]."|";
// our update time
$yt_flag_data .= time();
$form_array[] = array('user4', $yt_flag_data, 4);
} elseif(!empty($CONFIG['user_field4_name'])) {
the data is stored in the following format : duration_seconds|youtube_view_count|youtube_upload_time|cpg_update_time (ex: 54|95|1168283825|1168676023)
- BUGFIX -
okay there is one tiny bug in the original hack, it may have been discussed/fix elsewhere/before but i had to fix it in my script so..
The bug is the following : the xml file containing all the youtube data is not deleted after the video is added to the gallery.
Locate:
// First, we delete the preview image.
if ((!strstr($preview_path, 'thumb')) and (file_exists($preview_path))) {
unlink($preview_path);
Insert BELOW:
// youtube xml data cleanup
if (preg_match('/^youtube_(.*)\.jpg$/', $file_set[0], $ytmatches)){
if (file_exists("albums/edit/yt_".$ytmatches[1].".xml")) {
unlink("albums/edit/yt_".$ytmatches[1].".xml");
}
}
- Known unfixed BUG -
Using the hack to test my modifications i also found another bug.
If you upload the same video twice, the upload process will succeed without errors (preview & thumbs ok) but the actual video won't work because cpg upload process will change the "picture" filename of the video in order not to overwrite the existing one and so it will also change the url of the video, pointing to a non existing video.
well that's about it
hope it helps..