izlesene.py 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import get_element_by_id, parse_iso8601, determine_ext, int_or_none
  6. class IzleseneIE(InfoExtractor):
  7. _VALID_URL = r'https?://(?:www\.|m\.)?izlesene\.com/(?:video|embedplayer)/(?:[^/]+/)?(?P<id>[0-9]+)'
  8. _STREAM_URL = 'http://panel.izlesene.com/api/streamurl/{id:}/{format:}'
  9. _TEST = {
  10. 'url': 'http://www.izlesene.com/video/sevincten-cildirtan-dogum-gunu-hediyesi/7599694',
  11. 'md5': '4384f9f0ea65086734b881085ee05ac2',
  12. 'info_dict': {
  13. 'id': '7599694',
  14. 'title': u'Sevinçten Çıldırtan Doğum Günü Hediyesi',
  15. 'upload_date': '20140702',
  16. 'uploader_id': 'pelikzzle',
  17. 'description': u'Annesi oğluna doğum günü hediyesi olarak minecraft cd si alıyor, ve çocuk hunharca seviniyor',
  18. 'timestamp': 1404298698,
  19. 'duration': 95,
  20. 'ext': 'mp4',
  21. 'thumbnail': 're:^http://.*\.jpg',
  22. 'age_limit': 0,
  23. }
  24. }
  25. def _real_extract(self, url):
  26. mobj = re.match(self._VALID_URL, url)
  27. video_id = mobj.group('id')
  28. url = 'http://www.izlesene.com/video/%s' % video_id
  29. webpage = self._download_webpage(url, video_id)
  30. title = self._og_search_title(webpage)
  31. description = self._og_search_description(webpage)
  32. thumbnail = self._og_search_thumbnail(webpage)
  33. duration = int(
  34. self._html_search_regex(
  35. r'"videoduration"\s?:\s?"([^"]+)"', webpage, 'duration',
  36. fatal=False, default='0')
  37. ) / 1000
  38. view_count = get_element_by_id('videoViewCount',
  39. webpage).replace('.', '')
  40. timestamp = parse_iso8601(self._html_search_meta('uploadDate', webpage,
  41. 'upload date', fatal=False))
  42. family_friendly = self._html_search_meta('isFamilyFriendly', webpage,
  43. 'age limit', fatal=False)
  44. uploader = self._html_search_regex(r"adduserUsername\s?=\s?'([^']+)';",
  45. webpage, 'uploader', fatal=False,
  46. default='')
  47. comment_count = self._html_search_regex(
  48. r'comment_count\s?=\s?\'([^\']+)\';',
  49. webpage, 'uploader', fatal=False)
  50. content_url = self._html_search_meta('contentURL', webpage,
  51. 'content URL', fatal=False)
  52. ext = determine_ext(content_url)
  53. # Might be empty for some videos.
  54. qualities = self._html_search_regex(r'"quality"\s?:\s?"([^"]+)"',
  55. webpage, 'qualities', fatal=False,
  56. default='')
  57. formats = []
  58. for quality in qualities.split('|'):
  59. json = self._download_json(
  60. self._STREAM_URL.format(id=video_id, format=quality), video_id,
  61. note=u'Getting video URL for "%s" quality' % quality,
  62. errnote=u'Failed to get video URL for "%s" quality' % quality
  63. )
  64. video_format = '%sp' % quality if quality else 'sd'
  65. formats.append({
  66. 'url': json.get('streamurl'),
  67. 'ext': ext,
  68. 'format': video_format,
  69. 'format_id': video_format,
  70. })
  71. return {
  72. 'id': video_id,
  73. 'title': title,
  74. 'formats': formats,
  75. 'description': description,
  76. 'thumbnail': thumbnail,
  77. 'duration': duration,
  78. 'view_count': int_or_none(view_count),
  79. 'timestamp': timestamp,
  80. 'age_limit': 18 if family_friendly == 'False' else 0,
  81. 'uploader_id': uploader,
  82. 'comment_count': int_or_none(comment_count),
  83. }