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.

67 lines
2.1 KiB

  1. Using the ``youtube_dl`` module
  2. ===============================
  3. When using the ``youtube_dl`` module, you start by creating an instance of :class:`YoutubeDL` and adding all the available extractors:
  4. .. code-block:: python
  5. >>> from youtube_dl import YoutubeDL
  6. >>> ydl = YoutubeDL()
  7. >>> ydl.add_default_info_extractors()
  8. Extracting video information
  9. ----------------------------
  10. You use the :meth:`YoutubeDL.extract_info` method for getting the video information, which returns a dictionary:
  11. .. code-block:: python
  12. >>> info = ydl.extract_info('http://www.youtube.com/watch?v=BaW_jenozKc', download=False)
  13. [youtube] Setting language
  14. [youtube] BaW_jenozKc: Downloading webpage
  15. [youtube] BaW_jenozKc: Downloading video info webpage
  16. [youtube] BaW_jenozKc: Extracting video information
  17. >>> info['title']
  18. 'youtube-dl test video "\'/\\ä↭𝕐'
  19. >>> info['height'], info['width']
  20. (720, 1280)
  21. If you want to download or play the video you can get its url:
  22. .. code-block:: python
  23. >>> info['url']
  24. 'https://...'
  25. Extracting playlist information
  26. -------------------------------
  27. The playlist information is extracted in a similar way, but the dictionary is a bit different:
  28. .. code-block:: python
  29. >>> playlist = ydl.extract_info('http://www.ted.com/playlists/13/open_source_open_world', download=False)
  30. [TED] open_source_open_world: Downloading playlist webpage
  31. ...
  32. >>> playlist['title']
  33. 'Open-source, open world'
  34. You can access the videos in the playlist with the ``entries`` field:
  35. .. code-block:: python
  36. >>> for video in playlist['entries']:
  37. ... print('Video #%d: %s' % (video['playlist_index'], video['title']))
  38. Video #1: How Arduino is open-sourcing imagination
  39. Video #2: The year open data went worldwide
  40. Video #3: Massive-scale online collaboration
  41. Video #4: The art of asking
  42. Video #5: How cognitive surplus will change the world
  43. Video #6: The birth of Wikipedia
  44. Video #7: Coding a better government
  45. Video #8: The era of open innovation
  46. Video #9: The currency of the new economy is trust