Jump to content

[SOLVED] Needing Youtube thumb nail fix.


NightZ

Recommended Posts

If i change my code like this.

from

$ytvids[$ytid]['thumb']=str_replace("http://img.youtube.com/watch?v=","http://img.youtube.com/vi/",$ytvids[$ytid]['thumb']);

$ytvids[$ytid]['link']=str_replace("watch?vi=","vi/",$ytattr['URL']);

$ytvids[$ytid]['thumb'].="default.jpg';

}

}

 

 

To

 

$ytvids[$ytid]['thumb']=str_replace("http://img.youtube.com/watch?v=","http://img.youtube.com/vi/",$ytvids[$ytid]['thumb']);

$ytvids[$ytid]['link']=str_replace("watch?vi=","vi/",$ytattr['URL']);

$ytvids[$ytid]['thumb'].="http://img.youtube.com/vi/qGyo8BZ8T0s/default.jpg";

}

}

 

i get

 

http://holybiblez.com/music/video/index.php?search=coldplay&source=all

 

But all the thumbs are the same.

 

My apologies for me being frustrating.

Link to comment
Share on other sites

I don't quite understand why you don't just use the function I proved you with, which works quite fine.

 

<?php
function yt($search)
{
    $xml = new SimpleXMLElement('http://gdata.youtube.com/feeds/videos?vq=' . urlencode($search) . '&start-index=1&max-results=40', null, true);

    $xml->registerXPathNamespace('m', 'http://search.yahoo.com/mrss/');

    $videos = array();
    foreach ($xml->xpath('//m:player') as $player) {
        parse_str(parse_url($player['url'], PHP_URL_QUERY), $query);
        
        $videos[] = array(
            'link' => (string) $player['url'],
            'thumb' => 'http://i.ytimg.com/vi/' . $query['v'] . '/2.jpg',
        );
    }

    return $videos;
}


foreach (yt('test') as $video) {
    echo <<<EOF
<div>
    <a href="{$video['link']}"><img src="{$video['thumb']}"></a>
</div>

EOF;
}

 

Apply your own HTML instead.

Link to comment
Share on other sites

NightZ, you will find people much more responsive when you format your posts appropriately, e.g. use [ CODE ] or [ PHP ] tags.

 

From the Forum Guidelines

4. Users will format posts as best as they can by using proper [ code ][ /code ] or [ php ][ /php ] tags and following Proper Code Indentation guidelines.

 

Note: spaces added to prevent forum from parsing the tags.

Link to comment
Share on other sites

Your code is ok but it doesn't do what i need.

This code gives thumb nails to videos that are not automatic.

(the ones searched by the user)

plus when the user hits the video it redirects them to you-tubes site.(where on my code it pulls in the you-tube video and embeds it on my site page.

 

Link to comment
Share on other sites

You are right and don't understand much.

I didn't write the code,

The code used to work on my site,but youtube changed something at their end and the code stopped working.(leaving me to try and find something that works)

I only no a small amount of php,

 

The code you gave me(i think)if i change the "test" word to another topic it brings in them videos.

i'm not after certain videos, i want all videos.(so the user can pic any video they want and it appears on my site.

i have another view.php which allows the video to embed on another page.

(the site works but the thumbs come through as ....

 

http://img.youtube.com/vi/lOgQyIMX_XU&feature=youtube_gdata/2.jpg

 

the........ &feature=youtube_gdata

is being added to the browser address.(which is causing the problem)

 

i am looking for a way to get around it,so the address comes through as

http://img.youtube.com/vi/YOUTUBEVIDEOCODE/2.jpg

 

When you give me a code,all i do is paste it into the page.

and run it, to see if it works.

 

Your code does this.

http://holybiblez.com/music/video/index.php?search=pop&source=all

 

The search bar doesn't find any videos,and the thumbs appear but link to youtube.

 

Or is this right and i have to edit the code, in some way?

 

 

Link to comment
Share on other sites

The code you gave me(i think)if i change the "test" word to another topic it brings in them videos.

i'm not after certain videos, i want all videos.(so the user can pic any video they want and it appears on my site.

i have another view.php which allows the video to embed on another page.

(the site works but the thumbs come through as ....

 

So then just put in the relevant search terms instead of test, like a variable containing whatever the user entered.

 

When you give me a code,all i do is paste it into the page.

and run it, to see if it works.

 

That is obviously not going to work. It would be impossible for me to write a piece of code that you can just plug in and then it works perfectly.

Link to comment
Share on other sites

" then just put in the relevant search terms instead of test"

 

But isn't that limiting what people can view on the site?

if i haven't added the right word ,they wont see the video.

 

Also the videos link to you-tubes site,

is that what,it is meant to do?

Link to comment
Share on other sites

To be honest, I'm not sure what you're trying to do. You wanted to get YouTube thumbnails and I've written you a function that gives YouTube thumbnails based on specific search terms.

 

If you don't know how to program, then you probably have little chance of fixing this yourself. I would recommend that you make a topic in our freelancing section so you can hire someone to fix it for you.

Link to comment
Share on other sites

Oh right is see,

yes

you have given the right code for that.

This is not what i was looking for, but thanks for your time.

 

The youtube videos all work on my site ,just with out the thumbs.

i can make 1 appear for all searched videos.

 

http://holybiblez.com/music/video/index.php?search=&source=all

 

 

my site uses a search button that lets people ,

look for any of the youtube videos ,and also plays them on my site.

 

I have the feeling ,that if i go through the code you made and the ones others have given, the answer may be in there.

i will also take you advice on looking at the freelancing section.

 

i need to stick to my original code, to keep the site working.

also i know other sites ,like mine (as we have the same script)

will have this same problem.

 

thanks

 

also barrywood said he uses this for his to work.

 

http://img.youtube.com/vi/'.$rec['youtube_Link'].'/default.jpg

 

what is the,

 

.$rec['youtube_Link'].

 

part for

would i need to add a variable

to this?

Link to comment
Share on other sites

Okay, so check this out:

 

<?php
function yt($search, $limit = 40, $startIndex = 1)
{
    $xml = new SimpleXMLElement('http://gdata.youtube.com/feeds/videos?vq=' . urlencode($search) . '&start-index=' . intval($startIndex) . '&max-results=' . intval($limit), null, true);
    
    $videos = array();
    foreach ($xml->xpath('//media:group') as $group) {
        list($player) = $group->xpath('media:player');
        list($title) = $group->xpath('media:title');
        list($thumb) = $group->xpath('media:thumbnail');
        
        $videos[] = array(
            'title' => (string) $title,
            'link' => (string) $player['url'],
            'thumb' => (string) $thumb['url'],
        );
    }

    return $videos;
}

$searchQuery = 'test';

foreach (yt($searchQuery) as $video) {
    $linkUrlencode = urlencode($video['link']);
    echo <<<EOF
<div>
    <a href="view.php?link={$linkUrlencode}"><img src="{$video['thumb']}"></a><br>
    {$video['title']}<br>
    <a href="view.php?link={$linkUrlencode}">>> View <<</a>
    <a href="http://www.hotsmusic.com/video/keep.php?url={$linkUrlencode}">>> Download <<</a>
</div>
EOF;
}

 

You don't get much closer to plug and play. The only thing you'll have to do is:

 

1) Change the HTML so it fits however you want to it to look like.

2) Substitute $searchQuery with whatever the variable with your user's search query is called.

Link to comment
Share on other sites

This has fixed it,

Thank you so much.

 

<?php

function yt($search, $limit = 40, $startIndex = 1)

{

    $xml = new SimpleXMLElement('http://gdata.youtube.com/feeds/videos?vq=' . urlencode($search) . '&start-index=' . intval($startIndex) . '&max-results=' . intval($limit), null, true);

   

    $videos = array();

    foreach ($xml->xpath('//media:group') as $group) {

        list($player) = $group->xpath('media:player');

        list($title) = $group->xpath('media:title');

        list($thumb) = $group->xpath('media:thumbnail');

       

        $videos[] = array(

            'title' => (string) $title,

            'link' => (string) $player['url'],

            'thumb' => (string) $thumb['url'],

        );

    }

 

    return $videos;

}

 

$searchQuery = 'Christian';

 

foreach (yt($searchQuery) as $video) {

    $linkUrlencode = urlencode($video['link']);

    echo <<<EOF

EOF;

}

 

 

http://holybiblez.com/music/video/index.php?search=denmark&source=all

 

 

If you send me a banner.

or something you want me to advertise on my site's,I will put them on my site's (free)

for you as a thank you.

NightZ

 

Once again

Thank you so much for your help.

i would never ,have been able to correct it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.