This commit is contained in:
pukkandan 2022-04-18 04:39:25 +05:30
parent 77f9033095
commit 43cc91ad75
No known key found for this signature in database
GPG key ID: 7EEE9E1E817D0A39
2 changed files with 9 additions and 8 deletions

View file

@ -60,6 +60,7 @@
* [EXTRACTOR ARGUMENTS](#extractor-arguments) * [EXTRACTOR ARGUMENTS](#extractor-arguments)
* [PLUGINS](#plugins) * [PLUGINS](#plugins)
* [EMBEDDING YT-DLP](#embedding-yt-dlp) * [EMBEDDING YT-DLP](#embedding-yt-dlp)
* [Embedding examples](#embedding-examples)
* [DEPRECATED OPTIONS](#deprecated-options) * [DEPRECATED OPTIONS](#deprecated-options)
* [CONTRIBUTING](CONTRIBUTING.md#contributing-to-yt-dlp) * [CONTRIBUTING](CONTRIBUTING.md#contributing-to-yt-dlp)
* [Opening an Issue](CONTRIBUTING.md#opening-an-issue) * [Opening an Issue](CONTRIBUTING.md#opening-an-issue)
@ -1755,11 +1756,11 @@ # EMBEDDING YT-DLP
Most likely, you'll want to use various options. For a list of options available, have a look at [`yt_dlp/YoutubeDL.py`](yt_dlp/YoutubeDL.py#L181). Most likely, you'll want to use various options. For a list of options available, have a look at [`yt_dlp/YoutubeDL.py`](yt_dlp/YoutubeDL.py#L181).
**Tip**: If you are porting your code from youtube-dl to yt-dlp, one important point to look out for is that we do not guarantee the return value of `YoutubeDL.extract_info` to be json serializable, or even be a dictionary. It will be dictionary-like, but if you want to ensure it is a serializable dictionary, pass it through `YoutubeDL.sanitize_info` as shown in the example above **Tip**: If you are porting your code from youtube-dl to yt-dlp, one important point to look out for is that we do not guarantee the return value of `YoutubeDL.extract_info` to be json serializable, or even be a dictionary. It will be dictionary-like, but if you want to ensure it is a serializable dictionary, pass it through `YoutubeDL.sanitize_info` as shown in the [example below](#extracting-information)
## Embedding examples ## Embedding examples
### Extracting information #### Extracting information
```python ```python
import json import json
@ -1775,7 +1776,7 @@ # See help(yt_dlp.YoutubeDL) for a list of available options and public f
# ydl.sanitize_info makes the info json-serializable # ydl.sanitize_info makes the info json-serializable
print(json.dumps(ydl.sanitize_info(info))) print(json.dumps(ydl.sanitize_info(info)))
``` ```
### Download from info-json #### Download using an info-json
```python ```python
import yt_dlp import yt_dlp
@ -1789,7 +1790,7 @@ ### Download from info-json
else 'All videos successfully downloaded') else 'All videos successfully downloaded')
``` ```
### Extract audio #### Extract audio
```python ```python
import yt_dlp import yt_dlp
@ -1808,7 +1809,7 @@ ### Extract audio
with yt_dlp.YoutubeDL(ydl_opts) as ydl: with yt_dlp.YoutubeDL(ydl_opts) as ydl:
error_code = ydl.download(URLS) error_code = ydl.download(URLS)
``` ```
### Adding logger and progress hook #### Adding logger and progress hook
```python ```python
import yt_dlp import yt_dlp
@ -1849,7 +1850,7 @@ # See "progress_hooks" in help(yt_dlp.YoutubeDL)
ydl.download(URLS) ydl.download(URLS)
``` ```
### Add a custom PostProcessor #### Add a custom PostProcessor
```python ```python
import yt_dlp import yt_dlp
@ -1869,7 +1870,7 @@ # See help(yt_dlp.postprocessor.PostProcessor)
``` ```
### Use a custom format selector #### Use a custom format selector
```python ```python
import yt_dlp import yt_dlp

View file

@ -431,7 +431,7 @@ def download(self, filename, info_dict, subtitle=False):
else: else:
min_sleep_interval = self.params.get('sleep_interval') or 0 min_sleep_interval = self.params.get('sleep_interval') or 0
sleep_interval = random.uniform( sleep_interval = random.uniform(
min_sleep_interval, self.params.get('max_sleep_interval', min_sleep_interval)) min_sleep_interval, self.params.get('max_sleep_interval') or min_sleep_interval)
if sleep_interval > 0: if sleep_interval > 0:
self.to_screen(f'[download] Sleeping {sleep_interval:.2f} seconds ...') self.to_screen(f'[download] Sleeping {sleep_interval:.2f} seconds ...')
time.sleep(sleep_interval) time.sleep(sleep_interval)