Advanced search  

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Pages: [1] 2 3 4 5 ... 22   Go Down

Author Topic: Displaying videos from Youtube in Coppermine.  (Read 431848 times)

0 Members and 1 Guest are viewing this topic.

Nibbler

  • Guest
Displaying videos from Youtube in Coppermine.
« on: October 31, 2006, 03:42:27 am »

This mod allows you to embed Youtube videos in your Coppermine gallery. A new section appears on the upload page where you enter the URL of the video. Coppermine will use the video thumbnail and title/caption/keywords from Youtube when adding the video.


Demo: http://gelipo.com/members/Nibbler/pictures/61993

To use this mod you will need some extra things:


Files to be changed: upload.php, theme.php

upload.php, add this code near the top of the file after the comments (you can skip this step if you have PHP5)

Code: [Select]
if (!function_exists('file_put_contents')) {
function file_put_contents($n,$d) {
$f=@fopen($n,"w");
if (!$f) {
return false;
} else {
fwrite($f,$d);
fclose($f);
return true;
}
}
}

Then find

Code: [Select]
            // Add the control device.
            $form_array[] = array('control', 'phase_1', 4);
           

before it, add
           
Code: [Select]
           // Youtube
           if (USER_ID) {
            $form_array[] = 'Youtube uploads';
              $form_array[] = array('', 'YT_array[]', 0, 256, 3);
              $form_array[] = 'Note: YouTube videos must be added in the form http://www.youtube.com/watch?v=xxxxxxxxxxx';
}
         
         
Find         

Code: [Select]
//Now we must prepare the inital form for adding the pictures to the database, and we must move them to their final location.         
before it, add
         
Code: [Select]
    // youtube
   
   $YT_array = count($_POST['YT_array']);

if ($YT_array) {
$YT_failure_array = array();

for ($counter = 0; $counter < $YT_array; $counter++) {

// Create the failure ordinal for ordering the report of failed uploads.

$failure_cardinal = $counter + 1;

$failure_ordinal = ''.$failure_cardinal.'. ';
           
$YT_URI = $_POST['YT_array'][$counter];

if (!$YT_URI) continue;


if (preg_match('/youtube\.com\/watch\?v=(.*)/', $YT_URI, $matches)){

$vid = $matches[1];
                     
$xurl = "http://www.youtube.com/api2_rest?method=youtube.videos.get_details&dev_id=xxxxxxxxxxx&video_id=$vid";
                     
$xdata = file_get_contents($xurl);

file_put_contents($CONFIG['fullpath'] . "edit/yt_$vid.xml", $xdata);

// todo: parse the xml properly
if (preg_match('/<thumbnail_url>(.*)<\/thumbnail_url>/', $xdata, $xmatches)){

$thumbnail = $xmatches[1];

$rh = fopen($thumbnail, 'rb');
$wh = fopen($CONFIG['fullpath'] . "edit/yt_$vid.jpg", 'wb');


        while (!feof($rh)) fwrite($wh, fread($rh, 1024));

fclose($rh);
fclose($wh);
     
$escrow_array[] = array('actual_name'=>"youtube_$vid.jpg", 'temporary_name'=> "yt_$vid.jpg");

} else {
$YT_failure_array[] = array( 'failure_ordinal'=>$failure_ordinal, 'URI_name'=> $YT_URI, 'error_code'=> $xdata);
}
             
             } else {
                 $YT_failure_array[] = array( 'failure_ordinal'=>$failure_ordinal, 'URI_name'=> $YT_URI, 'error_code'=> 'Failed to find video');
             }
         }
     }



In the block of code above, you must replace xxxxxxxxxxx with your youtube developer id.
     
Find

Code: [Select]
     
     $zip_error_count = count($zip_failure_array);

After, add

Code: [Select]
     
      $YT_error_count = count($YT_failure_array);
     
Find

Code: [Select]
   
        // Create error report if we have errors.
    if (($file_error_count + $URI_error_count + $zip_error_count) > 0) {
   
Change to

Code: [Select]
   
        // Create error report if we have errors.
    if (($file_error_count + $URI_error_count + $zip_error_count + $YT_error_count) > 0) {
     
Find

Code: [Select]
     
             // Close the error report table.
        endtable()

before it, add
       
Code: [Select]
     
                // Look for YT upload errors.
        if ($YT_error_count > 0) {

            // There are URI upload errors. Generate the section label.
            form_label("YT errors:");
            echo "<tr><td>URI</td><td>Error message</td></tr>";

            // Cycle through the file upload errors.
            for ($i=0; $i < $YT_error_count; $i++) {

                // Print the error ordinal, file name, and error code.
                echo "<tr><td>{$YT_failure_array[$i]['failure_ordinal']} {$YT_failure_array[$i]['URI_name']}</td><td>{$YT_failure_array[$i]['error_code']}</td></tr>";

            }

        }
       
Find

Code: [Select]
       
                $form_array = array(
        sprintf($lang_upload_php['max_fsize'], $CONFIG['max_upl_size']),
        array($lang_upload_php['album'], 'album', 2),
        array('MAX_FILE_SIZE', $max_file_size, 4),
        array($lang_upload_php['picture'], 'userpicture', 1, 1),
        array($lang_upload_php['pic_title'], 'title', 0, 255, 1),
        array($captionLabel, 'caption', 3, $CONFIG['max_img_desc_length']),
        array($lang_upload_php['keywords'], 'keywords', 0, 255, 1),
        array('event', 'picture', 4)
        );

Change to
       
Code: [Select]
       
        if (preg_match('/^youtube_(.*)\.jpg$/', $file_set[0], $ytmatches)){

         $vid = $ytmatches[1];

$xdata = file_get_contents($CONFIG['fullpath'] . "edit/yt_$vid.xml");


// todo: parse the xml properly
preg_match('/<description>(.*)<\/description>/', $xdata, $xmatches);
$description = substr($xmatches[1], 0, $CONFIG['max_img_desc_length']);

// todo: parse the xml properly
preg_match('/<tags>(.*)<\/tags>/', $xdata, $xmatches);
$keywords = $xmatches[1];

// todo: parse the xml properly
preg_match('/<title>(.*)<\/title>/', $xdata, $xmatches);
$title = substr($xmatches[1], 0, 255);


                $form_array = array(
        array($lang_upload_php['album'], 'album', 2),
        array($lang_upload_php['pic_title'], 'title', 0, 255, 1, $title),
        array($captionLabel, 'caption', 3, $CONFIG['max_img_desc_length'], $description),
        array($lang_upload_php['keywords'], 'keywords', 0, 255, 1, $keywords),
    array('control', 'phase_2', 4),
    array('unique_ID', $_POST['unique_ID'], 4),
        );
       
   
    } else {

                $form_array = array(
        sprintf($lang_upload_php['max_fsize'], $CONFIG['max_upl_size']),
        array($lang_upload_php['album'], 'album', 2),
        array('MAX_FILE_SIZE', $max_file_size, 4),
        array($lang_upload_php['picture'], 'userpicture', 1, 1),
        array($lang_upload_php['pic_title'], 'title', 0, 255, 1),
        array($captionLabel, 'caption', 3, $CONFIG['max_img_desc_length']),
        array($lang_upload_php['keywords'], 'keywords', 0, 255, 1),
        array('event', 'picture', 4)
        );

}

theme.php (if you can't find this code, copy theme_html_picture() over from sample theme and then apply the change)

Find

Code: [Select]
if (isset($image_size['reduced'])) {

Change to

Code: [Select]

      if (preg_match('/^youtube_(.*)\.jpg$/', $CURRENT_PIC_DATA['filename'], $ytmatches)){
   
    $vid = $ytmatches[1];
      $pic_html = '<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/'. $vid . '"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/'. $vid . '" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object><br />';
   
    } elseif (isset($image_size['reduced'])) {


If you get this message when you upload:

Quote
     
        1YouTube internal error. Please report this issue -- including the exact method of producing this error -- to YouTube.

then your dev_id is probably wrong.
« Last Edit: April 02, 2008, 10:37:45 am by Nibbler »
Logged

freynolds

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 30
Re: Displaying videos from Youtube in Coppermine.
« Reply #1 on: October 31, 2006, 03:45:25 am »

THANKS!
Logged

Gilbert

  • Coppermine newbie
  • Offline Offline
  • Gender: Male
  • Posts: 3
Re: Displaying videos from Youtube in Coppermine.
« Reply #2 on: October 31, 2006, 10:32:45 am »

Thanks, I'll try that next week.
I was also busy with a solution but yours is more professional and with euchm neat code, and I hadn't a solution for the thumbnails.

Logged

ninocass

  • Coppermine newbie
  • Offline Offline
  • Posts: 7
Re: Displaying videos from Youtube in Coppermine.
« Reply #3 on: October 31, 2006, 04:59:33 pm »

Many thanks for the time you have spent coding this :)

However im getting the following error:

Code: [Select]
Fatal error: Call to undefined function: file_put_contents() in /home/fhlinux192/n/nino.fruitvalestudios.com/user/htdocs/gallery/upload.php on line 2064

Many thanks

Antonio
Logged

Nibbler

  • Guest
Re: Displaying videos from Youtube in Coppermine.
« Reply #4 on: October 31, 2006, 06:03:16 pm »

You don't have PHP5 - read what I said.
Logged

Iced Coffee

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 128
Re: Displaying videos from Youtube in Coppermine.
« Reply #5 on: November 01, 2006, 07:51:51 am »

What about photobucket.com? Can I link videos from photobucket the same way? or what should I modify?
Logged

Nibbler

  • Guest
Re: Displaying videos from Youtube in Coppermine.
« Reply #6 on: November 01, 2006, 01:53:09 pm »

No idea.
Logged

netager

  • Coppermine newbie
  • Offline Offline
  • Posts: 4
Re: Displaying videos from Youtube in Coppermine.
« Reply #7 on: November 02, 2006, 02:57:15 am »

Great forum here - I found all answers here even without registration... :)
Quote
PHP 5 (I will review this later, it is only required for convenience)
Any update on this? I have PHP 4.4.1 and really like to have this mod.
Thanks :)
Logged

Nibbler

  • Guest
Re: Displaying videos from Youtube in Coppermine.
« Reply #8 on: November 02, 2006, 02:59:15 am »

Try adding this code into the top of upload.php

Code: [Select]
if (!function_exists('file_put_contents')) {
function file_put_contents($n,$d) {
  $f=@fopen($n,"w");
  if (!$f) {
   return false;
  } else {
   fwrite($f,$d);
   fclose($f);
   return true;
  }
}
}
« Last Edit: November 03, 2006, 03:45:10 am by Nibbler »
Logged

Iced Coffee

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 128
Re: Displaying videos from Youtube in Coppermine.
« Reply #9 on: November 02, 2006, 04:34:06 am »

No idea.

Too bad for me then as I prefer to use photobucket. youtube is good but they reduce the quality of the movies badly.
Logged

netager

  • Coppermine newbie
  • Offline Offline
  • Posts: 4
Re: Displaying videos from Youtube in Coppermine.
« Reply #10 on: November 02, 2006, 04:44:39 am »

Nibbler, thank you :) That was quick.
I'll try it tomorrow and report how it works :)
Logged

Pascal YAP

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: fr
  • Offline Offline
  • Gender: Male
  • Posts: 13833
  • Hello World :-)
    • CPG 1.5.x ExperiMental website
Re: Displaying videos from Youtube in Coppermine.
« Reply #11 on: November 02, 2006, 09:16:47 am »

Displaying videos from Youtube in Coppermine in French.

Morning Nibbler, All ozers,

  This MOD/HACK in our French board (in French)

Thanx

PYAP
« Last Edit: November 02, 2006, 09:31:03 am by PYAP »
Logged

netager

  • Coppermine newbie
  • Offline Offline
  • Posts: 4
Re: Displaying videos from Youtube in Coppermine.
« Reply #12 on: November 03, 2006, 03:35:40 am »

Heh... I don't know if I did everything right, but... I got this trying to open Upload page:

Code: [Select]
Parse error: parse error, unexpected $ in /home/xxxxxxxxx/public_html/gallery/upload.php on line 2702
Logged

kegobeer

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 4637
  • Beer - it does a body good!
    • The Kazebeer Family Website
Re: Displaying videos from Youtube in Coppermine.
« Reply #13 on: November 03, 2006, 03:42:07 am »

Heh... I don't know if I did everything right, but... I got this trying to open Upload page:

Code: [Select]
Parse error: parse error, unexpected $ in /home/xxxxxxxxx/public_html/gallery/upload.php on line 2702

You didn't.  Review your changes and make sure you did everything correctly.  Most likely you forgot a curly bracket or a semicolon somewhere.
Logged
Do not send me a private message unless I ask for one.  Make your post public so everyone can benefit.

There are no stupid questions
But there are a LOT of inquisitive idiots

Nibbler

  • Guest
Re: Displaying videos from Youtube in Coppermine.
« Reply #14 on: November 03, 2006, 03:46:03 am »

Actually, I did. I have modified my previous post with the fix.

http://forum.coppermine-gallery.net/index.php?topic=37962.msg179381#msg179381
Logged

netager

  • Coppermine newbie
  • Offline Offline
  • Posts: 4
Re: Displaying videos from Youtube in Coppermine.
« Reply #15 on: November 03, 2006, 05:05:27 am »

Thenk you :) Now it works! Awe-e-e-esome :)
Logged

h4nh4n

  • Translator
  • Coppermine novice
  • **
  • Offline Offline
  • Gender: Male
  • Posts: 38
  • God loves you!
    • Indonesian Actress
Re: Displaying videos from Youtube in Coppermine.
« Reply #16 on: November 04, 2006, 09:13:47 am »

Nice scripts, however when uploading I got this message
Code: [Select]
0 uploads were successful.
What's wrong with that?



___________edit____________
OMG! I just realized, I can't upload images/photos from the url as well, as I'm never use this one before (always using batch add)

_________________________
My bad, allow_url_fopen is off, I'll ask my hosting provider to change it.
« Last Edit: November 04, 2006, 01:21:13 pm by h4nh4n »
Logged
Artis Indonesia - Albums of Indonesian Actresses
Johan Ng - Personal Website

h4nh4n

  • Translator
  • Coppermine novice
  • **
  • Offline Offline
  • Gender: Male
  • Posts: 38
  • God loves you!
    • Indonesian Actress
Re: Displaying videos from Youtube in Coppermine.
« Reply #17 on: November 05, 2006, 02:10:44 pm »

Hi Nibbler,
I am confused with theme.php which theme.php should we change, the ones we use for default template or only on /sample/theme.php ?


Thank you



Don't worry I solved the problem :) works like charming!

h4nh4n
« Last Edit: November 05, 2006, 02:28:12 pm by h4nh4n »
Logged
Artis Indonesia - Albums of Indonesian Actresses
Johan Ng - Personal Website

h4nh4n

  • Translator
  • Coppermine novice
  • **
  • Offline Offline
  • Gender: Male
  • Posts: 38
  • God loves you!
    • Indonesian Actress
Re: Displaying videos from Youtube in Coppermine.
« Reply #18 on: November 06, 2006, 09:18:03 am »

Hi Nibbler, I guess mine has a problem now... After I installed this mod I can't use batch-add anymore...

When I selected the folder in batch-add, the thumbnail didn't show up, but the links to images are working fine... When I tried insert to an album I got an error message saying "click for details or to reload" I clicked and nothing changes.

Have you test yours one? or maybe its only happened to me?

__________________________
And another one, does it effect to sitemap as well? http://www.cariartis.com/sitemap.php <<< check this out, I just realized when I visited google.com/webmaster and suprised an error with my sitemap...
Code: [Select]
This Sitemap has the following errors:
Leading whitespace
We've detected that your Sitemap file begins with whitespace. We've accepted the file, but you may want to remove the whitespace so that the file adheres to the XML standard.



h4nh4n
« Last Edit: November 06, 2006, 10:18:20 am by h4nh4n »
Logged
Artis Indonesia - Albums of Indonesian Actresses
Johan Ng - Personal Website

Nibbler

  • Guest
Re: Displaying videos from Youtube in Coppermine.
« Reply #19 on: November 06, 2006, 12:31:50 pm »

You probably added some whitespace at the end of your theme.php by accident.
Logged
Pages: [1] 2 3 4 5 ... 22   Go Up
 

Page created in 0.037 seconds with 20 queries.