mirror of
https://github.com/ihabunek/twitch-dl
synced 2024-08-30 18:32:25 +00:00
Add compact videos display
This commit is contained in:
parent
f289c93305
commit
4d19f09065
@ -12,6 +12,7 @@ implementation of new features, but has no breaking changes for the CLI.
|
|||||||
* **BREAKING**: Require Python 3.7 or later.
|
* **BREAKING**: Require Python 3.7 or later.
|
||||||
* Add `--rate-limit` option to `download` for limiting maximum bandwidth when
|
* Add `--rate-limit` option to `download` for limiting maximum bandwidth when
|
||||||
downloading.
|
downloading.
|
||||||
|
* Add `--compact` option to `download` for displaying one video per line.
|
||||||
* Allow passing multiple video ids to `download` to download multiple videos
|
* Allow passing multiple video ids to `download` to download multiple videos
|
||||||
successively.
|
successively.
|
||||||
* Improved progress meter, updates on each chunk downloaded, instead of each VOD
|
* Improved progress meter, updates on each chunk downloaded, instead of each VOD
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
changes:
|
changes:
|
||||||
- "**BREAKING**: Require Python 3.7 or later."
|
- "**BREAKING**: Require Python 3.7 or later."
|
||||||
- "Add `--rate-limit` option to `download` for limiting maximum bandwidth when downloading."
|
- "Add `--rate-limit` option to `download` for limiting maximum bandwidth when downloading."
|
||||||
|
- "Add `--compact` option to `download` for displaying one video per line."
|
||||||
- "Allow passing multiple video ids to `download` to download multiple videos successively."
|
- "Allow passing multiple video ids to `download` to download multiple videos successively."
|
||||||
- "Improved progress meter, updates on each chunk downloaded, instead of each VOD downloaded."
|
- "Improved progress meter, updates on each chunk downloaded, instead of each VOD downloaded."
|
||||||
- "Improved speed estimate, displays recent speed instead of average speed since the start of download."
|
- "Improved speed estimate, displays recent speed instead of average speed since the start of download."
|
||||||
|
@ -12,6 +12,7 @@ implementation of new features, but has no breaking changes for the CLI.
|
|||||||
* **BREAKING**: Require Python 3.7 or later.
|
* **BREAKING**: Require Python 3.7 or later.
|
||||||
* Add `--rate-limit` option to `download` for limiting maximum bandwidth when
|
* Add `--rate-limit` option to `download` for limiting maximum bandwidth when
|
||||||
downloading.
|
downloading.
|
||||||
|
* Add `--compact` option to `download` for displaying one video per line.
|
||||||
* Allow passing multiple video ids to `download` to download multiple videos
|
* Allow passing multiple video ids to `download` to download multiple videos
|
||||||
successively.
|
successively.
|
||||||
* Improved progress meter, updates on each chunk downloaded, instead of each VOD
|
* Improved progress meter, updates on each chunk downloaded, instead of each VOD
|
||||||
|
@ -33,6 +33,11 @@ twitch-dl videos <channel_name> [FLAGS] [OPTIONS]
|
|||||||
<td class="code">-j, --json</td>
|
<td class="code">-j, --json</td>
|
||||||
<td>Show results as JSON. Ignores <code>--pager</code>.</td>
|
<td>Show results as JSON. Ignores <code>--pager</code>.</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td class="code">-c, --compact</td>
|
||||||
|
<td>Show videos in compact mode, one line per video</td>
|
||||||
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ import sys
|
|||||||
|
|
||||||
from twitchdl import twitch
|
from twitchdl import twitch
|
||||||
from twitchdl.exceptions import ConsoleError
|
from twitchdl.exceptions import ConsoleError
|
||||||
from twitchdl.output import print_out, print_paged_videos, print_video, print_json
|
from twitchdl.output import print_out, print_paged_videos, print_video, print_json, print_video_compact
|
||||||
|
|
||||||
|
|
||||||
def videos(args):
|
def videos(args):
|
||||||
@ -32,6 +32,9 @@ def videos(args):
|
|||||||
|
|
||||||
count = 0
|
count = 0
|
||||||
for video in generator:
|
for video in generator:
|
||||||
|
if args.compact:
|
||||||
|
print_video_compact(video)
|
||||||
|
else:
|
||||||
print_out()
|
print_out()
|
||||||
print_video(video)
|
print_video(video)
|
||||||
count += 1
|
count += 1
|
||||||
|
@ -112,6 +112,11 @@ COMMANDS = [
|
|||||||
"nargs": "?",
|
"nargs": "?",
|
||||||
"const": 10,
|
"const": 10,
|
||||||
}),
|
}),
|
||||||
|
(["-c", "--compact"], {
|
||||||
|
"help": "Show videos in compact mode, one line per video",
|
||||||
|
"action": "store_true",
|
||||||
|
"default": False,
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Command(
|
Command(
|
||||||
|
@ -48,6 +48,13 @@ def strip_tags(text):
|
|||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
||||||
|
def truncate(string, length):
|
||||||
|
if len(string) > length:
|
||||||
|
return string[:length - 1] + "…"
|
||||||
|
|
||||||
|
return string
|
||||||
|
|
||||||
|
|
||||||
def print_out(*args, **kwargs):
|
def print_out(*args, **kwargs):
|
||||||
args = [colorize(a) if USE_ANSI_COLOR else strip_tags(a) for a in args]
|
args = [colorize(a) if USE_ANSI_COLOR else strip_tags(a) for a in args]
|
||||||
print(*args, **kwargs)
|
print(*args, **kwargs)
|
||||||
@ -89,6 +96,14 @@ def print_video(video):
|
|||||||
print_out("<i>{}</i>".format(url))
|
print_out("<i>{}</i>".format(url))
|
||||||
|
|
||||||
|
|
||||||
|
def print_video_compact(video):
|
||||||
|
id = video["id"]
|
||||||
|
date = video["publishedAt"][:10]
|
||||||
|
game = video["game"]["name"] if video["game"] else ""
|
||||||
|
title = truncate(video["title"], 80).ljust(80)
|
||||||
|
print_out(f'<b>{id}</b> {date} <green>{title}</green> <blue>{game}</blue>')
|
||||||
|
|
||||||
|
|
||||||
def print_paged_videos(generator, page_size, total_count):
|
def print_paged_videos(generator, page_size, total_count):
|
||||||
iterator = iter(generator)
|
iterator = iter(generator)
|
||||||
page = list(islice(iterator, page_size))
|
page = list(islice(iterator, page_size))
|
||||||
|
Loading…
Reference in New Issue
Block a user