Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1 from kaip/master

Video Responses
  • Loading branch information...
commit 230696082b711750c12ddd76d6645ac6a0cc521f 2 parents e204afc + 7896f35
@noahsilas authored
Showing with 22 additions and 3 deletions.
  1. +22 −3 pytube/client.py
View
25 pytube/client.py
@@ -131,6 +131,10 @@ def __repr__(self):
def __unicode__(self):
return u"<YouTube Video: %s>" % (str(self.id),)
+ def respond_to(self, video_id):
+ self.client.video_response(self.id, video_id)
+
+
class VideoStream(Stream, LinksMixin):
""" Stream for parsing YouTube Video results """
@@ -141,7 +145,8 @@ def _handle_data(self, data):
self.title = data[u'feed'][u'title'][u'$t']
self.updated = yt_ts_to_datetime(data[u'feed'][u'updated'][u'$t'])
self._parse_links(data[u'feed'][u'link'])
- return [Video(self.client, x) for x in data['feed']['entry']]
+ videos = data['feed'].get('entry', ())
+ return [Video(self.client, x) for x in videos]
def __repr__(self):
return "<YouTube VideoStream: %s>" % (self.uri,)
@@ -206,6 +211,7 @@ class Client(object):
YOUTUBE_COMMENTS_URL = 'http://gdata.youtube.com/feeds/api/videos/%(video_id)s/comments'
YOUTUBE_SUBSCRIBE_URL = 'http://gdata.youtube.com/feeds/api/users/default/subscriptions'
YOUTUBE_SUBSCRIPTIONS_URL = 'http://gdata.youtube.com/feeds/api/users/%(username)s/subscriptions?alt=json&v=2'
+ YOUTUBE_RESPONSE_URL = 'http://gdata.youtube.com/feeds/api/videos/%(original_video_id)s/responses'
def __init__(self, app_name, dev_key=None):
self._auth_data = None
@@ -356,16 +362,19 @@ def video(self, video_id):
raise
return Video(self, data[u'entry'])
- def video_search(self, term):
+ def video_search(self, **query):
""" Searches YouTube for videos matching a search term
"""
- return VideoStream(self, self.YOUTUBE_SEARCH_URL, query={'q': term})
+ return VideoStream(self, self.YOUTUBE_SEARCH_URL, query=query)
def video_comments(self, video_id):
""" Gets Comments for a specific video
"""
return CommentStream(self, self.YOUTUBE_COMMENTS_URL % {'video_id': video_id})
+ def video_responses(self, video_id):
+ return VideoStream(self, self.YOUTUBE_RESPONSE_URL % {'original_video_id': video_id})
+
def subscribe(self, username='default'):
"""Subscribes the authenticated user to username's channels
"""
@@ -380,3 +389,13 @@ def subscribe(self, username='default'):
</entry>'''.format(username)
subscribe_headers = { 'Content-Type': 'application/atom+xml'}
response = self._gdata_request(self.YOUTUBE_SUBSCRIBE_URL, None, subscribe_data, subscribe_headers)
+
+ def video_response(self, original_video_id, response_video_id):
+ response_data = \
+ '''<?xml version="1.0" encoding="UTF-8"?>
+ <entry xmlns="http://www.w3.org/2005/Atom">
+ <id>{0}</id>
+ </entry>'''.format(response_video_id)
+ response_headers = { 'Content-Type': 'application/atom+xml'}
+ response = self._gdata_request(self.YOUTUBE_RESPONSE_URL % {'original_video_id': original_video_id }, None, response_data, response_headers)
+
Please sign in to comment.
Something went wrong with that request. Please try again.