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.

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