trilulilu.py 3.5 KB

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