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.

73 lines
2.3 KiB

11 years ago
11 years ago
11 years ago
  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. compat_urlparse,
  7. str_to_int,
  8. ExtractorError,
  9. )
  10. import json
  11. class GoshgayIE(InfoExtractor):
  12. _VALID_URL = r'^(?:https?://)www.goshgay.com/video(?P<id>\d+?)($|/)'
  13. _TEST = {
  14. 'url': 'http://www.goshgay.com/video4116282',
  15. 'md5': '268b9f3c3229105c57859e166dd72b03',
  16. 'info_dict': {
  17. 'id': '4116282',
  18. 'ext': 'flv',
  19. 'title': 'md5:089833a4790b5e103285a07337f245bf',
  20. 'thumbnail': 're:http://.*\.jpg',
  21. 'age_limit': 18,
  22. }
  23. }
  24. def _real_extract(self, url):
  25. mobj = re.match(self._VALID_URL, url)
  26. video_id = mobj.group('id')
  27. webpage = self._download_webpage(url, video_id)
  28. title = self._search_regex(r'class="video-title"><h1>(.+?)<', webpage, 'title')
  29. player_config = self._search_regex(
  30. r'(?s)jwplayer\("player"\)\.setup\(({.+?})\)', webpage, 'config settings')
  31. player_vars = json.loads(player_config.replace("'", '"'))
  32. width = str_to_int(player_vars.get('width'))
  33. height = str_to_int(player_vars.get('height'))
  34. config_uri = player_vars.get('config')
  35. if config_uri is None:
  36. raise ExtractorError('Missing config URI')
  37. node = self._download_xml(config_uri, video_id, 'Downloading player config XML',
  38. errnote='Unable to download XML')
  39. if node is None:
  40. raise ExtractorError('Missing config XML')
  41. if node.tag != 'config':
  42. raise ExtractorError('Missing config attribute')
  43. fns = node.findall('file')
  44. imgs = node.findall('image')
  45. if len(fns) != 1:
  46. raise ExtractorError('Missing media URI')
  47. video_url = fns[0].text
  48. if len(imgs) < 1:
  49. thumbnail = None
  50. else:
  51. thumbnail = imgs[0].text
  52. url_comp = compat_urlparse.urlparse(url)
  53. ref = "%s://%s%s" % (url_comp[0], url_comp[1], url_comp[2])
  54. return {
  55. 'id': video_id,
  56. 'url': video_url,
  57. 'title': title,
  58. 'width': width,
  59. 'height': height,
  60. 'thumbnail': thumbnail,
  61. 'http_referer': ref,
  62. 'age_limit': 18,
  63. }