Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I fetch youtube title and description from given url using python code?

How do I fetch youtube title and description from python code from the given url. Is it necessory to use youtube API for it? I am writing a program which need to find generate title and description from given url

like image 516
Tachyons Avatar asked Jul 04 '12 01:07

Tachyons


People also ask

How do I extract data from a YouTube channel using Python?

Python Script to Get Information from YouTubeFirst, we import the required libraries. To move further, we create the HTTP session. Now, we create a function that will return all the data in a dictionary. In the above method, we download the HTML code of the web page.


1 Answers

It is not necessary, but it is probably significantly quicker and easier than writing your own.

For more information, see https://developers.google.com/youtube/1.0/developers_guide_python

After installing the gdata module, try

import gdata.youtube
import gdata.youtube.service

yt_service = gdata.youtube.service.YouTubeService()

# authorize - you need to sign up for your own access key, or be rate-limited
# yt_service.developer_key = 'ABCxyz123...'
# yt_service.client_id = 'My-Client_id'

def PrintEntryDetails(entry):
    print 'Video title: %s' % entry.media.title.text
    print 'Video published on: %s ' % entry.published.text
    print 'Video description: %s' % entry.media.description.text
    print 'Video category: %s' % entry.media.category[0].text
    print 'Video tags: %s' % entry.media.keywords.text
    print 'Video watch page: %s' % entry.media.player.url
    print 'Video flash player URL: %s' % entry.GetSwfUrl()
    print 'Video duration: %s' % entry.media.duration.seconds

for entry in yt_service.GetTopRatedVideoFeed().entry:
    PrintEntryDetails(entry)
like image 68
Hugh Bothwell Avatar answered Sep 25 '22 19:09

Hugh Bothwell