A
A
Andrew2015-12-09 18:06:37
YouTube
Andrew, 2015-12-09 18:06:37

Getting list of youtube channel video?

Maybe someone knows how to get the list of video channel using youtube api? I read the documentation, but it didn't really help me.
Well, or at least the algorithm of actions for this case.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Afonin, 2015-12-11
@reli

To get a specific record, next to it there is a selection of the entire list, and you also parse it!

def get_small_image_url(self):
        return 'http://img.youtube.com/vi/%s/%s.jpg' % (self.video_id, random.randint(1, 3))

    def get_hqdefault(self):
        return 'http://i1.ytimg.com/vi/%s/hqdefault.jpg' % self.video_id

    def get_mqdefault(self):
        return 'http://i1.ytimg.com/vi/%s/mqdefault.jpg' % self.video_id

    def get_sddefault(self):
        return 'http://i1.ytimg.com/vi/%s/sddefault.jpg' % self.video_id

    def get_video_id(self, url):
        link = urlparse.urlparse(url)
        if link.hostname == 'youtu.be':
            return link.path[1:]
        if link.hostname in ('www.youtube.com', 'youtube.com'):
            if link.path == '/watch':
                state = urlparse.parse_qs(link.query)
                return state['v'][0]
            if link.path[:7] == '/embed/':
                return link.path.split('/')[2]
            if link.path[:3] == '/v/':
                return link.path.split('/')[2]
        return False

    def get_meta(self, video_id):
        api_token = 'ТУТ ТВОЙ ТОКЕН, ПОЛУЧЕННЫЙ В ГУГЕЛЬ КОНСОЛЬ'
        url = 'https://www.googleapis.com/youtube/v3/videos?part=snippet&id=%s&key=%s' % (video_id, api_token)
        response = json.load(urllib.urlopen(url))
        print response
        context = {
            'title': response['items'][0]['snippet']['localized']['title'],
            'desc': response['items'][0]['snippet']['localized']['description']
        }
        return context

    def save(self, force_insert=False, force_update=False, using=None,
             update_fields=None):
        video_id = self.get_video_id(self.url)
        meta = self.get_meta(video_id)
        self.video_id = video_id
        self.title = meta['title']
        self.description = meta['desc']
        super(Videos, self).save(
            force_insert=force_insert,
            force_update=force_update,
            using=using,
            update_fields=update_fields
        )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question