You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
2.5 KiB

  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. ExtractorError,
  5. unescapeHTML,
  6. )
  7. class FlickrIE(InfoExtractor):
  8. """Information Extractor for Flickr videos"""
  9. _VALID_URL = r'(?:https?://)?(?:www\.)?flickr\.com/photos/(?P<uploader_id>[\w\-_@]+)/(?P<id>\d+).*'
  10. _TEST = {
  11. u'url': u'http://www.flickr.com/photos/forestwander-nature-pictures/5645318632/in/photostream/',
  12. u'file': u'5645318632.mp4',
  13. u'md5': u'6fdc01adbc89d72fc9c4f15b4a4ba87b',
  14. u'info_dict': {
  15. u"description": u"Waterfalls in the Springtime at Dark Hollow Waterfalls. These are located just off of Skyline Drive in Virginia. They are only about 6/10 of a mile hike but it is a pretty steep hill and a good climb back up.",
  16. u"uploader_id": u"forestwander-nature-pictures",
  17. u"title": u"Dark Hollow Waterfalls"
  18. }
  19. }
  20. def _real_extract(self, url):
  21. mobj = re.match(self._VALID_URL, url)
  22. video_id = mobj.group('id')
  23. video_uploader_id = mobj.group('uploader_id')
  24. webpage_url = 'http://www.flickr.com/photos/' + video_uploader_id + '/' + video_id
  25. webpage = self._download_webpage(webpage_url, video_id)
  26. secret = self._search_regex(r"photo_secret: '(\w+)'", webpage, u'secret')
  27. first_url = 'https://secure.flickr.com/apps/video/video_mtl_xml.gne?v=x&photo_id=' + video_id + '&secret=' + secret + '&bitrate=700&target=_self'
  28. first_xml = self._download_webpage(first_url, video_id, 'Downloading first data webpage')
  29. node_id = self._html_search_regex(r'<Item id="id">(\d+-\d+)</Item>',
  30. first_xml, u'node_id')
  31. second_url = 'https://secure.flickr.com/video_playlist.gne?node_id=' + node_id + '&tech=flash&mode=playlist&bitrate=700&secret=' + secret + '&rd=video.yahoo.com&noad=1'
  32. second_xml = self._download_webpage(second_url, video_id, 'Downloading second data webpage')
  33. self.report_extraction(video_id)
  34. mobj = re.search(r'<STREAM APP="(.+?)" FULLPATH="(.+?)"', second_xml)
  35. if mobj is None:
  36. raise ExtractorError(u'Unable to extract video url')
  37. video_url = mobj.group(1) + unescapeHTML(mobj.group(2))
  38. return [{
  39. 'id': video_id,
  40. 'url': video_url,
  41. 'ext': 'mp4',
  42. 'title': self._og_search_title(webpage),
  43. 'description': self._og_search_description(webpage),
  44. 'thumbnail': self._og_search_thumbnail(webpage),
  45. 'uploader_id': video_uploader_id,
  46. }]