thvideo.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. mobj = re.match(self._VALID_URL, url)
  25. video_id = mobj.group('id')
  26. # extract download link from mobile player page
  27. webpage_player = self._download_webpage(
  28. 'http://thvideo.tv/mobile.php?cid=%s-0' % (video_id),
  29. video_id, note='Downloading video source page')
  30. video_url = self._html_search_regex(
  31. r'<source src="(.*?)" type', webpage_player, 'video url')
  32. # extract video info from main page
  33. webpage = self._download_webpage(
  34. 'http://thvideo.tv/v/th%s' % (video_id), video_id)
  35. title = self._og_search_title(webpage)
  36. display_id = 'th%s' % video_id
  37. thumbnail = self._og_search_thumbnail(webpage)
  38. description = self._og_search_description(webpage)
  39. upload_date = unified_strdate(self._html_search_regex(
  40. r'span itemprop="datePublished" content="(.*?)">', webpage,
  41. 'upload date', fatal=False))
  42. return {
  43. 'id': video_id,
  44. 'ext': 'mp4',
  45. 'url': video_url,
  46. 'title': title,
  47. 'display_id': display_id,
  48. 'thumbnail': thumbnail,
  49. 'description': description,
  50. 'upload_date': upload_date
  51. }
  52. class THVideoPlaylistIE(InfoExtractor):
  53. _VALID_URL = r'http?://(?:www\.)?thvideo\.tv/mylist(?P<id>[0-9]+)'
  54. _TEST = {
  55. 'url': 'http://thvideo.tv/mylist2',
  56. 'info_dict': {
  57. 'id': '2',
  58. 'title': '幻想万華鏡',
  59. },
  60. 'playlist_mincount': 23,
  61. }
  62. def _real_extract(self, url):
  63. webpage = self._download_webpage(url, 'playlist')
  64. mobj = re.match(self._VALID_URL, url)
  65. list_id = mobj.group('id')
  66. list_title = self._html_search_regex(r'<h1 class="show_title">(.*?)<b id', webpage, 'playlist title')
  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, list_id, list_title)