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.

73 lines
2.5 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. import codecs
  5. from .common import InfoExtractor
  6. from ..utils import unified_strdate
  7. class GooglePlusIE(InfoExtractor):
  8. IE_DESC = 'Google Plus'
  9. _VALID_URL = r'https?://plus\.google\.com/(?:[^/]+/)*?posts/(?P<id>\w+)'
  10. IE_NAME = 'plus.google'
  11. _TEST = {
  12. 'url': 'https://plus.google.com/u/0/108897254135232129896/posts/ZButuJc6CtH',
  13. 'info_dict': {
  14. 'id': 'ZButuJc6CtH',
  15. 'ext': 'flv',
  16. 'title': '嘆きの天使 降臨',
  17. 'upload_date': '20120613',
  18. 'uploader': '井上ヨシマサ',
  19. }
  20. }
  21. def _real_extract(self, url):
  22. video_id = self._match_id(url)
  23. # Step 1, Retrieve post webpage to extract further information
  24. webpage = self._download_webpage(url, video_id, 'Downloading entry webpage')
  25. title = self._og_search_description(webpage).splitlines()[0]
  26. upload_date = unified_strdate(self._html_search_regex(
  27. r'''(?x)<a.+?class="o-U-s\s[^"]+"\s+style="display:\s*none"\s*>
  28. ([0-9]{4}-[0-9]{2}-[0-9]{2})</a>''',
  29. webpage, 'upload date', fatal=False, flags=re.VERBOSE))
  30. uploader = self._html_search_regex(
  31. r'rel="author".*?>(.*?)</a>', webpage, 'uploader', fatal=False)
  32. # Step 2, Simulate clicking the image box to launch video
  33. DOMAIN = 'https://plus.google.com/'
  34. video_page = self._search_regex(
  35. r'<a href="((?:%s)?photos/.*?)"' % re.escape(DOMAIN),
  36. webpage, 'video page URL')
  37. if not video_page.startswith(DOMAIN):
  38. video_page = DOMAIN + video_page
  39. webpage = self._download_webpage(video_page, video_id, 'Downloading video page')
  40. def unicode_escape(s):
  41. decoder = codecs.getdecoder('unicode_escape')
  42. return re.sub(
  43. r'\\u[0-9a-fA-F]{4,}',
  44. lambda m: decoder(m.group(0))[0],
  45. s)
  46. # Extract video links all sizes
  47. formats = [{
  48. 'url': unicode_escape(video_url),
  49. 'ext': 'flv',
  50. 'width': int(width),
  51. 'height': int(height),
  52. } for width, height, video_url in re.findall(
  53. r'\d+,(\d+),(\d+),"(https?://[^.]+\.googleusercontent.com.*?)"', webpage)]
  54. self._sort_formats(formats)
  55. return {
  56. 'id': video_id,
  57. 'title': title,
  58. 'uploader': uploader,
  59. 'upload_date': upload_date,
  60. 'formats': formats,
  61. }