izlesene.py 4.3 KB

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