321 posts
  • Has been part of the Envato Community for over 7 years
  • Has collected 100+ items on Envato Market
  • Located in United States
timmylogue says

Thanks for the reply, I’m using http://codecanyon.net/item/youtube-channel-video-grabber/2658178 It’s a nice class file and I can pretty much get anything from the YouTube API easily…. but! the only issue i’m having is getting PHP to just output an xml structure I need it to do. Which is this:

<playlist title="">
        <item title="" id=""/>
</playlist>

... and after the XML structure is correct to just place the YouTube videos (titles and YouTube ID).

So if that class file outputs 10 youtube videos on the page because that’s what the user has uploaded, I need it to show like this inside the new XML file:

<playlist title="">
     <item title="Video Title 1" id="1vdW3452"/>
     <item title="Video Title 2" id="dSw3435"/>
     <item title="Video Title 3" id="SSDQIRsd"/>
     <item title="Video Title 4" id="SsUq230qqQ"/>
     <item title="Video Title 5" id="MmIy02eEr"/>
     <item title="Video Title 6" id="1vdW3452"/>
     <item title="Video Title 7" id="dSw3435"/>
     <item title="Video Title 8" id="SSDQIRsd"/>
     <item title="Video Title 9" id="SsUq230qqQ"/>
     <item title="Video Title 10" id="MmIy02eEr"/>
</playlist>

I know I probably keep asking the same thing, but It’s literally just the stupidest and probably the simplest issue by just having php getting to output the XML correctly and getting all YouTube videos (titles and ID’s) into the XML. All of them and not just one.

It’s giving me a HUGE headache.

Thanks!

321 posts
  • Has been part of the Envato Community for over 7 years
  • Has collected 100+ items on Envato Market
  • Located in United States
timmylogue says
With the Class file I can easliy call things I need for example, the Youtube video ID
$videoID = $youtube->watch_id($video_url);

So i would just use: $videoID

Here is what the php Class is outputting on the page. (image shown below). \\

I just now need php to generate an XML and add those titles and ID’s inside the XML structure I showed you.

I need that structure because I have a flash XML video player that will read those videos, but it has to be in that XML structure for it to understand :)

Tim

173 posts
  • Has been part of the Envato Community for over 2 years
  • Has sold $100+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
kungfu-themes says

Oh right…

Not tested this but try adding the function to your class.

public function kungFuXML($limit)
{
       $xmlstring = '<?xml version="1.0" encoding="ISO-8859-1"?>
        <root>
          <playlist/> 
        </root>';

     $xml = new SimpleXMLElement($xmlstring);

     //Add the main title
     $xml->playlist[0]->addAttribute("title", "KungFu-themes");

        $i=0;
        while(($video=$this->feed->entry[$i]) && ($i++!=$limit))
        {
            parse_str(parse_url($video->link['href'], PHP_URL_QUERY), $url_query);
            $id =null;
            if ( ! empty($url_query['v']) )
            $id = $url_query['v'];

            $xml->playlist[0]->addChild("item");
            $xml->playlist[0]->item[$i-1]->addAttribute("title", $video->title);
            $xml->playlist[0]->item[$i-1]->addAttribute("id", $id);

        }

         echo('<pre>');
         echo htmlentities($xml->asXML(), ENT_QUOTES);
         echo('</pre>');

}

And calling it would be:

$youtube->kungFuXML(5);
321 posts
  • Has been part of the Envato Community for over 7 years
  • Has collected 100+ items on Envato Market
  • Located in United States
timmylogue says

Darn, I thought that was gonna work. It’s not creating the

$xml->playlist[0]->addChild("item");
$xml->playlist[0]->item[$i-1]->addAttribute("title", $video->title);
$xml->playlist[0]->item[$i-1]->addAttribute("id", $id);

It’s just outputting this.

<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
          <playlist title="KungFu-themes"/> 
</root>

I appreciate all your help so far. You rock.

1 post
  • Has been part of the Envato Community for over 1 year
ambersubdued says

Very nice dude.

321 posts
  • Has been part of the Envato Community for over 7 years
  • Has collected 100+ items on Envato Market
  • Located in United States
timmylogue says

Darn, I thought that was gonna work. It’s not creating the

$xml->playlist[0]->addChild("item");
$xml->playlist[0]->item[$i-1]->addAttribute("title", $video->title);
$xml->playlist[0]->item[$i-1]->addAttribute("id", $id);

It’s just outputting this.

<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
          <playlist title="KungFu-themes"/> 
</root>

I appreciate all your help so far. You rock.

173 posts
  • Has been part of the Envato Community for over 2 years
  • Has sold $100+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
kungfu-themes says

Can you report your entire class and how you’re calling it.

321 posts
  • Has been part of the Envato Community for over 7 years
  • Has collected 100+ items on Envato Market
  • Located in United States
timmylogue says

Yup one sec! :)

Ok, I just sent you an email.

173 posts
  • Has been part of the Envato Community for over 2 years
  • Has sold $100+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
kungfu-themes says

hi just modify your youtube_userFeed.php

to this.

$i = 1;

                $xmlstring = '<?xml version="1.0" encoding="ISO-8859-1"?>
                              <root>
                                    <playlist/> 
                              </root>';

                $xml = new SimpleXMLElement($xmlstring);
                $xml->playlist[0]->addAttribute("title", "timmylogue");

                foreach ($data->entry as $entry)
                {

                    $video_url             = $youtube->get_video_url($entry);
                    $video_thumbnail     = $youtube->get_thumbnail($entry);
                    $video_title        = $youtube->get_title($entry);
                    $video_description    = $youtube->get_description($entry);
                    $video_title        = $youtube->shorten_text($video_title, 5000);
                    $video_description    = $youtube->shorten_text($video_description, 5000);
                    $video_category        = $youtube->get_category($entry);
                    $video_keywords        = $youtube->get_keywords($entry);

                    // Optional, get more information about the video
                    //$info = $youtube->video_info($youtube->watch_id($video_url));
                    $videoID = $youtube->watch_id($video_url);
                    //$views = $info['views'];
                    //$favorites = $info['favorites'];
                    //$dislikes = $info['dislikes'];
                    //$likes = $info['likes'];

                    {
                        //$video_description    = $youtube->shorten_text($video_description, 500);
                        echo '<a href="' . $video_url . '"></a>';
                        echo '<div><a href="' . $video_url . '"><span>' . $video_title . '</span></a></div>';
                        echo '<div><span>' . $videoID . '</span></div>';
                    }

                    $xml->playlist[0]->addChild("item");
                    $xml->playlist[0]->item[$i-1]->addAttribute("title", $video_title);
                    $xml->playlist[0]->item[$i-1]->addAttribute("id", $videoID);

                    $i++;
                }

                 $fp = fopen('youtube_userFeed.xml', 'w');
                 fwrite($fp, $xml->playlist[0]->asXML());

                  fclose($fp);

Upon executing it a new xml will be created in the same directory. Hope this works. Again not had a chance to test it though.

321 posts
  • Has been part of the Envato Community for over 7 years
  • Has collected 100+ items on Envato Market
  • Located in United States
timmylogue says

Yes!!!!!

Worked like a charm! So awesome, thanks dude. Hands down probably the best help I’ve ever gotten on a forum.

You rock!

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by