March 21, 2010, 03:27:11 am *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: cpg1.4.26 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.4.25 or older update to this latest version as soon as possible.
[more]
   Home   Help Search Board rules Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Displaying videos from Youtube in Coppermine without fopen & Youtube dev API ID  (Read 7961 times)
0 Members and 1 Guest are viewing this topic.
Αndré Topic starter
Dev Team member
****
Gender: Male
Germany Germany

Posts: 2598


aka eenemeenemuu


« on: February 25, 2009, 08:37:56 am »

Because Nibbler's Youtube mod doesn't work for me (I'm using a freehoster with PHP URL fopen disabled), I created another method to "upload" Youtube videos to your Coppermine gallery.

Open themes/<yourtheme>/theme.php and copy the function theme_html_picture() from themes/sample/theme.php to your theme.php, if it isn't already there.

Search
Code:
        $pic_html  = '<object id="'.$player['id'].'" '.$player['clsid'].$player['codebase'].$player['mime'].$image_size['whole'].'>';
        $pic_html .= "<param name=\"autostart\" value=\"$autostart\" /><param name=\"src\" value=\"". $picture_url . "\" />";
        $pic_html .= '<embed '.$image_size['whole'].' src="'. $picture_url . '" autostart="'.$autostart.'" '.$player['mime'].'></embed>';
        $pic_html .= "</object><br />\n";
and replace it with
Code:
        if ($mime_content['extension'] == "youtube") {
            // get content of .youtube file
            $youtube_file_content = file_get_contents($picture_url);
            // remove apostrophes and quotes
            $youtube_file_content = str_replace("'", "", $youtube_file_content);
            $youtube_file_content = str_replace("\"", "", $youtube_file_content);
            // get youtube video id
            $youtube_file_content = str_replace("http://www.youtube.com/watch?v=", "", $youtube_file_content);
            $youtube_file_content = explode("&", $youtube_file_content);
            $youtube_video_id = $youtube_file_content[0];
            // check if video id is valid
            if (strlen($youtube_video_id) == "11") {
                $youtube_check_result = preg_match("/[A-Za-z0-9_-]{11}/", $youtube_video_id, $youtube_video_id_valid);
            }
            // embed video or print error message
            if ($youtube_check_result == "1" ) {
                $pic_html = "<embed type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" width=\"640\" height=\"385\" src=\"http://www.youtube.com/v/{$youtube_video_id_valid[0]}&hl=de&fs=1\" />";
            } else {
                $pic_html = "Error: no valid youtube video id";
            }
        } else {
            $pic_html  = '<object id="'.$player['id'].'" '.$player['clsid'].$player['codebase'].$player['mime'].$image_size['whole'].'>';
            $pic_html .= "<param name=\"autostart\" value=\"$autostart\" /><param name=\"src\" value=\"". $picture_url . "\" />";
            $pic_html .= '<embed '.$image_size['whole'].' src="'. $picture_url . '" autostart="'.$autostart.'" '.$player['mime'].'></embed>';
            $pic_html .= "</object><br />\n";
        }

Next you have to add the filetype ".youtube" to the database. Download the attached file, copy it to your cpg root directory and call it in your browser.

To add a Youtube video to your gallery, you have to create a file with the extension ".youtube". The file should contain the youtube video ID (e.g. if you watch the video http://www.youtube.com/watch?v=6B26asyGKDo, the video ID is 6B26asyGKDo). The whole youtube url should also work, but if you copy only the ID into your file, you are on the safe side.

At least check if the youtube filetype is allowed in the config. If all is done, you can upload your .youtube files like every other file.

The thumbnail for the video can be created as described here.
« Last Edit: February 26, 2009, 08:29:28 am by eenemeenemuu » Logged

Nibbler
Dev Team member
****
Gender: Male
United Kingdom United Kingdom

Posts: 19610



WWW
« Reply #1 on: February 25, 2009, 03:52:49 pm »

You should check that the format of the video ID is valid before you use it for security reasons.
Logged

I don't care about what they say, I won't live or die that way.
Αndré Topic starter
Dev Team member
****
Gender: Male
Germany Germany

Posts: 2598


aka eenemeenemuu


« Reply #2 on: February 25, 2009, 03:57:43 pm »

Any hint where to begin? I've never dealt with this before Lips sealed

The only idea I have is deleting all " and ' . Which security issues do you see in my mod?
« Last Edit: February 25, 2009, 04:51:51 pm by eenemeenemuu » Logged

Αndré Topic starter
Dev Team member
****
Gender: Male
Germany Germany

Posts: 2598


aka eenemeenemuu


« Reply #3 on: February 26, 2009, 08:34:29 am »

I added some lines in my first post. It extracts the video id and checks for string length and unvalid characters.
Can you evaluate my changes Nibbler? Is it a security improvement?
Logged

Cath22
Coppermine regular visitor
**
Posts: 62


« Reply #4 on: February 26, 2009, 01:25:56 pm »

Hi there,

Will this also work for other sites, like for instance Yahoo? I have some videos there I would like to share.

Thanks in advance
Greetz
Cath
Logged
Αndré Topic starter
Dev Team member
****
Gender: Male
Germany Germany

Posts: 2598


aka eenemeenemuu


« Reply #5 on: February 26, 2009, 01:44:35 pm »

This method should work for all websites that provide an embed code for their videos. Currently my mod supports Youtube only.

The whole idea is, that the user uploads a file with a video id. Coppermine reads this video id out of the file and places it in the given html embed code. The result is the embed code with the video id, that looks just as the provided embed code of the according website.

The code for Yahoo video could look like:
Code:
        if ($mime_content['extension'] == "yahoo") {
            $pic_html = '<embed src="http://d.yimg.com/static.video.yahoo.com/yep/YV_YEP.swf?ver=2.2.34" type="application/x-shockwave-flash" width="512" height="322" allowFullScreen="true" AllowScriptAccess="always" bgcolor="#000000" flashVars="id='.file_get_contents($picture_url).'&embed=1" />';
        }
Of course the filetype has to be added to the database, too. This has not been tested and is beyond the intention of this mod.


If you understand how this method works, it should be very easy to adapt it to your needs.
Logged

Cath22
Coppermine regular visitor
**
Posts: 62


« Reply #6 on: February 26, 2009, 02:37:53 pm »

This method should work for all websites that provide an embed code for their videos. Currently my mod supports Youtube only.

The whole idea is, that the user uploads a file with a video id. Coppermine reads this video id out of the file and places it in the given html embed code. The result is the embed code with the video id, that looks just as the provided embed code of the according website.


If you understand how this method works, it should be very easy to adapt it to your needs.

I'm not completely sure how it works, but hell I'll give it a try,  Grin we'll keep on triying to make it all better right.
Thanks for your reply.

Cath
Logged
concreto
Coppermine novice
*
Gender: Male
Ecuador Ecuador

Posts: 26


WWW
« Reply #7 on: May 25, 2009, 04:27:53 am »

hi
any one could post a demo  to see if there´s any diffrenece with nibbler´s method...
Logged

CPG RULES
Αndré Topic starter
Dev Team member
****
Gender: Male
Germany Germany

Posts: 2598


aka eenemeenemuu


« Reply #8 on: May 26, 2009, 09:49:23 am »

There's no difference in displaying the video.

Example with Nibbler's mod: http://gelipo.com/members/Nibbler/pictures/61993
Example with my mod: http://eenemeenemuu.ee.funpic.de/cpg14x/displayimage.php?pos=-2


My mod lacks of these features:
A new section appears on the upload page where you enter the URL of the video.
You have to create a file with the extension '.youtube' and upload it (like an image) with my mod.

Coppermine will use the video thumbnail and title/caption/keywords from Youtube when adding the video.
This isn't possible with PHP URL fopen disabled.
Logged

concreto
Coppermine novice
*
Gender: Male
Ecuador Ecuador

Posts: 26


WWW
« Reply #9 on: May 27, 2009, 04:35:39 am »

ok thanks i´ll try your method soon.... looks good
Logged

CPG RULES
Joachim Müller
Administrator
*****
Gender: Male
Germany Germany

Posts: 46240


aka "GauGau"


WWW
« Reply #10 on: May 27, 2009, 06:43:44 am »

Gelipo is not a good example - they deliberately hide the "Powered by Coppermine" tag, which makes their hacked copy of Coppermine an illegal one. They have been made aware of this, but they ignore the fact that they're running an illegal version. They fail to give credit where credit is due, which is just lame imo. I suggest not to advertize their site as an example for anything except as for silly and rude behaviour.
Logged
Αndré Topic starter
Dev Team member
****
Gender: Male
Germany Germany

Posts: 2598


aka eenemeenemuu


« Reply #11 on: May 27, 2009, 06:54:28 am »

Thanks for the hint Joachim. I hadn't noticed that they hide out footer. I just copied the link out of Nibbler's announcement thread.

//Edit: They hide the tag, but they display an image instead. See attachment.
Logged

Nibbler
Dev Team member
****
Gender: Male
United Kingdom United Kingdom

Posts: 19610



WWW
« Reply #12 on: May 27, 2009, 11:45:21 am »

I've put back the text link. Logo was nicer though I thought.
Logged

I don't care about what they say, I won't live or die that way.
top10ufo
Coppermine newbie

United States United States

Posts: 7

www.top10ufo.com


WWW
« Reply #13 on: October 06, 2009, 08:20:54 pm »

Thanks for this mod, Αndré. My host doesn't allow fopen, so this is great. It's going to save me alot of bandwidth now as well instead of hosting the videos myself.

 Grin Thanks again!  Grin

You can see the mod in action here:
http://www.top10ufo.com/photos/index.php?cat=5
Logged
timbuktu
Coppermine newbie

Pakistan Pakistan

Posts: 4


« Reply #14 on: November 11, 2009, 02:16:08 am »

kindly tell me in which root should we put the add_filetyp.php ?? in theme or in public_html?? Thanks with Regards
Logged
Αndré Topic starter
Dev Team member
****
Gender: Male
Germany Germany

Posts: 2598


aka eenemeenemuu


« Reply #15 on: November 11, 2009, 08:04:22 am »

copy it to your cpg root directory
= your Coppermine directory where e.g. index.php is located.
Logged

timbuktu
Coppermine newbie

Pakistan Pakistan

Posts: 4


« Reply #16 on: November 12, 2009, 07:38:56 am »

Andre , Could you please tell me that if i'm using different template in which there is no such code you told us to find and replace with the code give, then what should i do ?? you can see that attached file with name theme, kindly let me know i'll be really very thankful to you,

With Regards,
Nomi
Logged
Αndré Topic starter
Dev Team member
****
Gender: Male
Germany Germany

Posts: 2598


aka eenemeenemuu


« Reply #17 on: November 12, 2009, 08:21:21 am »

Andre , Could you please tell me that if i'm using different template in which there is no such code you told us to find and replace with the code give, then what should i do ??
Read my instructions in the initial post!

Logged

DigiMajik
Coppermine newbie

United States United States

Posts: 1


« Reply #18 on: January 03, 2010, 05:43:31 am »

Thanks for this mod and the outstanding documentation.

http://www.thewarcenter.net/gallery/
Logged
dmosley
Coppermine newbie

United States United States

Posts: 1


« Reply #19 on: March 07, 2010, 11:07:42 pm »

Thanks for the mod! Worked like a charm!
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC
Page created in 0.097 seconds with 19 queries.