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