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.

60 lines
2.6 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. unescapeHTML,
  7. )
  8. class FlickrIE(InfoExtractor):
  9. """Information Extractor for Flickr videos"""
  10. _VALID_URL = r'(?:https?://)?(?:www\.|secure\.)?flickr\.com/photos/(?P<uploader_id>[\w\-_@]+)/(?P<id>\d+).*'
  11. _TEST = {
  12. 'url': 'http://www.flickr.com/photos/forestwander-nature-pictures/5645318632/in/photostream/',
  13. 'file': '5645318632.mp4',
  14. 'md5': '6fdc01adbc89d72fc9c4f15b4a4ba87b',
  15. 'info_dict': {
  16. "description": "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.",
  17. "uploader_id": "forestwander-nature-pictures",
  18. "title": "Dark Hollow Waterfalls"
  19. }
  20. }
  21. def _real_extract(self, url):
  22. mobj = re.match(self._VALID_URL, url)
  23. video_id = mobj.group('id')
  24. video_uploader_id = mobj.group('uploader_id')
  25. webpage_url = 'http://www.flickr.com/photos/' + video_uploader_id + '/' + video_id
  26. webpage = self._download_webpage(webpage_url, video_id)
  27. secret = self._search_regex(r"photo_secret: '(\w+)'", webpage, 'secret')
  28. first_url = 'https://secure.flickr.com/apps/video/video_mtl_xml.gne?v=x&photo_id=' + video_id + '&secret=' + secret + '&bitrate=700&target=_self'
  29. first_xml = self._download_webpage(first_url, video_id, 'Downloading first data webpage')
  30. node_id = self._html_search_regex(r'<Item id="id">(\d+-\d+)</Item>',
  31. first_xml, 'node_id')
  32. 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'
  33. second_xml = self._download_webpage(second_url, video_id, 'Downloading second data webpage')
  34. self.report_extraction(video_id)
  35. mobj = re.search(r'<STREAM APP="(.+?)" FULLPATH="(.+?)"', second_xml)
  36. if mobj is None:
  37. raise ExtractorError('Unable to extract video url')
  38. video_url = mobj.group(1) + unescapeHTML(mobj.group(2))
  39. return [{
  40. 'id': video_id,
  41. 'url': video_url,
  42. 'ext': 'mp4',
  43. 'title': self._og_search_title(webpage),
  44. 'description': self._og_search_description(webpage),
  45. 'thumbnail': self._og_search_thumbnail(webpage),
  46. 'uploader_id': video_uploader_id,
  47. }]