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.

92 lines
2.8 KiB

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