News:

Wondering if this will always be free?  See why free is better.

Main Menu

Ohara YouTube Embed

Started by Suki, December 21, 2011, 03:04:59 PM

Previous topic - Next topic

Kurogane

With Ampersand solved the problem.

Thanks  :)

FemR

Just installed on pretty much vanilla 2.0.2, seems to work great. Simple, easy to use. Thank you!

BigMike

Ok, updated my video title retrieval code with a more simple approach using an XML object that takes 2 less lines:


    $doc = new DOMDocument;
    $doc->load("http://gdata.youtube.com/feeds/api/videos/" . $string);
    $video_title = $doc->getElementsByTagName("title")->item(0)->nodeValue;


Example data from each method...

The former file_get_contents() method:

{
"provider_url": "http:\/\/www.youtube.com\/"
"thumbnail_url": "http:\/\/i1.ytimg.com\/vi\/8mrFkpYKJ6Q\/hqdefault.jpg"
"title": "BigMike's 511:1 Marlin Crawler Parking Stall Burn Out"
"html": "\u003ciframe width=\"480\" height=\"270\" src=\"http:\/\/www.youtube.com\/embed\/8mrFkpYKJ6Q?fs=1\u0026feature=oembed\" frameborder=\"0\" allowfullscreen\u003e\u003c\/iframe\u003e"
"author_name": "MarlinCrawlerMedia"
"height": 270, "thumbnail_width": 480, "width": 480, "version": "1.0"
"author_url": "http:\/\/www.youtube.com\/user\/MarlinCrawlerMedia"
"provider_name": "YouTube"
"type": "video"
"thumbnail_height": 360
}


The new DOMdocument method:

SimpleXMLElement Object
(
    [id] => http://gdata.youtube.com/feeds/api/videos/8mrFkpYKJ6Q
    [published] => 2012-05-02T01:04:14.000Z
    [updated] => 2012-08-01T03:14:03.000Z
    [category] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [scheme] => http://schemas.google.com/g/2005#kind
                            [term] => http://gdata.youtube.com/schemas/2007#video
                        )

                )

            [1] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [scheme] => http://gdata.youtube.com/schemas/2007/categories.cat
                            [term] => People
                            [label] => People & Blogs
                        )

                )

        )

    [title] => BigMike's 511:1 Marlin Crawler Parking Stall Burn Out
    [content] => Our customer Rick Crarey from Canada and Marlin got to check out BigMike's Crawler doing a 511:1 parking stall burn out. The engine is idling at 800 rpm. Triple Marlin Crawler Ultimate Setup
    [link] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [rel] => alternate
                            [type] => text/html
                            [href] => http://www.youtube.com/watch?v=8mrFkpYKJ6Q&feature=youtube_gdata
                        )

                )

            [1] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [rel] => http://gdata.youtube.com/schemas/2007#video.responses
                            [type] => application/atom+xml
                            [href] => http://gdata.youtube.com/feeds/api/videos/8mrFkpYKJ6Q/responses
                        )

                )

            [2] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [rel] => http://gdata.youtube.com/schemas/2007#video.related
                            [type] => application/atom+xml
                            [href] => http://gdata.youtube.com/feeds/api/videos/8mrFkpYKJ6Q/related
                        )

                )

            [3] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [rel] => http://gdata.youtube.com/schemas/2007#mobile
                            [type] => text/html
                            [href] => http://m.youtube.com/details?v=8mrFkpYKJ6Q
                        )

                )

            [4] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [rel] => self
                            [type] => application/atom+xml
                            [href] => http://gdata.youtube.com/feeds/api/videos/8mrFkpYKJ6Q
                        )

                )

        )

    [author] => SimpleXMLElement Object
        (
            [name] => MarlinCrawlerMedia
            [uri] => http://gdata.youtube.com/feeds/api/users/MarlinCrawlerMedia
        )

)


I'm not sure which method is best yet. The DOM method "feels" like it loads faster, but test results prove otherwise.
The former method stores more than 5 times less variable data (621 bytes vs 3,475 bytes)...

Speed test using Firebug, average from 3 tests, loading a forum page with 20 videos:
file_get_contents() method: 12.77 seconds, page size 838.8 kb, 106 requests.
DOMdocument method: 13.82 seconds, size 849.2 kb, 104 requests.

Not sure why the average requests are different, must have something to do with caching.

Anyway, both methods are still slower than whatever vBulletin is doing....

BigMike

pspmichael

I installed this mod on my SMF 2.02 new installation using the package manager.  Everything reported going just fine.  It then it asked if I wanted it installed on my other themes.  I selected all themes I have and installed.  Again it reported everything was fine.  I have no button for adding any videos.  I tried to input the command by hand to see if it would work.  It did not. 
Any suggestions?

Suki

The other themes  setting is just to copy the appropiate you tube image to your custom theme BBC images folder.

Try running again the database file, get the mod, unzip it, find the database.php file, upload it to your forum root folder (where SSI.php is)  and call it with your browser:  myforum.com/database.php

Then make sure you have the appropriate calls to the relevant hooks on your DB, go to phpmyadmin or similar, then your DB then your settings table, you must have  some rows with the following values:

   'integrate_bbc_codes' => 'OYTE_bbc_add_code',
   'integrate_bbc_buttons' => 'OYTE_bbc_add_button',
   'integrate_pre_include' => '$sourcedir/OharaYTEmbed.php',
   'integrate_general_mod_settings' => 'OYTE_settings',
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

pspmichael

I am not a coder so I don't understand some of the things you mentioned.  I tried uninstalling then reinstalling.  Then I copied the database to the root as you suggested and tried to access it as you instructed.  I'm not sure if it actually did anything or not.

I set my SMF BB back to the original theme hoping that would help, no change. 

That makes me wonder if I have something wrong in my installation or does the mod package not work properly with the SMF 2.02?  I took the defaults on everything in my installation.

Suki

Quote from: Suki on September 12, 2012, 06:34:12 PM
try to change this:

function OYTE_bbc_add_button($buttons)

with this:

function OYTE_bbc_add_button(&$buttons)
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

pspmichael

I really hate being a pest, but which file would I find that statement to make the change?

Suki

Oh, my bad, I deleted the part in the quoted message where I said which file, the file its located at Sources/OharaYTEmbed.php
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

CBG

Hi,

How can I add it to support https and http Youtube addresses?

Thanks
SMF version: 2.0.7

Regards,
Garry

Suki

Open Sources/OharaYTEmbed.php  and find:


(http://(?:www\.)?youtu(?:be\.com/watch\?v=|\.be/)(\w*)(&(amp;)?[\w\?=]*)?)


There are 2 instances of this string, make the change to both.

and replace with this:


((http|https)://(?:www\.)?youtu(?:be\.com/watch\?v=|\.be/)(\w*)(&(amp;)?[\w\?=]*)?)


Back up the file first before doing the change as I haven't tested this change.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Sapozhnik

The type of link with Parameters _http://www.youtube.com/watch?v=YFpZ6P6Uv3I&feature=youtu.be doesn't work.  >:( Can you help?

Suki

I actually built the craziest regex I ever wrote for this mod, to support nearly all youtube links, unfortunately, it is lost and I need to start all over again, keep an eye on my site as thats where I will post all future versions.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

BigMike

Quote from: BigMike on October 24, 2012, 11:25:46 AM
Ok, updated my video title retrieval code with a more simple approach using an XML object that takes 2 less lines:


    $doc = new DOMDocument;
    $doc->load("http://gdata.youtube.com/feeds/api/videos/" . $string);
    $video_title = $doc->getElementsByTagName("title")->item(0)->nodeValue;

After doing some more performance tests, I've concluded that the json method is best, so I've switched back and updated my original code that now only uses ONE line:

$video = json_decode(file_get_contents("http://www.youtube.com/oembed?url=http%3A//youtube.com/watch%3Fv%3D".$string."&format=json"), TRUE);

Now just simply use $video['title'] to print out the video's title.

Enjoy
BigMike

BigMike

Other available array data that is 100% ready to use is, for example,


Array
(
    [provider_name] => YouTube
    [width] => 459
    [title] => John drives BigMike's Truck at 511:1 Crawl Ratio
    [author_url] => http://www.youtube.com/user/Husoku
    [version] => 1.0
    [thumbnail_height] => 360
    [provider_url] => http://www.youtube.com/
    [thumbnail_url] => http://i3.ytimg.com/vi/6LoQTme51tA/hqdefault.jpg
    [thumbnail_width] => 480
    [type] => video
    [html] => ****this is the full ready-to-use embed code here****
    [height] => 344
    [author_name] => Husoku
)


BigMike

cerberusenator

Quote from: Suki on December 07, 2012, 01:09:50 PM
Open Sources/OharaYTEmbed.php  and find:


(http://(?:www\.)?youtu(?:be\.com/watch\?v=|\.be/)(\w*)(&(amp;)?[\w\?=]*)?)


There are 2 instances of this string, make the change to both.

and replace with this:


((http|https)://(?:www\.)?youtu(?:be\.com/watch\?v=|\.be/)(\w*)(&(amp;)?[\w\?=]*)?)


Back up the file first before doing the change as I haven't tested this change.

That isn't working...  :'( please help

Suki

Just change that part with another regex, there are literally thousands of examples of how to get a youtube url, pick one and follow the instructions.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

BGH

Is it possible to insert a playlist? I ask because I tried it, in the post preview, but it doesn't seem to do the trick.

I wrote something, then inserted the following:

[youtube]http://www.youtube.com/watch?v=44NFSbjjGl4&list=PLWxJthc4qU_ZF7xNDwcrbQtxlVe3SzKDQ[/youtube]

And it only inserted the first video from the list.

And I thought that it was possible to embed the playlist since I posted something like you mention in your first post:


http://www.youtube.com/watch?v={ID}&{Parameters}


Is not a big issue though, but wanted to know if it's possible to use it for playlists.

Thank you for this mod, Suki :)

Suki

No, it is not possible to insert playlists, the mod simply wasn't designed for that, its just a very simple BBC mod for showing videos.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

BGH


Advertisement: