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.

95 lines
2.9 KiB

  1. from __future__ import unicode_literals
  2. import json
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import int_or_none
  6. _translation_table = {
  7. 'a': 'h', 'd': 'e', 'e': 'v', 'f': 'o', 'g': 'f', 'i': 'd', 'l': 'n',
  8. 'm': 'a', 'n': 'm', 'p': 'u', 'q': 't', 'r': 's', 'v': 'p', 'x': 'r',
  9. 'y': 'l', 'z': 'i',
  10. '$': ':', '&': '.', '(': '=', '^': '&', '=': '/',
  11. }
  12. def _decode(s):
  13. return ''.join(_translation_table.get(c, c) for c in s)
  14. class CliphunterIE(InfoExtractor):
  15. IE_NAME = 'cliphunter'
  16. _VALID_URL = r'''(?x)http://(?:www\.)?cliphunter\.com/w/
  17. (?P<id>[0-9]+)/
  18. (?P<seo>.+?)(?:$|[#\?])
  19. '''
  20. _TEST = {
  21. 'url': 'http://www.cliphunter.com/w/1012420/Fun_Jynx_Maze_solo',
  22. 'md5': 'a2ba71eebf523859fe527a61018f723e',
  23. 'info_dict': {
  24. 'id': '1012420',
  25. 'ext': 'mp4',
  26. 'title': 'Fun Jynx Maze solo',
  27. 'thumbnail': 're:^https?://.*\.jpg$',
  28. 'age_limit': 18,
  29. }
  30. }
  31. def _real_extract(self, url):
  32. mobj = re.match(self._VALID_URL, url)
  33. video_id = mobj.group('id')
  34. webpage = self._download_webpage(url, video_id)
  35. video_title = self._search_regex(
  36. r'mediaTitle = "([^"]+)"', webpage, 'title')
  37. pl_fiji = self._search_regex(
  38. r'pl_fiji = \'([^\']+)\'', webpage, 'video data')
  39. pl_c_qual = self._search_regex(
  40. r'pl_c_qual = "(.)"', webpage, 'video quality')
  41. video_url = _decode(pl_fiji)
  42. formats = [{
  43. 'url': video_url,
  44. 'format_id': 'default-%s' % pl_c_qual,
  45. }]
  46. qualities_json = self._search_regex(
  47. r'var pl_qualities\s*=\s*(.*?);\n', webpage, 'quality info')
  48. qualities_data = json.loads(qualities_json)
  49. for i, t in enumerate(
  50. re.findall(r"pl_fiji_([a-z0-9]+)\s*=\s*'([^']+')", webpage)):
  51. quality_id, crypted_url = t
  52. video_url = _decode(crypted_url)
  53. f = {
  54. 'format_id': quality_id,
  55. 'url': video_url,
  56. 'quality': i,
  57. }
  58. if quality_id in qualities_data:
  59. qd = qualities_data[quality_id]
  60. m = re.match(
  61. r'''(?x)<b>(?P<width>[0-9]+)x(?P<height>[0-9]+)<\\/b>
  62. \s*\(\s*(?P<tbr>[0-9]+)\s*kb\\/s''', qd)
  63. if m:
  64. f['width'] = int(m.group('width'))
  65. f['height'] = int(m.group('height'))
  66. f['tbr'] = int(m.group('tbr'))
  67. formats.append(f)
  68. self._sort_formats(formats)
  69. thumbnail = self._search_regex(
  70. r"var\s+mov_thumb\s*=\s*'([^']+)';",
  71. webpage, 'thumbnail', fatal=False)
  72. return {
  73. 'id': video_id,
  74. 'title': video_title,
  75. 'formats': formats,
  76. 'age_limit': self._rta_search(webpage),
  77. 'thumbnail': thumbnail,
  78. }