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.

67 lines
2.8 KiB

10 years ago
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..compat import compat_urllib_request
  5. from ..utils import (
  6. ExtractorError,
  7. find_xpath_attr,
  8. )
  9. class FlickrIE(InfoExtractor):
  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. 'md5': '6fdc01adbc89d72fc9c4f15b4a4ba87b',
  14. 'info_dict': {
  15. 'id': '5645318632',
  16. 'ext': 'mp4',
  17. "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.",
  18. "uploader_id": "forestwander-nature-pictures",
  19. "title": "Dark Hollow Waterfalls"
  20. }
  21. }
  22. def _real_extract(self, url):
  23. mobj = re.match(self._VALID_URL, url)
  24. video_id = mobj.group('id')
  25. video_uploader_id = mobj.group('uploader_id')
  26. webpage_url = 'http://www.flickr.com/photos/' + video_uploader_id + '/' + video_id
  27. req = compat_urllib_request.Request(webpage_url)
  28. req.add_header(
  29. 'User-Agent',
  30. # it needs a more recent version
  31. 'Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20150101 Firefox/38.0 (Chrome)')
  32. webpage = self._download_webpage(req, video_id)
  33. secret = self._search_regex(r'secret"\s*:\s*"(\w+)"', webpage, 'secret')
  34. first_url = 'https://secure.flickr.com/apps/video/video_mtl_xml.gne?v=x&photo_id=' + video_id + '&secret=' + secret + '&bitrate=700&target=_self'
  35. first_xml = self._download_xml(first_url, video_id, 'Downloading first data webpage')
  36. node_id = find_xpath_attr(
  37. first_xml, './/{http://video.yahoo.com/YEP/1.0/}Item', 'id',
  38. 'id').text
  39. 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'
  40. second_xml = self._download_xml(second_url, video_id, 'Downloading second data webpage')
  41. self.report_extraction(video_id)
  42. stream = second_xml.find('.//STREAM')
  43. if stream is None:
  44. raise ExtractorError('Unable to extract video url')
  45. video_url = stream.attrib['APP'] + stream.attrib['FULLPATH']
  46. return {
  47. 'id': video_id,
  48. 'url': video_url,
  49. 'ext': 'mp4',
  50. 'title': self._og_search_title(webpage),
  51. 'description': self._og_search_description(webpage),
  52. 'thumbnail': self._og_search_thumbnail(webpage),
  53. 'uploader_id': video_uploader_id,
  54. }