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.

66 lines
2.4 KiB

  1. import datetime
  2. import json
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. )
  8. class PhotobucketIE(InfoExtractor):
  9. """Information extractor for photobucket.com."""
  10. # TODO: the original _VALID_URL was:
  11. # r'(?:http://)?(?:[a-z0-9]+\.)?photobucket\.com/.*[\?\&]current=(.*\.flv)'
  12. # Check if it's necessary to keep the old extracion process
  13. _VALID_URL = r'(?:http://)?(?:[a-z0-9]+\.)?photobucket\.com/.*(([\?\&]current=)|_)(?P<id>.*)\.(?P<ext>(flv)|(mp4))'
  14. IE_NAME = u'photobucket'
  15. def _real_extract(self, url):
  16. # Extract id from URL
  17. mobj = re.match(self._VALID_URL, url)
  18. if mobj is None:
  19. raise ExtractorError(u'Invalid URL: %s' % url)
  20. video_id = mobj.group('id')
  21. video_extension = mobj.group('ext')
  22. # Retrieve video webpage to extract further information
  23. webpage = self._download_webpage(url, video_id)
  24. # Extract URL, uploader, and title from webpage
  25. self.report_extraction(video_id)
  26. # We try first by looking the javascript code:
  27. mobj = re.search(r'Pb\.Data\.Shared\.put\(Pb\.Data\.Shared\.MEDIA, (?P<json>.*?)\);', webpage)
  28. if mobj is not None:
  29. info = json.loads(mobj.group('json'))
  30. return [{
  31. 'id': video_id,
  32. 'url': info[u'downloadUrl'],
  33. 'uploader': info[u'username'],
  34. 'upload_date': datetime.date.fromtimestamp(info[u'creationDate']).strftime('%Y%m%d'),
  35. 'title': info[u'title'],
  36. 'ext': video_extension,
  37. 'thumbnail': info[u'thumbUrl'],
  38. }]
  39. # We try looking in other parts of the webpage
  40. video_url = self._search_regex(r'<link rel="video_src" href=".*\?file=([^"]+)" />',
  41. webpage, u'video URL')
  42. mobj = re.search(r'<title>(.*) video by (.*) - Photobucket</title>', webpage)
  43. if mobj is None:
  44. raise ExtractorError(u'Unable to extract title')
  45. video_title = mobj.group(1).decode('utf-8')
  46. video_uploader = mobj.group(2).decode('utf-8')
  47. return [{
  48. 'id': video_id.decode('utf-8'),
  49. 'url': video_url.decode('utf-8'),
  50. 'uploader': video_uploader,
  51. 'upload_date': None,
  52. 'title': video_title,
  53. 'ext': video_extension.decode('utf-8'),
  54. }]