izlesene.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. get_element_by_id,
  7. parse_iso8601,
  8. determine_ext,
  9. int_or_none,
  10. str_to_int,
  11. )
  12. class IzleseneIE(InfoExtractor):
  13. _VALID_URL = r'''(?x)
  14. https?://(?:(?:www|m)\.)?izlesene\.com/
  15. (?:video|embedplayer)/(?:[^/]+/)?(?P<id>[0-9]+)
  16. '''
  17. _STREAM_URL = 'http://panel.izlesene.com/api/streamurl/{id:}/{format:}'
  18. _TESTS = [
  19. {
  20. 'url': 'http://www.izlesene.com/video/sevincten-cildirtan-dogum-gunu-hediyesi/7599694',
  21. 'md5': '4384f9f0ea65086734b881085ee05ac2',
  22. 'info_dict': {
  23. 'id': '7599694',
  24. 'ext': 'mp4',
  25. 'title': 'Sevinçten Çıldırtan Doğum Günü Hediyesi',
  26. 'description': 'md5:253753e2655dde93f59f74b572454f6d',
  27. 'thumbnail': 're:^http://.*\.jpg',
  28. 'uploader_id': 'pelikzzle',
  29. 'timestamp': 1404298698,
  30. 'upload_date': '20140702',
  31. 'duration': 95.395,
  32. 'age_limit': 0,
  33. }
  34. },
  35. {
  36. 'url': 'http://www.izlesene.com/video/tarkan-dortmund-2006-konseri/17997',
  37. 'md5': '97f09b6872bffa284cb7fa4f6910cb72',
  38. 'info_dict': {
  39. 'id': '17997',
  40. 'ext': 'mp4',
  41. 'title': 'Tarkan Dortmund 2006 Konseri',
  42. 'description': 'Tarkan Dortmund 2006 Konseri',
  43. 'thumbnail': 're:^http://.*\.jpg',
  44. 'uploader_id': 'parlayankiz',
  45. 'timestamp': 1163318593,
  46. 'upload_date': '20061112',
  47. 'duration': 253.666,
  48. 'age_limit': 0,
  49. }
  50. },
  51. ]
  52. def _real_extract(self, url):
  53. mobj = re.match(self._VALID_URL, url)
  54. video_id = mobj.group('id')
  55. url = 'http://www.izlesene.com/video/%s' % video_id
  56. webpage = self._download_webpage(url, video_id)
  57. title = self._og_search_title(webpage)
  58. description = self._og_search_description(webpage)
  59. thumbnail = self._og_search_thumbnail(webpage)
  60. uploader = self._html_search_regex(
  61. r"adduserUsername\s*=\s*'([^']+)';",
  62. webpage, 'uploader', fatal=False, default='')
  63. timestamp = parse_iso8601(self._html_search_meta(
  64. 'uploadDate', webpage, 'upload date', fatal=False))
  65. duration = int_or_none(self._html_search_regex(
  66. r'"videoduration"\s*:\s*"([^"]+)"',
  67. webpage, 'duration', fatal=False))
  68. if duration:
  69. duration /= 1000.0
  70. view_count = str_to_int(get_element_by_id('videoViewCount', webpage))
  71. comment_count = self._html_search_regex(
  72. r'comment_count\s*=\s*\'([^\']+)\';',
  73. webpage, 'comment_count', fatal=False)
  74. family_friendly = self._html_search_meta(
  75. 'isFamilyFriendly', webpage, 'age limit', fatal=False)
  76. content_url = self._html_search_meta(
  77. 'contentURL', webpage, 'content URL', fatal=False)
  78. ext = determine_ext(content_url, 'mp4')
  79. # Might be empty for some videos.
  80. streams = self._html_search_regex(
  81. r'"qualitylevel"\s*:\s*"([^"]+)"',
  82. webpage, 'streams', fatal=False, default='')
  83. formats = []
  84. if streams:
  85. for stream in streams.split('|'):
  86. quality, url = re.search(r'\[(\w+)\](.+)', stream).groups()
  87. formats.append({
  88. 'format_id': '%sp' % quality if quality else 'sd',
  89. 'url': url,
  90. 'ext': ext,
  91. })
  92. else:
  93. stream_url = self._search_regex(
  94. r'"streamurl"\s?:\s?"([^"]+)"', webpage, 'stream URL')
  95. formats.append({
  96. 'format_id': 'sd',
  97. 'url': stream_url,
  98. 'ext': ext,
  99. })
  100. return {
  101. 'id': video_id,
  102. 'title': title,
  103. 'description': description,
  104. 'thumbnail': thumbnail,
  105. 'uploader_id': uploader,
  106. 'timestamp': timestamp,
  107. 'duration': duration,
  108. 'view_count': int_or_none(view_count),
  109. 'comment_count': int_or_none(comment_count),
  110. 'age_limit': 18 if family_friendly == 'False' else 0,
  111. 'formats': formats,
  112. }