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.

118 lines
4.0 KiB

10 years ago
  1. from __future__ import unicode_literals
  2. import re
  3. import json
  4. from .common import InfoExtractor
  5. from ..compat import (
  6. compat_urllib_parse_unquote,
  7. compat_urlparse,
  8. )
  9. from ..utils import (
  10. ExtractorError,
  11. clean_html,
  12. get_element_by_id,
  13. )
  14. class VeeHDIE(InfoExtractor):
  15. _VALID_URL = r'https?://veehd\.com/video/(?P<id>\d+)'
  16. # Seems VeeHD videos have multiple copies on several servers, all of
  17. # whom have different MD5 checksums, so omit md5 field in all tests
  18. _TESTS = [{
  19. 'url': 'http://veehd.com/video/4639434_Solar-Sinter',
  20. 'info_dict': {
  21. 'id': '4639434',
  22. 'ext': 'mp4',
  23. 'title': 'Solar Sinter',
  24. 'uploader_id': 'VideoEyes',
  25. 'description': 'md5:46a840e8692ddbaffb5f81d9885cb457',
  26. },
  27. 'skip': 'Video deleted',
  28. }, {
  29. 'url': 'http://veehd.com/video/4905758_Elysian-Fields-Channeling',
  30. 'info_dict': {
  31. 'id': '4905758',
  32. 'ext': 'mp4',
  33. 'title': 'Elysian Fields - Channeling',
  34. 'description': 'md5:360e4e95fdab58aefbea0f2a19e5604b',
  35. 'uploader_id': 'spotted',
  36. }
  37. }, {
  38. 'url': 'http://veehd.com/video/2046729_2012-2009-DivX-Trailer',
  39. 'info_dict': {
  40. 'id': '2046729',
  41. 'ext': 'avi',
  42. 'title': '2012 (2009) DivX Trailer',
  43. 'description': 'md5:75435ee95255e6a9838ac6f6f3a2396b',
  44. 'uploader_id': 'Movie_Trailers',
  45. }
  46. }]
  47. def _real_extract(self, url):
  48. video_id = self._match_id(url)
  49. # VeeHD seems to send garbage on the first request.
  50. # See https://github.com/ytdl-org/youtube-dl/issues/2102
  51. self._download_webpage(url, video_id, 'Requesting webpage')
  52. webpage = self._download_webpage(url, video_id)
  53. if 'This video has been removed<' in webpage:
  54. raise ExtractorError('Video %s has been removed' % video_id, expected=True)
  55. player_path = self._search_regex(
  56. r'\$\("#playeriframe"\).attr\({src : "(.+?)"',
  57. webpage, 'player path')
  58. player_url = compat_urlparse.urljoin(url, player_path)
  59. self._download_webpage(player_url, video_id, 'Requesting player page')
  60. player_page = self._download_webpage(
  61. player_url, video_id, 'Downloading player page')
  62. video_url = None
  63. config_json = self._search_regex(
  64. r'value=\'config=({.+?})\'', player_page, 'config json', default=None)
  65. if config_json:
  66. config = json.loads(config_json)
  67. video_url = compat_urllib_parse_unquote(config['clip']['url'])
  68. if not video_url:
  69. video_url = self._html_search_regex(
  70. r'<embed[^>]+type="video/divx"[^>]+src="([^"]+)"',
  71. player_page, 'video url', default=None)
  72. if not video_url:
  73. iframe_src = self._search_regex(
  74. r'<iframe[^>]+src="/?([^"]+)"', player_page, 'iframe url')
  75. iframe_url = 'http://veehd.com/%s' % iframe_src
  76. self._download_webpage(iframe_url, video_id, 'Requesting iframe page')
  77. iframe_page = self._download_webpage(
  78. iframe_url, video_id, 'Downloading iframe page')
  79. video_url = self._search_regex(
  80. r"file\s*:\s*'([^']+)'", iframe_page, 'video url')
  81. title = clean_html(get_element_by_id('videoName', webpage).rpartition('|')[0])
  82. uploader_id = self._html_search_regex(
  83. r'<a href="/profile/\d+">(.+?)</a>',
  84. webpage, 'uploader')
  85. thumbnail = self._search_regex(
  86. r'<img id="veehdpreview" src="(.+?)"',
  87. webpage, 'thumbnail')
  88. description = self._html_search_regex(
  89. r'<td class="infodropdown".*?<div>(.*?)<ul',
  90. webpage, 'description', flags=re.DOTALL)
  91. return {
  92. '_type': 'video',
  93. 'id': video_id,
  94. 'title': title,
  95. 'url': video_url,
  96. 'uploader_id': uploader_id,
  97. 'thumbnail': thumbnail,
  98. 'description': description,
  99. }