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.

98 lines
3.4 KiB

  1. # coding: utf-8
  2. import datetime
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. )
  8. class GooglePlusIE(InfoExtractor):
  9. IE_DESC = u'Google Plus'
  10. _VALID_URL = r'(?:https://)?plus\.google\.com/(?:[^/]+/)*?posts/(\w+)'
  11. IE_NAME = u'plus.google'
  12. _TEST = {
  13. u"url": u"https://plus.google.com/u/0/108897254135232129896/posts/ZButuJc6CtH",
  14. u"file": u"ZButuJc6CtH.flv",
  15. u"info_dict": {
  16. u"upload_date": u"20120613",
  17. u"uploader": u"井上ヨシマサ",
  18. u"title": u"嘆きの天使 降臨"
  19. }
  20. }
  21. def _real_extract(self, url):
  22. # Extract id from URL
  23. mobj = re.match(self._VALID_URL, url)
  24. if mobj is None:
  25. raise ExtractorError(u'Invalid URL: %s' % url)
  26. post_url = mobj.group(0)
  27. video_id = mobj.group(1)
  28. video_extension = 'flv'
  29. # Step 1, Retrieve post webpage to extract further information
  30. webpage = self._download_webpage(post_url, video_id, u'Downloading entry webpage')
  31. self.report_extraction(video_id)
  32. # Extract update date
  33. upload_date = self._html_search_regex(
  34. r'''(?x)<a.+?class="o-U-s\s[^"]+"\s+style="display:\s*none"\s*>
  35. ([0-9]{4}-[0-9]{2}-[0-9]{2})</a>''',
  36. webpage, u'upload date', fatal=False, flags=re.VERBOSE)
  37. if upload_date:
  38. # Convert timestring to a format suitable for filename
  39. upload_date = datetime.datetime.strptime(upload_date, "%Y-%m-%d")
  40. upload_date = upload_date.strftime('%Y%m%d')
  41. # Extract uploader
  42. uploader = self._html_search_regex(r'rel\="author".*?>(.*?)</a>',
  43. webpage, u'uploader', fatal=False)
  44. # Extract title
  45. # Get the first line for title
  46. video_title = self._html_search_regex(r'<meta name\=\"Description\" content\=\"(.*?)[\n<"]',
  47. webpage, 'title', default=u'NA')
  48. # Step 2, Simulate clicking the image box to launch video
  49. DOMAIN = 'https://plus.google.com/'
  50. video_page = self._search_regex(r'<a href="((?:%s)?photos/.*?)"' % re.escape(DOMAIN),
  51. webpage, u'video page URL')
  52. if not video_page.startswith(DOMAIN):
  53. video_page = DOMAIN + video_page
  54. webpage = self._download_webpage(video_page, video_id, u'Downloading video page')
  55. # Extract video links on video page
  56. """Extract video links of all sizes"""
  57. pattern = r'\d+,\d+,(\d+),"(http\://redirector\.googlevideo\.com.*?)"'
  58. mobj = re.findall(pattern, webpage)
  59. if len(mobj) == 0:
  60. raise ExtractorError(u'Unable to extract video links')
  61. # Sort in resolution
  62. links = sorted(mobj)
  63. # Choose the lowest of the sort, i.e. highest resolution
  64. video_url = links[-1]
  65. # Only get the url. The resolution part in the tuple has no use anymore
  66. video_url = video_url[-1]
  67. # Treat escaped \u0026 style hex
  68. try:
  69. video_url = video_url.decode("unicode_escape")
  70. except AttributeError: # Python 3
  71. video_url = bytes(video_url, 'ascii').decode('unicode-escape')
  72. return [{
  73. 'id': video_id,
  74. 'url': video_url,
  75. 'uploader': uploader,
  76. 'upload_date': upload_date,
  77. 'title': video_title,
  78. 'ext': video_extension,
  79. }]