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.

89 lines
3.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. _TEST = {
  16. 'url': 'http://veehd.com/video/4639434_Solar-Sinter',
  17. 'info_dict': {
  18. 'id': '4639434',
  19. 'ext': 'mp4',
  20. 'title': 'Solar Sinter',
  21. 'uploader_id': 'VideoEyes',
  22. 'description': 'md5:46a840e8692ddbaffb5f81d9885cb457',
  23. },
  24. }
  25. def _real_extract(self, url):
  26. video_id = self._match_id(url)
  27. # VeeHD seems to send garbage on the first request.
  28. # See https://github.com/rg3/youtube-dl/issues/2102
  29. self._download_webpage(url, video_id, 'Requesting webpage')
  30. webpage = self._download_webpage(url, video_id)
  31. if 'This video has been removed<' in webpage:
  32. raise ExtractorError('Video %s has been removed' % video_id, expected=True)
  33. player_path = self._search_regex(
  34. r'\$\("#playeriframe"\).attr\({src : "(.+?)"',
  35. webpage, 'player path')
  36. player_url = compat_urlparse.urljoin(url, player_path)
  37. self._download_webpage(player_url, video_id, 'Requesting player page')
  38. player_page = self._download_webpage(
  39. player_url, video_id, 'Downloading player page')
  40. config_json = self._search_regex(
  41. r'value=\'config=({.+?})\'', player_page, 'config json', default=None)
  42. if config_json:
  43. config = json.loads(config_json)
  44. video_url = compat_urlparse.unquote(config['clip']['url'])
  45. else:
  46. iframe_src = self._search_regex(
  47. r'<iframe[^>]+src="/?([^"]+)"', player_page, 'iframe url')
  48. iframe_url = 'http://veehd.com/%s' % iframe_src
  49. self._download_webpage(iframe_url, video_id, 'Requesting iframe page')
  50. iframe_page = self._download_webpage(
  51. iframe_url, video_id, 'Downloading iframe page')
  52. video_url = self._search_regex(
  53. r"file\s*:\s*'([^']+)'", iframe_page, 'video url')
  54. title = clean_html(get_element_by_id('videoName', webpage).rpartition('|')[0])
  55. uploader_id = self._html_search_regex(
  56. r'<a href="/profile/\d+">(.+?)</a>',
  57. webpage, 'uploader')
  58. thumbnail = self._search_regex(
  59. r'<img id="veehdpreview" src="(.+?)"',
  60. webpage, 'thumbnail')
  61. description = self._html_search_regex(
  62. r'<td class="infodropdown".*?<div>(.*?)<ul',
  63. webpage, 'description', flags=re.DOTALL)
  64. return {
  65. '_type': 'video',
  66. 'id': video_id,
  67. 'title': title,
  68. 'url': video_url,
  69. 'ext': 'mp4',
  70. 'uploader_id': uploader_id,
  71. 'thumbnail': thumbnail,
  72. 'description': description,
  73. }