logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

trilulilu.py (3624B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. int_or_none,
  7. parse_iso8601,
  8. )
  9. class TriluliluIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:(?:www|m)\.)?trilulilu\.ro/(?:[^/]+/)?(?P<id>[^/#\?]+)'
  11. _TESTS = [{
  12. 'url': 'http://www.trilulilu.ro/big-buck-bunny-1',
  13. 'md5': '68da087b676a6196a413549212f60cc6',
  14. 'info_dict': {
  15. 'id': 'ae2899e124140b',
  16. 'ext': 'mp4',
  17. 'title': 'Big Buck Bunny',
  18. 'description': ':) pentru copilul din noi',
  19. 'uploader_id': 'chipy',
  20. 'upload_date': '20120304',
  21. 'timestamp': 1330830647,
  22. 'uploader': 'chipy',
  23. 'view_count': int,
  24. 'like_count': int,
  25. 'comment_count': int,
  26. },
  27. }, {
  28. 'url': 'http://www.trilulilu.ro/adena-ft-morreti-inocenta',
  29. 'md5': '929dfb8729dc71750463af88bbbbf4a4',
  30. 'info_dict': {
  31. 'id': 'f299710e3c91c5',
  32. 'ext': 'mp4',
  33. 'title': 'Adena ft. Morreti - Inocenta',
  34. 'description': 'pop music',
  35. 'uploader_id': 'VEVOmixt',
  36. 'upload_date': '20151204',
  37. 'uploader': 'VEVOmixt',
  38. 'timestamp': 1449187937,
  39. 'view_count': int,
  40. 'like_count': int,
  41. 'comment_count': int,
  42. },
  43. }]
  44. def _real_extract(self, url):
  45. display_id = self._match_id(url)
  46. media_info = self._download_json('http://m.trilulilu.ro/%s?format=json' % display_id, display_id)
  47. age_limit = 0
  48. errors = media_info.get('errors', {})
  49. if errors.get('friends'):
  50. raise ExtractorError('This video is private.', expected=True)
  51. elif errors.get('geoblock'):
  52. raise ExtractorError('This video is not available in your country.', expected=True)
  53. elif errors.get('xxx_unlogged'):
  54. age_limit = 18
  55. media_class = media_info.get('class')
  56. if media_class not in ('video', 'audio'):
  57. raise ExtractorError('not a video or an audio')
  58. user = media_info.get('user', {})
  59. thumbnail = media_info.get('cover_url')
  60. if thumbnail:
  61. thumbnail.format(width='1600', height='1200')
  62. # TODO: get correct ext for audio files
  63. stream_type = media_info.get('stream_type')
  64. formats = [{
  65. 'url': media_info['href'],
  66. 'ext': stream_type,
  67. }]
  68. if media_info.get('is_hd'):
  69. formats.append({
  70. 'format_id': 'hd',
  71. 'url': media_info['hrefhd'],
  72. 'ext': stream_type,
  73. })
  74. if media_class == 'audio':
  75. formats[0]['vcodec'] = 'none'
  76. else:
  77. formats[0]['format_id'] = 'sd'
  78. return {
  79. 'id': media_info['identifier'].split('|')[1],
  80. 'display_id': display_id,
  81. 'formats': formats,
  82. 'title': media_info['title'],
  83. 'description': media_info.get('description'),
  84. 'thumbnail': thumbnail,
  85. 'uploader_id': user.get('username'),
  86. 'uploader': user.get('fullname'),
  87. 'timestamp': parse_iso8601(media_info.get('published'), ' '),
  88. 'duration': int_or_none(media_info.get('duration')),
  89. 'view_count': int_or_none(media_info.get('count_views')),
  90. 'like_count': int_or_none(media_info.get('count_likes')),
  91. 'comment_count': int_or_none(media_info.get('count_comments')),
  92. 'age_limit': age_limit,
  93. }