Add support for downloading audio only

This commit is contained in:
Ivan Habunek 2022-02-05 13:57:49 +01:00
parent fbc227017d
commit 2fddb0c6a4
No known key found for this signature in database
GPG Key ID: CDBD63C43A30BB95
4 changed files with 25 additions and 5 deletions

View File

@ -147,6 +147,12 @@ Setting quality to `source` will download the best available quality:
twitch-dl download -q source 221837124
```
Setting quality to `audio_only` will download only audio:
```
twitch-dl download -q audio_only 221837124
```
### Overriding file name
The target filename can be defined by passing the `--output` option followed by

View File

@ -1,3 +1,8 @@
1.19.0:
date: TBA
changes:
- "Add support for downloading audio only (#10)"
1.18.1:
date: 2022-02-05
changes:

View File

@ -18,10 +18,15 @@ from twitchdl.output import print_out
def _parse_playlists(playlists_m3u8):
playlists = m3u8.loads(playlists_m3u8)
for p in playlists.playlists:
name = p.media[0].name if p.media else ""
resolution = "x".join(str(r) for r in p.stream_info.resolution)
yield name, resolution, p.uri
for p in sorted(playlists.playlists, key=lambda p: p.stream_info.resolution is None):
if p.stream_info.resolution:
name = p.media[0].name
description = "x".join(str(r) for r in p.stream_info.resolution)
else:
name = p.media[0].group_id
description = None
yield name, description, p.uri
def _get_playlist_by_name(playlists, quality):
@ -41,7 +46,10 @@ def _get_playlist_by_name(playlists, quality):
def _select_playlist_interactive(playlists):
print_out("\nAvailable qualities:")
for n, (name, resolution, uri) in enumerate(playlists):
if resolution:
print_out("{}) {} [{}]".format(n + 1, name, resolution))
else:
print_out("{}) {}".format(n + 1, name))
no = utils.read_int("Choose quality", min=1, max=len(playlists) + 1, default=1)
_, _, uri = playlists[no - 1]

View File

@ -309,6 +309,7 @@ def get_playlists(video_id, access_token):
response = requests.get(url, params={
"nauth": access_token['value'],
"nauthsig": access_token['signature'],
"allow_audio_only": "true",
"allow_source": "true",
"player": "twitchweb",
})