django_youtube/models.py
def save(self, *args, **kwargs):
        """
        Syncronize the video information on db with the video on Youtube
        The reason that I didn't use signals is to avoid saving the video instance twice.
        """

        # if this is a new instance add details from api
        if not self.id:
            # Connect to api and get the details
            entry = self.entry()

            # Set the details
            self.title = entry.media.title.text
            self.description = entry.media.description.text
            self.keywords = entry.media.keywords.text
            self.youtube_url = entry.media.player.url
            self.swf_url = entry.GetSwfUrl()
            if entry.media.private:
                self.access_control = AccessControl.Private
            else:
                self.access_control = AccessControl.Public

            # Save the instance
            super(Video, self).save(*args, **kwargs)

            # show thumbnails
            for thumbnail in entry.media.thumbnail:
                t = Thumbnail()
                t.url = thumbnail.url
                t.video = self
                t.save()
        else:
            # updating the video instance
            # Connect to API and update video on youtube
            api = Api()

            # update method needs authentication
            api.authenticate()

            # Update the info on youtube, raise error on failure
            api.update_video(self.video_id, self.title, self.description,
                             self.keywords, self.access_control)

        # Save the model
        return super(Video, self).save(*args, **kwargs)
def save(self, *args, **kwargs):
        """
        Syncronize the video information on db with the video on Youtube
        The reason that I didn't use signals is to avoid saving the video instance twice.
        """

        # if this is a new instance add details from api
        if not self.id:
            # Connect to api and get the details
            entry = self.entry()

            # Set the details
            self.title = entry.media.title.text
            self.description = entry.media.description.text
            self.keywords = entry.media.keywords.text
            self.youtube_url = entry.media.player.url
            self.swf_url = entry.GetSwfUrl()
            if entry.media.private:
                self.access_control = AccessControl.Private
            else:
                self.access_control = AccessControl.Public

            # Save the instance
            super(Video, self).save(*args, **kwargs)

            # show thumbnails
            for thumbnail in entry.media.thumbnail:
                t = Thumbnail()
                t.url = thumbnail.url
                t.video = self
                t.save()
        else:
            # updating the video instance
            # Connect to API and update video on youtube
            api = Api()

            # update method needs authentication
            api.authenticate()

            # Update the info on youtube, raise error on failure
            api.update_video(self.video_id, self.title, self.description,
                             self.keywords, self.access_control)

        # Save the model
        return super(Video, self).save(*args, **kwargs)
Syncronize the video information on db with the video on Youtube
        The reason that I didn't use signals is to avoid saving the video instance twice.