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.

57 lines
2.4 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. def _real_extract(self, url):
  11. mobj = re.match(self._VALID_URL, url)
  12. video_id = mobj.group('id')
  13. video_uploader_id = mobj.group('uploader_id')
  14. webpage_url = 'http://www.flickr.com/photos/' + video_uploader_id + '/' + video_id
  15. webpage = self._download_webpage(webpage_url, video_id)
  16. secret = self._search_regex(r"photo_secret: '(\w+)'", webpage, u'secret')
  17. first_url = 'https://secure.flickr.com/apps/video/video_mtl_xml.gne?v=x&photo_id=' + video_id + '&secret=' + secret + '&bitrate=700&target=_self'
  18. first_xml = self._download_webpage(first_url, video_id, 'Downloading first data webpage')
  19. node_id = self._html_search_regex(r'<Item id="id">(\d+-\d+)</Item>',
  20. first_xml, u'node_id')
  21. 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'
  22. second_xml = self._download_webpage(second_url, video_id, 'Downloading second data webpage')
  23. self.report_extraction(video_id)
  24. mobj = re.search(r'<STREAM APP="(.+?)" FULLPATH="(.+?)"', second_xml)
  25. if mobj is None:
  26. raise ExtractorError(u'Unable to extract video url')
  27. video_url = mobj.group(1) + unescapeHTML(mobj.group(2))
  28. video_title = self._html_search_regex(r'<meta property="og:title" content=(?:"([^"]+)"|\'([^\']+)\')',
  29. webpage, u'video title')
  30. video_description = self._html_search_regex(r'<meta property="og:description" content=(?:"([^"]+)"|\'([^\']+)\')',
  31. webpage, u'description', fatal=False)
  32. thumbnail = self._html_search_regex(r'<meta property="og:image" content=(?:"([^"]+)"|\'([^\']+)\')',
  33. webpage, u'thumbnail', fatal=False)
  34. return [{
  35. 'id': video_id,
  36. 'url': video_url,
  37. 'ext': 'mp4',
  38. 'title': video_title,
  39. 'description': video_description,
  40. 'thumbnail': thumbnail,
  41. 'uploader_id': video_uploader_id,
  42. }]