示例#1
0
    def getVideos(self):
        videos = []
        logging.debug("YoutubePlaylist getting videos from %s", self.url)

        try:
            urlObj = urllib2.urlopen(self.url)
            data   = urlObj.read()
        except:
            logging.critical("Unable to open " + self.url)
            print youtube.api.PLAYLIST_VIDEOS_ERROR % self.playlist_id 

        dom = xml.dom.minidom.parseString(data)
        try:
            for entry in dom.getElementsByTagName('entry'):
                id = (entry.getElementsByTagName('id')[0]).firstChild.data
                video = YoutubeVideo(id)
                logging.debug("Video id: " + video.id)

                video.title =  \
                    (entry.getElementsByTagName('title')[0]).firstChild.data
                logging.debug("Video title: " + video.title)

                if entry.hasAttribute('published'):
                    video.ctime = \
                        gdataTime2UnixTime((entry.getElementsByTagName('published')[0]).firstChild.data)
                    logging.debug("Video ctime: " + str(video.ctime))

                video.mtime = \
                    gdataTime2UnixTime((entry.getElementsByTagName('updated')[0]).firstChild.data)
                logging.debug("Video mtime: " + str(video.mtime))

                mediaGroup      = (entry.getElementsByTagName('media:group')[0])
                mediaContent    = (mediaGroup.getElementsByTagName('media:content'))

                if mediaContent and \
                        mediaContent[0].getAttribute('type') \
                            == "application/x-shockwave-flash":
                    video.url   =  mediaContent[0].getAttribute('url')
                    video.type  =  mediaContent[0].getAttribute('type')
                if (video.url != ""):        
                    videos.append(video)
        except Exception,inst:
            logging.critical("Invalid video XML format: " + \
                        str(inst))
示例#2
0
class YoutubeUser:
    def __init__(self,username):
        self.__username__ = username

    def getSubscriptions(self):
        subscriptions = []
        url = youtube.api.SUBSCRIPTIONS_URI % (self.__username__)
        logging.debug("YoutubeUser getting subscriptions from %s",url)

        try:
            urlObj = urllib2.urlopen(url)
            data   = urlObj.read()
        except Exception,inst:
            logging.critical("Unable to open " + url)
            logging.critical(str(inst))

        dom = xml.dom.minidom.parseString(data)
        try:
            for entry in dom.getElementsByTagName('entry'):
                id = (entry.getElementsByTagName('id')[0]).firstChild.data
                sub = YoutubeSubscription(id)
                sub.title =  \
                    (entry.getElementsByTagName('title')[0]).firstChild.data
                logging.debug("Subscription title: " + sub.title)

                sub.ctime = \
                    gdataTime2UnixTime((entry.getElementsByTagName('published')[0]).firstChild.data)
                logging.debug("Subscription ctime: " + str(sub.ctime))

                sub.mtime = \
                   gdataTime2UnixTime((entry.getElementsByTagName('updated')[0]).firstChild.data)
                logging.debug("Subscription mtime: " + str(sub.mtime))
                subscriptions.append(sub)

                feedLink = entry.getElementsByTagName('gd:feedLink')
                if feedLink:
                    sub.url = feedLink[0].getAttribute('href')
                    logging.debug("Subscription url " + str(sub.url))                
                subscriptions.append(sub)
        except Exception, inst:            
            logging.critical("Invalid subscription XML format " + \
                        str(inst))
示例#3
0
            logging.critical("Unable to open " + url)
            logging.critical(str(inst))

        dom = xml.dom.minidom.parseString(data)
        try:
            for entry in dom.getElementsByTagName('entry'):
                id = (entry.getElementsByTagName('id')[0]).firstChild.data
                pl = YoutubePlaylist(id)
                logging.debug("Playlist id: " + pl.id)

                pl.title =  \
                    (entry.getElementsByTagName('title')[0]).firstChild.data
                logging.debug("Playlist title: " + pl.title)

                pl.ctime = \
                    gdataTime2UnixTime((entry.getElementsByTagName('published')[0]).firstChild.data)
                logging.debug("Playlist ctime: " + str(pl.ctime))

                pl.mtime = \
                   gdataTime2UnixTime((entry.getElementsByTagName('updated')[0]).firstChild.data)
                logging.debug("Playlist mtime: " + str(pl.mtime))
                playlists.append(pl)
        except Exception, inst:            
            logging.critical("Invalid playlist XML format " + \
                        str(inst))

        return playlists        

    """
        Returns a YoutubePlaylist object containing all
        of the user's favourite videos.