mirror of
https://github.com/ihabunek/twitch-dl
synced 2024-08-30 18:32:25 +00:00
Add rate limiting to download
This commit is contained in:
@ -79,6 +79,11 @@ twitch-dl download <video> [FLAGS] [OPTIONS]
|
|||||||
<td class="code">-o, --output</td>
|
<td class="code">-o, --output</td>
|
||||||
<td>Output file name template. See docs for details.</td>
|
<td>Output file name template. See docs for details.</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td class="code">-r, --rate-limit</td>
|
||||||
|
<td>Limit the maximum download speed in bytes per second. Use 'k' and 'm' suffixes for kbps and mbps.</td>
|
||||||
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
@ -172,4 +177,4 @@ download command:
|
|||||||
|
|
||||||
```
|
```
|
||||||
twitch-dl download 221837124 --auth-token iduetx4i107rn4b9wrgctf590aiktv
|
twitch-dl download 221837124 --auth-token iduetx4i107rn4b9wrgctf590aiktv
|
||||||
```
|
```
|
@ -305,7 +305,7 @@ def _download_video(video_id, args):
|
|||||||
len(vod_paths), args.max_workers, target_dir))
|
len(vod_paths), args.max_workers, target_dir))
|
||||||
sources = [base_uri + path for path in vod_paths]
|
sources = [base_uri + path for path in vod_paths]
|
||||||
targets = [os.path.join(target_dir, "{:05d}.ts".format(k)) for k, _ in enumerate(vod_paths)]
|
targets = [os.path.join(target_dir, "{:05d}.ts".format(k)) for k, _ in enumerate(vod_paths)]
|
||||||
asyncio.run(download_all(sources, targets, args.max_workers))
|
asyncio.run(download_all(sources, targets, args.max_workers, rate_limit=args.rate_limit))
|
||||||
|
|
||||||
# Make a modified playlist which references downloaded VODs
|
# Make a modified playlist which references downloaded VODs
|
||||||
# Keep only the downloaded segments and skip the rest
|
# Keep only the downloaded segments and skip the rest
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
|
import re
|
||||||
|
|
||||||
from argparse import ArgumentParser, ArgumentTypeError
|
from argparse import ArgumentParser, ArgumentTypeError
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
@ -46,6 +47,24 @@ def pos_integer(value):
|
|||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
def rate(value):
|
||||||
|
match = re.search(r"^([0-9]+)(k|m|)$", value, flags=re.IGNORECASE)
|
||||||
|
|
||||||
|
if not match:
|
||||||
|
raise ArgumentTypeError("must be an integer, followed by an optional 'k' or 'm'")
|
||||||
|
|
||||||
|
amount = int(match.group(1))
|
||||||
|
unit = match.group(2)
|
||||||
|
|
||||||
|
if unit == "k":
|
||||||
|
return amount * 1024
|
||||||
|
|
||||||
|
if unit == "m":
|
||||||
|
return amount * 1024 * 1024
|
||||||
|
|
||||||
|
return amount
|
||||||
|
|
||||||
|
|
||||||
COMMANDS = [
|
COMMANDS = [
|
||||||
Command(
|
Command(
|
||||||
name="videos",
|
name="videos",
|
||||||
@ -197,7 +216,12 @@ COMMANDS = [
|
|||||||
"help": "Output file name template. See docs for details.",
|
"help": "Output file name template. See docs for details.",
|
||||||
"type": str,
|
"type": str,
|
||||||
"default": "{date}_{id}_{channel_login}_{title_slug}.{format}"
|
"default": "{date}_{id}_{channel_login}_{title_slug}.{format}"
|
||||||
})
|
}),
|
||||||
|
(["-r", "--rate-limit"], {
|
||||||
|
"help": "Limit the maximum download speed in bytes per second. "
|
||||||
|
"Use 'k' and 'm' suffixes for kbps and mbps.",
|
||||||
|
"type": rate,
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Command(
|
Command(
|
||||||
|
Reference in New Issue
Block a user