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.

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