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.

163 lines
6.1 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import parse_iso8601
  5. class NextMediaIE(InfoExtractor):
  6. _VALID_URL = r'http://hk.apple.nextmedia.com/[^/]+/[^/]+/(?P<date>\d+)/(?P<id>\d+)'
  7. _TESTS = [{
  8. 'url': 'http://hk.apple.nextmedia.com/realtime/news/20141108/53109199',
  9. 'md5': 'dff9fad7009311c421176d1ac90bfe4f',
  10. 'info_dict': {
  11. 'id': '53109199',
  12. 'ext': 'mp4',
  13. 'title': '【佔領金鐘】50外國領事議員撐場 讚學生勇敢香港有希望',
  14. 'thumbnail': 're:^https?://.*\.jpg$',
  15. 'description': 'md5:28222b9912b6665a21011b034c70fcc7',
  16. 'timestamp': 1415456273,
  17. 'upload_date': '20141108',
  18. }
  19. }]
  20. _URL_PATTERN = r'\{ url: \'(.+)\' \}'
  21. def _real_extract(self, url):
  22. news_id = self._match_id(url)
  23. page = self._download_webpage(url, news_id)
  24. return self._extract_from_nextmedia_page(news_id, url, page)
  25. def _extract_from_nextmedia_page(self, news_id, url, page):
  26. title = self._fetch_title(page)
  27. video_url = self._search_regex(self._URL_PATTERN, page, 'video url')
  28. attrs = {
  29. 'id': news_id,
  30. 'title': title,
  31. 'url': video_url, # ext can be inferred from url
  32. 'thumbnail': self._fetch_thumbnail(page),
  33. 'description': self._fetch_description(page),
  34. }
  35. timestamp = self._fetch_timestamp(page)
  36. if timestamp:
  37. attrs['timestamp'] = timestamp
  38. else:
  39. attrs['upload_date'] = self._fetch_upload_date(url)
  40. return attrs
  41. def _fetch_title(self, page):
  42. return self._og_search_title(page)
  43. def _fetch_thumbnail(self, page):
  44. return self._og_search_thumbnail(page)
  45. def _fetch_timestamp(self, page):
  46. dateCreated = self._search_regex('"dateCreated":"([^"]+)"', page, 'created time')
  47. return parse_iso8601(dateCreated)
  48. def _fetch_upload_date(self, url):
  49. return self._search_regex(self._VALID_URL, url, 'upload date', group='date')
  50. def _fetch_description(self, page):
  51. return self._og_search_property('description', page)
  52. class NextMediaActionNewsIE(NextMediaIE):
  53. _VALID_URL = r'http://hk.dv.nextmedia.com/actionnews/[^/]+/(?P<date>\d+)/(?P<id>\d+)/\d+'
  54. _TESTS = [{
  55. 'url': 'http://hk.dv.nextmedia.com/actionnews/hit/20150121/19009428/20061460',
  56. 'md5': '05fce8ffeed7a5e00665d4b7cf0f9201',
  57. 'info_dict': {
  58. 'id': '19009428',
  59. 'ext': 'mp4',
  60. 'title': '【壹週刊】細10年男友偷食 50歲邵美琪再失戀',
  61. 'thumbnail': 're:^https?://.*\.jpg$',
  62. 'description': 'md5:cd802fad1f40fd9ea178c1e2af02d659',
  63. 'timestamp': 1421791200,
  64. 'upload_date': '20150120',
  65. }
  66. }]
  67. def _real_extract(self, url):
  68. news_id = self._match_id(url)
  69. actionnews_page = self._download_webpage(url, news_id)
  70. article_url = self._og_search_url(actionnews_page)
  71. article_page = self._download_webpage(article_url, news_id)
  72. return self._extract_from_nextmedia_page(news_id, url, article_page)
  73. class AppleDailyRealtimeNewsIE(NextMediaIE):
  74. _VALID_URL = r'http://(www|ent).appledaily.com.tw/(realtimenews|enews)/[^/]+/[^/]+/(?P<date>\d+)/(?P<id>\d+)(/.*)?'
  75. _TESTS = [{
  76. 'url': 'http://ent.appledaily.com.tw/enews/article/entertainment/20150128/36354694',
  77. 'md5': 'a843ab23d150977cc55ef94f1e2c1e4d',
  78. 'info_dict': {
  79. 'id': '36354694',
  80. 'ext': 'mp4',
  81. 'title': '周亭羽走過摩鐵陰霾2男陪吃 九把刀孤寒看醫生',
  82. 'thumbnail': 're:^https?://.*\.jpg$',
  83. 'description': 'md5:b23787119933404ce515c6356a8c355c',
  84. 'upload_date': '20150128',
  85. }
  86. }, {
  87. 'url': 'http://www.appledaily.com.tw/realtimenews/article/strange/20150128/550549/%E4%B8%8D%E6%BB%BF%E8%A2%AB%E8%B8%A9%E8%85%B3%E3%80%80%E5%B1%B1%E6%9D%B1%E5%85%A9%E5%A4%A7%E5%AA%BD%E4%B8%80%E8%B7%AF%E6%89%93%E4%B8%8B%E8%BB%8A',
  88. 'md5': '86b4e9132d158279c7883822d94ccc49',
  89. 'info_dict': {
  90. 'id': '550549',
  91. 'ext': 'mp4',
  92. 'title': '不滿被踩腳 山東兩大媽一路打下車',
  93. 'thumbnail': 're:^https?://.*\.jpg$',
  94. 'description': 'md5:2648aaf6fc4f401f6de35a91d111aa1d',
  95. 'upload_date': '20150128',
  96. }
  97. }]
  98. _URL_PATTERN = r'\{url: \'(.+)\'\}'
  99. def _fetch_title(self, page):
  100. return self._html_search_regex(r'<h1 id="h1">([^<>]+)</h1>', page, 'news title')
  101. def _fetch_thumbnail(self, page):
  102. return self._html_search_regex(r"setInitialImage\(\'([^']+)'\)", page, 'video thumbnail', fatal=False)
  103. def _fetch_timestamp(self, page):
  104. return None
  105. class AppleDailyAnimationNewsIE(AppleDailyRealtimeNewsIE):
  106. _VALID_URL = 'http://www.appledaily.com.tw/animation/[^/]+/[^/]+/(?P<date>\d+)/(?P<id>\d+)(/.*)?'
  107. _TESTS = [{
  108. 'url': 'http://www.appledaily.com.tw/animation/realtimenews/new/20150128/5003671',
  109. 'md5': '03df296d95dedc2d5886debbb80cb43f',
  110. 'info_dict': {
  111. 'id': '5003671',
  112. 'ext': 'mp4',
  113. 'title': '20正妹熱舞 《刀龍傳說Online》火辣上市',
  114. 'thumbnail': 're:^https?://.*\.jpg$',
  115. 'description': 'md5:23c0aac567dc08c9c16a3161a2c2e3cd',
  116. 'upload_date': '20150128',
  117. }
  118. }, {
  119. # No thumbnail
  120. 'url': 'http://www.appledaily.com.tw/animation/realtimenews/new/20150128/5003673/',
  121. 'md5': 'b06182cd386ea7bc6115ec7ff0f72aeb',
  122. 'info_dict': {
  123. 'id': '5003673',
  124. 'ext': 'mp4',
  125. 'title': '半夜尿尿 好像會看到___',
  126. 'description': 'md5:61d2da7fe117fede148706cdb85ac066',
  127. 'upload_date': '20150128',
  128. },
  129. 'expected_warnings': [
  130. 'video thumbnail',
  131. ]
  132. }]
  133. def _fetch_title(self, page):
  134. return self._html_search_meta('description', page, 'news title')
  135. def _fetch_description(self, page):
  136. return self._html_search_meta('description', page, 'news description')