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.

82 lines
2.4 KiB

  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. from ..utils import determine_ext
  4. _translation_table = {
  5. 'a': 'h', 'd': 'e', 'e': 'v', 'f': 'o', 'g': 'f', 'i': 'd', 'l': 'n',
  6. 'm': 'a', 'n': 'm', 'p': 'u', 'q': 't', 'r': 's', 'v': 'p', 'x': 'r',
  7. 'y': 'l', 'z': 'i',
  8. '$': ':', '&': '.', '(': '=', '^': '&', '=': '/',
  9. }
  10. def _decode(s):
  11. return ''.join(_translation_table.get(c, c) for c in s)
  12. class CliphunterIE(InfoExtractor):
  13. IE_NAME = 'cliphunter'
  14. _VALID_URL = r'''(?x)http://(?:www\.)?cliphunter\.com/w/
  15. (?P<id>[0-9]+)/
  16. (?P<seo>.+?)(?:$|[#\?])
  17. '''
  18. _TEST = {
  19. 'url': 'http://www.cliphunter.com/w/1012420/Fun_Jynx_Maze_solo',
  20. 'md5': 'b7c9bbd4eb3a226ab91093714dcaa480',
  21. 'info_dict': {
  22. 'id': '1012420',
  23. 'ext': 'flv',
  24. 'title': 'Fun Jynx Maze solo',
  25. 'thumbnail': 're:^https?://.*\.jpg$',
  26. 'age_limit': 18,
  27. }
  28. }
  29. def _real_extract(self, url):
  30. video_id = self._match_id(url)
  31. webpage = self._download_webpage(url, video_id)
  32. video_title = self._search_regex(
  33. r'mediaTitle = "([^"]+)"', webpage, 'title')
  34. fmts = {}
  35. for fmt in ('mp4', 'flv'):
  36. fmt_list = self._parse_json(self._search_regex(
  37. r'var %sjson\s*=\s*(\[.*?\]);' % fmt, webpage, '%s formats' % fmt), video_id)
  38. for f in fmt_list:
  39. fmts[f['fname']] = _decode(f['sUrl'])
  40. qualities = self._parse_json(self._search_regex(
  41. r'var player_btns\s*=\s*(.*?);\n', webpage, 'quality info'), video_id)
  42. formats = []
  43. for fname, url in fmts.items():
  44. f = {
  45. 'url': url,
  46. }
  47. if fname in qualities:
  48. qual = qualities[fname]
  49. f.update({
  50. 'format_id': '%s_%sp' % (determine_ext(url), qual['h']),
  51. 'width': qual['w'],
  52. 'height': qual['h'],
  53. 'tbr': qual['br'],
  54. })
  55. formats.append(f)
  56. self._sort_formats(formats)
  57. thumbnail = self._search_regex(
  58. r"var\s+mov_thumb\s*=\s*'([^']+)';",
  59. webpage, 'thumbnail', fatal=False)
  60. return {
  61. 'id': video_id,
  62. 'title': video_title,
  63. 'formats': formats,
  64. 'age_limit': self._rta_search(webpage),
  65. 'thumbnail': thumbnail,
  66. }