chore: Update version to 0.7.1 and improve poster display using viu
This commit is contained in:
BIN
dist/renamer-0.7.1-py3-none-any.whl
vendored
Normal file
BIN
dist/renamer-0.7.1-py3-none-any.whl
vendored
Normal file
Binary file not shown.
@@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "renamer"
|
||||
version = "0.6.12"
|
||||
version = "0.7.1"
|
||||
description = "Terminal-based media file renamer and metadata viewer"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.11"
|
||||
|
||||
@@ -74,39 +74,31 @@ class CatalogFormatter:
|
||||
return console.file.getvalue()
|
||||
|
||||
def _display_poster(self, image_path: str) -> str:
|
||||
"""Display poster image in terminal using simple ASCII art"""
|
||||
"""Display poster image in terminal using viu"""
|
||||
import subprocess
|
||||
import shutil
|
||||
|
||||
if not os.path.exists(image_path):
|
||||
return f"Image file not found: {image_path}"
|
||||
|
||||
# Check if viu is available
|
||||
if not shutil.which('viu'):
|
||||
return f"viu not installed. Install with: cargo install viu\nPoster at: {image_path}"
|
||||
|
||||
try:
|
||||
from PIL import Image
|
||||
import os
|
||||
# Run viu to render the image
|
||||
# -w 40: width in characters
|
||||
# -h 30: height in characters
|
||||
# -t: transparent background
|
||||
result = subprocess.run(
|
||||
['viu', '-w', '40', '-t', image_path],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True
|
||||
)
|
||||
return result.stdout
|
||||
|
||||
if not os.path.exists(image_path):
|
||||
return f"Image file not found: {image_path}"
|
||||
|
||||
# Open and resize image
|
||||
img = Image.open(image_path).convert('L').resize((80, 40), Image.Resampling.LANCZOS)
|
||||
|
||||
# ASCII characters from dark to light
|
||||
ascii_chars = '@%#*+=-:. '
|
||||
|
||||
# Convert to ASCII
|
||||
pixels = img.getdata()
|
||||
width, height = img.size
|
||||
|
||||
ascii_art = []
|
||||
for y in range(0, height, 2): # Skip every other row for aspect ratio
|
||||
row = []
|
||||
for x in range(width):
|
||||
# Average of two rows for better aspect
|
||||
pixel1 = pixels[y * width + x] if y < height else 255
|
||||
pixel2 = pixels[(y + 1) * width + x] if y + 1 < height else 255
|
||||
avg = (pixel1 + pixel2) // 2
|
||||
char = ascii_chars[avg * len(ascii_chars) // 256]
|
||||
row.append(char)
|
||||
ascii_art.append(''.join(row))
|
||||
|
||||
return '\n'.join(ascii_art)
|
||||
|
||||
except ImportError:
|
||||
return f"Image at {image_path} (PIL not available)"
|
||||
except subprocess.CalledProcessError as e:
|
||||
return f"Failed to render image with viu: {e.stderr}\nPoster at: {image_path}"
|
||||
except Exception as e:
|
||||
return f"Failed to display image at {image_path}: {e}"
|
||||
return f"Failed to display image: {e}\nPoster at: {image_path}"
|
||||
Reference in New Issue
Block a user