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]
|
[project]
|
||||||
name = "renamer"
|
name = "renamer"
|
||||||
version = "0.6.12"
|
version = "0.7.1"
|
||||||
description = "Terminal-based media file renamer and metadata viewer"
|
description = "Terminal-based media file renamer and metadata viewer"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.11"
|
requires-python = ">=3.11"
|
||||||
|
|||||||
@@ -74,39 +74,31 @@ class CatalogFormatter:
|
|||||||
return console.file.getvalue()
|
return console.file.getvalue()
|
||||||
|
|
||||||
def _display_poster(self, image_path: str) -> str:
|
def _display_poster(self, image_path: str) -> str:
|
||||||
"""Display poster image in terminal using simple ASCII art"""
|
"""Display poster image in terminal using viu"""
|
||||||
try:
|
import subprocess
|
||||||
from PIL import Image
|
import shutil
|
||||||
import os
|
|
||||||
|
|
||||||
if not os.path.exists(image_path):
|
if not os.path.exists(image_path):
|
||||||
return f"Image file not found: {image_path}"
|
return f"Image file not found: {image_path}"
|
||||||
|
|
||||||
# Open and resize image
|
# Check if viu is available
|
||||||
img = Image.open(image_path).convert('L').resize((80, 40), Image.Resampling.LANCZOS)
|
if not shutil.which('viu'):
|
||||||
|
return f"viu not installed. Install with: cargo install viu\nPoster at: {image_path}"
|
||||||
|
|
||||||
# ASCII characters from dark to light
|
try:
|
||||||
ascii_chars = '@%#*+=-:. '
|
# 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
|
||||||
|
|
||||||
# Convert to ASCII
|
except subprocess.CalledProcessError as e:
|
||||||
pixels = img.getdata()
|
return f"Failed to render image with viu: {e.stderr}\nPoster at: {image_path}"
|
||||||
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 Exception as e:
|
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