Add --raw flag to view command and improve metadata display
- Add --raw/-r flag to fetch from /cache/{cid}/raw endpoint
- Automatically use /raw when outputting to file or stdout
- Show friendly_name, title, filename in metadata view
- Use JSON API for metadata instead of streaming response
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
31
artdag.py
31
artdag.py
@@ -748,12 +748,18 @@ def cache(limit, offset, media_type):
|
|||||||
@cli.command()
|
@cli.command()
|
||||||
@click.argument("cid")
|
@click.argument("cid")
|
||||||
@click.option("--output", "-o", type=click.Path(), help="Save to file (use - for stdout)")
|
@click.option("--output", "-o", type=click.Path(), help="Save to file (use - for stdout)")
|
||||||
def view(cid, output):
|
@click.option("--raw", "-r", is_flag=True, help="Get raw content (use with -o to download)")
|
||||||
|
def view(cid, output, raw):
|
||||||
"""View or download cached content.
|
"""View or download cached content.
|
||||||
|
|
||||||
Use -o - to pipe to stdout, e.g.: artdag view <cid> -o - | mpv -
|
Use -o - to pipe to stdout, e.g.: artdag view <cid> -o - | mpv -
|
||||||
|
Use --raw to get the raw file content instead of metadata.
|
||||||
"""
|
"""
|
||||||
url = f"{get_server()}/cache/{cid}"
|
# Use /raw endpoint if --raw flag or if outputting to file/stdout
|
||||||
|
if raw or output:
|
||||||
|
url = f"{get_server()}/cache/{cid}/raw"
|
||||||
|
else:
|
||||||
|
url = f"{get_server()}/cache/{cid}"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if output == "-":
|
if output == "-":
|
||||||
@@ -771,16 +777,21 @@ def view(cid, output):
|
|||||||
f.write(chunk)
|
f.write(chunk)
|
||||||
click.echo(f"Saved to: {output}", err=True)
|
click.echo(f"Saved to: {output}", err=True)
|
||||||
else:
|
else:
|
||||||
# Get info via GET with stream to check size
|
# Get info - use JSON endpoint for metadata
|
||||||
resp = requests.get(url, stream=True)
|
headers = {"Accept": "application/json"}
|
||||||
|
resp = requests.get(f"{get_server()}/cache/{cid}", headers=headers)
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
size = resp.headers.get("content-length", "unknown")
|
info = resp.json()
|
||||||
content_type = resp.headers.get("content-type", "unknown")
|
|
||||||
click.echo(f"CID: {cid}")
|
click.echo(f"CID: {cid}")
|
||||||
click.echo(f"Size: {size} bytes")
|
click.echo(f"Size: {info.get('size', 'unknown')} bytes")
|
||||||
click.echo(f"Type: {content_type}")
|
click.echo(f"Type: {info.get('mime_type') or info.get('media_type', 'unknown')}")
|
||||||
click.echo(f"URL: {url}")
|
if info.get('friendly_name'):
|
||||||
resp.close()
|
click.echo(f"Friendly Name: {info['friendly_name']}")
|
||||||
|
if info.get('title'):
|
||||||
|
click.echo(f"Title: {info['title']}")
|
||||||
|
if info.get('filename'):
|
||||||
|
click.echo(f"Filename: {info['filename']}")
|
||||||
|
click.echo(f"Raw URL: {get_server()}/cache/{cid}/raw")
|
||||||
except requests.HTTPError as e:
|
except requests.HTTPError as e:
|
||||||
if e.response.status_code == 404:
|
if e.response.status_code == 404:
|
||||||
click.echo(f"Not found: {cid}", err=True)
|
click.echo(f"Not found: {cid}", err=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user