YouTube Search Explained 04-13-2014, 03:47 PM
#1
In GiyPy, I used a method that goes to the YouTube api itself, and gets a single video.
When we open the YouTube API, the word/phrase is always in the middle, when specifying the amount of videos we want that is.
Say we wanted http://gdata.youtube.com/feeds/api/videos?q=dubstep_and_shit&racy=include&orderby=relevance&max-results=1, we always replace spaces with underscores.
The API is XML-based, so when opening it we will see something like this.
We only need a few elements from this, however we can always expand.
Here's a run down of some of the basic elements that can be found in this API:
- User who uploaded the video
- Video title
- View count
- Video ID
- Video time length
- Description
- Rating
- Upload date
- Thumbnail
- Category
- MUCH more
I used a splitting method that only grabs data within certain parameters. An example of this would be if I wanted to get everything within <1> and <3>.
This would return <2> after splitting. However, you could say I got lucky. This method can have a LOT of problems. Either way, it works.
Code:
def youtube(query):
try:
xdat = str((urllib.request.urlopen("http://gdata.youtube.com/feeds/api/videos?vq="+query.replace(' ','_')+"&racy=include&orderby=relevance&max-results=1")).read())
if "<openSearch:totalResults>0</openSearch:totalResults>" in (xdat): return "No results."
else:
trash , yclean=(xdat).split("<media:player url='http://www.youtube.com/watch?q=",1)
yclean , trash=yclean.split("&",1)
trash2 , yclean2=(xdat).split("<media:title type='plain'>",1)
yclean2 , trash2=yclean2.split("</media:title>",1)
trash3 , yclean3=(xdat).split(yclean+"'/><author><name>",1)
yclean3 , trash3=yclean3.split("</name>",1)
return yclean2.capitalize()+"\nUploaded by "+yclean3.capitalize()+"\nhttps://www.youtube.com/watch?v="+yclean
except: return "Error"When we open the YouTube API, the word/phrase is always in the middle, when specifying the amount of videos we want that is.
Say we wanted http://gdata.youtube.com/feeds/api/videos?q=dubstep_and_shit&racy=include&orderby=relevance&max-results=1, we always replace spaces with underscores.
The API is XML-based, so when opening it we will see something like this.
Code:
<?xml version='1.0' encoding='UTF-8'?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:gd='http://schemas.google.com/g/2005' xmlns:yt='http://gdata.youtube.com/schemas/2007'><id>http://gdata.youtube.com/feeds/api/videos</id><updated>2014-04-13T14:34:44.900Z</updated><category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#video'/><title type='text'>Videos matching: dubstep_and_shit</title><logo>http://www.gstatic.com/youtube/img/logo.png</logo><link rel='alternate' type='text/html' href='http://www.youtube.com'/><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos'/><link rel='http://schemas.google.com/g/2005#batch' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/batch'/><link rel='self' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos?q=dubstep_and_shit&start-index=1&max-results=1&racy=include&orderby=relevance'/><link rel='next' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos?q=dubstep_and_shit&start-index=2&max-results=1&racy=include&orderby=relevance'/><author><name>YouTube</name><uri>http://www.youtube.com/</uri></author><generator version='2.1' uri='http://gdata.youtube.com'>YouTube data API</generator><openSearch:totalResults>220</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>1</openSearch:itemsPerPage><entry><id>http://gdata.youtube.com/feeds/api/videos/DGrLjISE7bA</id><published>2013-09-30T15:43:16.000Z</published><updated>2014-04-11T19:20:15.000Z</updated><category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#video'/><category scheme='http://gdata.youtube.com/schemas/2007/categories.cat' term='Games' label='Gaming'/><title type='text'>New intro/ Intro nou! Dubstep and shit</title><content type='text'>Melodia: Celldweller - Tough Guy (Tim Ismag Remix) Like la video, Share la altii si Subscribe la mine XD =====================...</content><link rel='alternate' type='text/html' href='http://www.youtube.com/watch?v=DGrLjISE7bA&feature=youtube_gdata'/><link rel='http://gdata.youtube.com/schemas/2007#video.related' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/DGrLjISE7bA/related'/><link rel='http://gdata.youtube.com/schemas/2007#mobile' type='text/html' href='http://m.youtube.com/details?v=DGrLjISE7bA'/><link rel='self' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/DGrLjISE7bA'/><author><name>MrRava12</name><uri>http://gdata.youtube.com/feeds/api/users/MrRava12</uri></author><gd:comments><gd:feedLink rel='http://gdata.youtube.com/schemas/2007#comments' href='http://gdata.youtube.com/feeds/api/videos/DGrLjISE7bA/comments' countHint='14'/></gd:comments><yt:hd/><media:group><media:category label='Gaming' scheme='http://gdata.youtube.com/schemas/2007/categories.cat'>Games</media:category><media:content url='http://www.youtube.com/v/DGrLjISE7bA?version=3&f=videos&app=youtube_gdata' type='application/x-shockwave-flash' medium='video' isDefault='true' expression='full' duration='11' yt:format='5'/><media:content url='rtsp://r2---sn-p5qlsu76.c.youtube.com/CiILENy73wIaGQmw7YSEjMtqDBMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='11' yt:format='1'/><media:content url='rtsp://r2---sn-p5qlsu76.c.youtube.com/CiILENy73wIaGQmw7YSEjMtqDBMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='11' yt:format='6'/><media:description type='plain'>Melodia: Celldweller - Tough Guy (Tim Ismag Remix) Like la video, Share la altii si Subscribe la mine XD =====================...</media:description><media:keywords/><media:player url='http://www.youtube.com/watch?v=DGrLjISE7bA&feature=youtube_gdata_player'/><media:thumbnail url='http://i.ytimg.com/vi/DGrLjISE7bA/0.jpg' height='360' width='480' time='00:00:05.500'/><media:thumbnail url='http://i.ytimg.com/vi/DGrLjISE7bA/1.jpg' height='90' width='120' time='00:00:02.750'/><media:thumbnail url='http://i.ytimg.com/vi/DGrLjISE7bA/2.jpg' height='90' width='120' time='00:00:05.500'/><media:thumbnail url='http://i.ytimg.com/vi/DGrLjISE7bA/3.jpg' height='90' width='120' time='00:00:08.250'/><media:title type='plain'>New intro/ Intro nou! Dubstep and shit</media:title><yt:duration seconds='11'/></media:group><gd:rating average='5.0' max='5' min='1' numRaters='12' rel='http://schemas.google.com/g/2005#overall'/><yt:statistics favoriteCount='0' viewCount='846'/></entry></feed>We only need a few elements from this, however we can always expand.
Here's a run down of some of the basic elements that can be found in this API:
- User who uploaded the video
- Video title
- View count
- Video ID
- Video time length
- Description
- Rating
- Upload date
- Thumbnail
- Category
- MUCH more
I used a splitting method that only grabs data within certain parameters. An example of this would be if I wanted to get everything within <1> and <3>.
Code:
trash,shit = trash.split('<1>',1)
trash,shit = shit.split('<3>',1)This would return <2> after splitting. However, you could say I got lucky. This method can have a LOT of problems. Either way, it works.
![[Image: BXqGARG.png]](https://i.imgur.com/BXqGARG.png)








![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)