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.

76 lines
2.9 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. _TEST = {
  16. u'url': u'http://media.photobucket.com/user/rachaneronas/media/TiredofLinkBuildingTryBacklinkMyDomaincom_zpsc0c3b9fa.mp4.html?filters[term]=search&filters[primary]=videos&filters[secondary]=images&sort=1&o=0',
  17. u'file': u'zpsc0c3b9fa.mp4',
  18. u'md5': u'7dabfb92b0a31f6c16cebc0f8e60ff99',
  19. u'info_dict': {
  20. u"upload_date": u"20130504",
  21. u"uploader": u"rachaneronas",
  22. u"title": u"Tired of Link Building? Try BacklinkMyDomain.com!"
  23. }
  24. }
  25. def _real_extract(self, url):
  26. # Extract id from URL
  27. mobj = re.match(self._VALID_URL, url)
  28. if mobj is None:
  29. raise ExtractorError(u'Invalid URL: %s' % url)
  30. video_id = mobj.group('id')
  31. video_extension = mobj.group('ext')
  32. # Retrieve video webpage to extract further information
  33. webpage = self._download_webpage(url, video_id)
  34. # Extract URL, uploader, and title from webpage
  35. self.report_extraction(video_id)
  36. # We try first by looking the javascript code:
  37. mobj = re.search(r'Pb\.Data\.Shared\.put\(Pb\.Data\.Shared\.MEDIA, (?P<json>.*?)\);', webpage)
  38. if mobj is not None:
  39. info = json.loads(mobj.group('json'))
  40. return [{
  41. 'id': video_id,
  42. 'url': info[u'downloadUrl'],
  43. 'uploader': info[u'username'],
  44. 'upload_date': datetime.date.fromtimestamp(info[u'creationDate']).strftime('%Y%m%d'),
  45. 'title': info[u'title'],
  46. 'ext': video_extension,
  47. 'thumbnail': info[u'thumbUrl'],
  48. }]
  49. # We try looking in other parts of the webpage
  50. video_url = self._search_regex(r'<link rel="video_src" href=".*\?file=([^"]+)" />',
  51. webpage, u'video URL')
  52. mobj = re.search(r'<title>(.*) video by (.*) - Photobucket</title>', webpage)
  53. if mobj is None:
  54. raise ExtractorError(u'Unable to extract title')
  55. video_title = mobj.group(1).decode('utf-8')
  56. video_uploader = mobj.group(2).decode('utf-8')
  57. return [{
  58. 'id': video_id.decode('utf-8'),
  59. 'url': video_url.decode('utf-8'),
  60. 'uploader': video_uploader,
  61. 'upload_date': None,
  62. 'title': video_title,
  63. 'ext': video_extension.decode('utf-8'),
  64. }]