photobucket.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import json
  2. import urllib.parse
  3. from .common import InfoExtractor
  4. class PhotobucketIE(InfoExtractor):
  5. _VALID_URL = r'https?://(?:[a-z0-9]+\.)?photobucket\.com/.*(([\?\&]current=)|_)(?P<id>.*)\.(?P<ext>(flv)|(mp4))'
  6. _TEST = {
  7. 'url': 'http://media.photobucket.com/user/rachaneronas/media/TiredofLinkBuildingTryBacklinkMyDomaincom_zpsc0c3b9fa.mp4.html?filters[term]=search&filters[primary]=videos&filters[secondary]=images&sort=1&o=0',
  8. 'md5': '7dabfb92b0a31f6c16cebc0f8e60ff99',
  9. 'info_dict': {
  10. 'id': 'zpsc0c3b9fa',
  11. 'ext': 'mp4',
  12. 'timestamp': 1367669341,
  13. 'upload_date': '20130504',
  14. 'uploader': 'rachaneronas',
  15. 'title': 'Tired of Link Building? Try BacklinkMyDomain.com!',
  16. },
  17. }
  18. def _real_extract(self, url):
  19. mobj = self._match_valid_url(url)
  20. video_id = mobj.group('id')
  21. video_extension = mobj.group('ext')
  22. webpage = self._download_webpage(url, video_id)
  23. # Extract URL, uploader, and title from webpage
  24. self.report_extraction(video_id)
  25. info_json = self._search_regex(r'Pb\.Data\.Shared\.put\(Pb\.Data\.Shared\.MEDIA, (.*?)\);',
  26. webpage, 'info json')
  27. info = json.loads(info_json)
  28. url = urllib.parse.unquote(self._html_search_regex(r'file=(.+\.mp4)', info['linkcodes']['html'], 'url'))
  29. return {
  30. 'id': video_id,
  31. 'url': url,
  32. 'uploader': info['username'],
  33. 'timestamp': info['creationDate'],
  34. 'title': info['title'],
  35. 'ext': video_extension,
  36. 'thumbnail': info['thumbUrl'],
  37. }