You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.8 KiB

10 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import ExtractorError
  6. class TriluliluIE(InfoExtractor):
  7. _VALID_URL = r'https?://(?:www\.)?trilulilu\.ro/(?:video-[^/]+/)?(?P<id>[^/#\?]+)'
  8. _TEST = {
  9. 'url': 'http://www.trilulilu.ro/video-animatie/big-buck-bunny-1',
  10. 'md5': 'c1450a00da251e2769b74b9005601cac',
  11. 'info_dict': {
  12. 'id': 'ae2899e124140b',
  13. 'ext': 'mp4',
  14. 'title': 'Big Buck Bunny',
  15. 'description': ':) pentru copilul din noi',
  16. },
  17. }
  18. def _real_extract(self, url):
  19. display_id = self._match_id(url)
  20. webpage = self._download_webpage(url, display_id)
  21. if re.search(r'Fişierul nu este disponibil pentru vizionare în ţara dumneavoastră', webpage):
  22. raise ExtractorError(
  23. 'This video is not available in your country.', expected=True)
  24. elif re.search('Fişierul poate fi accesat doar de către prietenii lui', webpage):
  25. raise ExtractorError('This video is private.', expected=True)
  26. flashvars_str = self._search_regex(
  27. r'block_flash_vars\s*=\s*(\{[^\}]+\})', webpage, 'flashvars', fatal=False, default=None)
  28. if flashvars_str:
  29. flashvars = self._parse_json(flashvars_str, display_id)
  30. else:
  31. raise ExtractorError(
  32. 'This page does not contain videos', expected=True)
  33. if flashvars['isMP3'] == 'true':
  34. raise ExtractorError(
  35. 'Audio downloads are currently not supported', expected=True)
  36. video_id = flashvars['hash']
  37. title = self._og_search_title(webpage)
  38. thumbnail = self._og_search_thumbnail(webpage)
  39. description = self._og_search_description(webpage, default=None)
  40. format_url = ('http://fs%(server)s.trilulilu.ro/%(hash)s/'
  41. 'video-formats2' % flashvars)
  42. format_doc = self._download_xml(
  43. format_url, video_id,
  44. note='Downloading formats',
  45. errnote='Error while downloading formats')
  46. video_url_template = (
  47. 'http://fs%(server)s.trilulilu.ro/stream.php?type=video'
  48. '&source=site&hash=%(hash)s&username=%(userid)s&'
  49. 'key=ministhebest&format=%%s&sig=&exp=' %
  50. flashvars)
  51. formats = [
  52. {
  53. 'format_id': fnode.text.partition('-')[2],
  54. 'url': video_url_template % fnode.text,
  55. 'ext': fnode.text.partition('-')[0]
  56. }
  57. for fnode in format_doc.findall('./formats/format')
  58. ]
  59. return {
  60. 'id': video_id,
  61. 'display_id': display_id,
  62. 'formats': formats,
  63. 'title': title,
  64. 'description': description,
  65. 'thumbnail': thumbnail,
  66. }