4

I am using the Zend GData library to manage YouTube videos from within my application. The application gives the user the ability to choose to add the uploaded video to one of their pre-existing YouTube playlists if they desire. One problem is that if the video is subsequently deleted from within our application, it seems to leave an "orphaned" deleted video object within the playlist to which it was added.

I've been trying to figure out a way to have our application remove the video from any playlists before deleting it from YouTube but I am having difficulty figuring out how to determine if a particular YouTube video is contained within playlists.

I've written a function which loops through each entry in each playlist relevant to the logged in user and attempts to compare the video Id of the video in the playlist with a video Id that has been passed as an argument. However, I can't seem to get a value for the video Id for any of the videos in the playlists.

Here's the function:

function remove_video_from_playlists($yt,$hash){

    $playlistListFeed = $yt->getPlaylistListFeed("default");

    foreach ($playlistListFeed as $playlistListEntry) {


        $playlistVideoFeed = $yt->getPlaylistVideoFeed($playlistListEntry->getPlaylistVideoFeedUrl());

        foreach ($playlistVideoFeed as $playlistVideoEntry) {


        //check to see if each video in the playlist matches the video we are trying to delete
            if($playlistVideoEntry->getMediaGroup()->videoId == $hash){

                $playlistVideoEntry->delete();

            }
        }   
    }
}

Any help would be appreciated. How do I get the underlying videoId of each video entry in the playlists?

Keplah
  • 954
  • 2
  • 13
  • 26

2 Answers2

1

I found the issue.

I needed to set the GData library version to version 2 on the $yt object

Used this: $yt->setMajorProtocolVersion(2);

This made all the strange behavior disappear and the usage of $playlistVideoEntry->getMediaGroup()->getVideoId() worked as expected.

  • Thanks, I was almost going insane here. Why isn't the API by default on 2? Duh. BTW, this works for me too: $playlistVideoEntry->getVideoId(); – Narretz Jul 21 '12 at 21:33
0

Have you tried doing

$playlistVideoEntry->getMediaGroup()->getVideoId();

Because from looking in the API, there seems to be such a function that should return exactly what you would need.

Janis Peisenieks
  • 4,938
  • 10
  • 55
  • 85