Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
Merge pull request #10 from bobcogneato/patch-20231202-01
Browse files Browse the repository at this point in the history
Better title cutting
  • Loading branch information
feederbox826 authored Dec 6, 2023
2 parents 6fd59ac + fbd6e55 commit bacd146
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions SHALookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from html import unescape
import re
from pathlib import Path
import emojis
from confusables import remove
from sqlite import lookup_sha, add_sha256, setup_sqlite
from oftitle import findTrailerTrigger
Expand Down Expand Up @@ -117,6 +118,13 @@ def truncate_title(title, max_length):
# Check if the title is already under max length
if len(title) <= max_length:
return title
last_punctuation_index = -1
punctuation_chars = {'.', '!', '?', '❤', '☺'}
punctuation_chars.update(emojis.get(title))
for c in punctuation_chars:
last_punctuation_index = max(title.rfind(c, 0, max_length), last_punctuation_index)
if last_punctuation_index != -1:
return title[:last_punctuation_index+1]
# Find the last space character before max length
last_space_index = title.rfind(" ",0, max_length)
# truncate at last_space_index if valid, else max_length
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
emojis
requests
lxml
stashapp-tools

0 comments on commit bacd146

Please sign in to comment.