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.

66 lines
2.3 KiB

10 years ago
  1. from __future__ import unicode_literals
  2. import re
  3. import json
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. compat_urlparse,
  7. get_element_by_id,
  8. clean_html,
  9. )
  10. class VeeHDIE(InfoExtractor):
  11. _VALID_URL = r'https?://veehd\.com/video/(?P<id>\d+)'
  12. _TEST = {
  13. 'url': 'http://veehd.com/video/4686958',
  14. 'info_dict': {
  15. 'id': '4686958',
  16. 'ext': 'mp4',
  17. 'title': 'Time Lapse View from Space ( ISS)',
  18. 'uploader_id': 'spotted',
  19. 'description': 'md5:f0094c4cf3a72e22bc4e4239ef767ad7',
  20. },
  21. }
  22. def _real_extract(self, url):
  23. mobj = re.match(self._VALID_URL, url)
  24. video_id = mobj.group('id')
  25. # VeeHD seems to send garbage on the first request.
  26. # See https://github.com/rg3/youtube-dl/issues/2102
  27. self._download_webpage(url, video_id, 'Requesting webpage')
  28. webpage = self._download_webpage(url, video_id)
  29. player_path = self._search_regex(
  30. r'\$\("#playeriframe"\).attr\({src : "(.+?)"',
  31. webpage, 'player path')
  32. player_url = compat_urlparse.urljoin(url, player_path)
  33. self._download_webpage(player_url, video_id, 'Requesting player page')
  34. player_page = self._download_webpage(
  35. player_url, video_id, 'Downloading player page')
  36. config_json = self._search_regex(
  37. r'value=\'config=({.+?})\'', player_page, 'config json')
  38. config = json.loads(config_json)
  39. video_url = compat_urlparse.unquote(config['clip']['url'])
  40. title = clean_html(get_element_by_id('videoName', webpage).rpartition('|')[0])
  41. uploader_id = self._html_search_regex(r'<a href="/profile/\d+">(.+?)</a>',
  42. webpage, 'uploader')
  43. thumbnail = self._search_regex(r'<img id="veehdpreview" src="(.+?)"',
  44. webpage, 'thumbnail')
  45. description = self._html_search_regex(r'<td class="infodropdown".*?<div>(.*?)<ul',
  46. webpage, 'description', flags=re.DOTALL)
  47. return {
  48. '_type': 'video',
  49. 'id': video_id,
  50. 'title': title,
  51. 'url': video_url,
  52. 'ext': 'mp4',
  53. 'uploader_id': uploader_id,
  54. 'thumbnail': thumbnail,
  55. 'description': description,
  56. }