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.

84 lines
3.0 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. unified_strdate
  7. )
  8. class THVideoIE(InfoExtractor):
  9. _VALID_URL = r'http://(?:www\.)?thvideo\.tv/(?:v/th|mobile\.php\?cid=)(?P<id>[0-9]+)'
  10. _TEST = {
  11. 'url': 'http://thvideo.tv/v/th1987/',
  12. 'md5': 'fa107b1f73817e325e9433505a70db50',
  13. 'info_dict': {
  14. 'id': '1987',
  15. 'ext': 'mp4',
  16. 'title': '【动画】秘封活动记录 ~ The Sealed Esoteric History.分镜稿预览',
  17. 'display_id': 'th1987',
  18. 'thumbnail': 'http://thvideo.tv/uploadfile/2014/0722/20140722013459856.jpg',
  19. 'description': '社团京都幻想剧团的第一个东方二次同人动画作品「秘封活动记录 ~ The Sealed Esoteric History.」 本视频是该动画第一期的分镜草稿...',
  20. 'upload_date': '20140722'
  21. }
  22. }
  23. def _real_extract(self, url):
  24. video_id = self._match_id(url)
  25. # extract download link from mobile player page
  26. webpage_player = self._download_webpage(
  27. 'http://thvideo.tv/mobile.php?cid=%s-0' % (video_id),
  28. video_id, note='Downloading video source page')
  29. video_url = self._html_search_regex(
  30. r'<source src="(.*?)" type', webpage_player, 'video url')
  31. # extract video info from main page
  32. webpage = self._download_webpage(
  33. 'http://thvideo.tv/v/th%s' % (video_id), video_id)
  34. title = self._og_search_title(webpage)
  35. display_id = 'th%s' % video_id
  36. thumbnail = self._og_search_thumbnail(webpage)
  37. description = self._og_search_description(webpage)
  38. upload_date = unified_strdate(self._html_search_regex(
  39. r'span itemprop="datePublished" content="(.*?)">', webpage,
  40. 'upload date', fatal=False))
  41. return {
  42. 'id': video_id,
  43. 'ext': 'mp4',
  44. 'url': video_url,
  45. 'title': title,
  46. 'display_id': display_id,
  47. 'thumbnail': thumbnail,
  48. 'description': description,
  49. 'upload_date': upload_date
  50. }
  51. class THVideoPlaylistIE(InfoExtractor):
  52. _VALID_URL = r'http?://(?:www\.)?thvideo\.tv/mylist(?P<id>[0-9]+)'
  53. _TEST = {
  54. 'url': 'http://thvideo.tv/mylist2',
  55. 'info_dict': {
  56. 'id': '2',
  57. 'title': '幻想万華鏡',
  58. },
  59. 'playlist_mincount': 23,
  60. }
  61. def _real_extract(self, url):
  62. playlist_id = self._match_id(url)
  63. webpage = self._download_webpage(url, playlist_id)
  64. list_title = self._html_search_regex(
  65. r'<h1 class="show_title">(.*?)<b id', webpage, 'playlist title',
  66. fatal=False)
  67. entries = [
  68. self.url_result('http://thvideo.tv/v/th' + id, 'THVideo')
  69. for id in re.findall(r'<dd><a href="http://thvideo.tv/v/th(\d+)/" target=', webpage)]
  70. return self.playlist_result(entries, playlist_id, list_title)