logo

youtube-dl

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

test_youtube_lists.py (2494B)


  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. from __future__ import unicode_literals
  4. # Allow direct execution
  5. import os
  6. import sys
  7. import unittest
  8. sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  9. from test.helper import FakeYDL
  10. from youtube_dl.extractor import (
  11. YoutubeIE,
  12. YoutubePlaylistIE,
  13. YoutubeTabIE,
  14. )
  15. class TestYoutubeLists(unittest.TestCase):
  16. def assertIsPlaylist(self, info):
  17. """Make sure the info has '_type' set to 'playlist'"""
  18. self.assertEqual(info['_type'], 'playlist')
  19. def test_youtube_playlist_noplaylist(self):
  20. dl = FakeYDL()
  21. dl.params['noplaylist'] = True
  22. dl.params['format'] = 'best'
  23. ie = YoutubePlaylistIE(dl)
  24. result = ie.extract('https://www.youtube.com/watch?v=FXxLjLQi3Fg&list=PLwiyx1dc3P2JR9N8gQaQN_BCvlSlap7re')
  25. self.assertEqual(result['_type'], 'url')
  26. result = dl.extract_info(result['url'], download=False, ie_key=result.get('ie_key'), process=False)
  27. self.assertEqual(YoutubeIE().extract_id(result['url']), 'FXxLjLQi3Fg')
  28. def test_youtube_mix(self):
  29. dl = FakeYDL()
  30. dl.params['format'] = 'best'
  31. ie = YoutubeTabIE(dl)
  32. result = dl.extract_info('https://www.youtube.com/watch?v=tyITL_exICo&list=RDCLAK5uy_kLWIr9gv1XLlPbaDS965-Db4TrBoUTxQ8',
  33. download=False, ie_key=ie.ie_key(), process=True)
  34. entries = (result or {}).get('entries', [{'id': 'not_found', }])
  35. self.assertTrue(len(entries) >= 25)
  36. original_video = entries[0]
  37. self.assertEqual(original_video['id'], 'tyITL_exICo')
  38. def test_youtube_flat_playlist_extraction(self):
  39. dl = FakeYDL()
  40. dl.params['extract_flat'] = True
  41. ie = YoutubeTabIE(dl)
  42. result = ie.extract('https://www.youtube.com/playlist?list=PL4lCao7KL_QFVb7Iudeipvc2BCavECqzc')
  43. self.assertIsPlaylist(result)
  44. entries = list(result['entries'])
  45. self.assertTrue(len(entries) == 1)
  46. video = entries[0]
  47. self.assertEqual(video['_type'], 'url')
  48. self.assertEqual(video['ie_key'], 'Youtube')
  49. self.assertEqual(video['id'], 'BaW_jenozKc')
  50. self.assertEqual(video['url'], 'BaW_jenozKc')
  51. self.assertEqual(video['title'], 'youtube-dl test video "\'/\\ä↭𝕐')
  52. self.assertEqual(video['duration'], 10)
  53. self.assertEqual(video['uploader'], 'Philipp Hagemeister')
  54. if __name__ == '__main__':
  55. unittest.main()