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.

99 lines
3.1 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. 'duration': 1317,
  30. }
  31. }
  32. def _real_extract(self, url):
  33. mobj = re.match(self._VALID_URL, url)
  34. video_id = mobj.group('id')
  35. webpage = self._download_webpage(url, video_id)
  36. video_title = self._search_regex(
  37. r'mediaTitle = "([^"]+)"', webpage, 'title')
  38. pl_fiji = self._search_regex(
  39. r'pl_fiji = \'([^\']+)\'', webpage, 'video data')
  40. pl_c_qual = self._search_regex(
  41. r'pl_c_qual = "(.)"', webpage, 'video quality')
  42. video_url = _decode(pl_fiji)
  43. formats = [{
  44. 'url': video_url,
  45. 'format_id': 'default-%s' % pl_c_qual,
  46. }]
  47. qualities_json = self._search_regex(
  48. r'var pl_qualities\s*=\s*(.*?);\n', webpage, 'quality info')
  49. qualities_data = json.loads(qualities_json)
  50. for i, t in enumerate(
  51. re.findall(r"pl_fiji_([a-z0-9]+)\s*=\s*'([^']+')", webpage)):
  52. quality_id, crypted_url = t
  53. video_url = _decode(crypted_url)
  54. f = {
  55. 'format_id': quality_id,
  56. 'url': video_url,
  57. 'quality': i,
  58. }
  59. if quality_id in qualities_data:
  60. qd = qualities_data[quality_id]
  61. m = re.match(
  62. r'''(?x)<b>(?P<width>[0-9]+)x(?P<height>[0-9]+)<\\/b>
  63. \s*\(\s*(?P<tbr>[0-9]+)\s*kb\\/s''', qd)
  64. if m:
  65. f['width'] = int(m.group('width'))
  66. f['height'] = int(m.group('height'))
  67. f['tbr'] = int(m.group('tbr'))
  68. formats.append(f)
  69. self._sort_formats(formats)
  70. thumbnail = self._search_regex(
  71. r"var\s+mov_thumb\s*=\s*'([^']+)';",
  72. webpage, 'thumbnail', fatal=False)
  73. duration = int_or_none(self._search_regex(
  74. r'pl_dur\s*=\s*([0-9]+)', webpage, 'duration', fatal=False))
  75. return {
  76. 'id': video_id,
  77. 'title': video_title,
  78. 'formats': formats,
  79. 'duration': duration,
  80. 'age_limit': self._rta_search(webpage),
  81. 'thumbnail': thumbnail,
  82. }