Skip to content

Commit 4e8ec92

Browse files
authored
Merge pull request #838 from budingkak12/feature/video-tag-i18n-improvements
视频标签搜索与随机排序功能增强
2 parents fc9acbc + d928aa4 commit 4e8ec92

File tree

67 files changed

+151
-73
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+151
-73
lines changed

javascript/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ Promise.resolve().then(async () => {
1313
<link rel="icon" href="/favicon.ico" />
1414
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
1515
<title>Infinite Image Browsing</title>
16-
<script type="module" crossorigin src="/infinite_image_browsing/fe-static/assets/index-56203bfb.js"></script>
17-
<link rel="stylesheet" href="/infinite_image_browsing/fe-static/assets/index-d06b4bd6.css">
16+
<script type="module" crossorigin src="/infinite_image_browsing/fe-static/assets/index-9ea28d47.js"></script>
17+
<link rel="stylesheet" href="/infinite_image_browsing/fe-static/assets/index-727d406a.css">
1818
</head>
1919
2020
<body>

scripts/iib/api.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -710,13 +710,21 @@ async def api_set_send_img_path():
710710

711711
@app.get(api_base + "/image_geninfo", dependencies=[Depends(verify_secret)])
712712
async def image_geninfo(path: str):
713-
return parse_image_info(path).raw_info
713+
# 使用 get_exif_data 函数,它已经支持视频文件
714+
from scripts.iib.db.update_image_data import get_exif_data
715+
try:
716+
result = get_exif_data(path)
717+
return result.raw_info or ""
718+
except Exception as e:
719+
logger.error(f"Failed to get geninfo for {path}: {e}")
720+
return ""
714721

715722
class GeninfoBatchReq(BaseModel):
716723
paths: List[str]
717724

718725
@app.post(api_base + "/image_geninfo_batch", dependencies=[Depends(verify_secret)])
719726
async def image_geninfo_batch(req: GeninfoBatchReq):
727+
from scripts.iib.db.update_image_data import get_exif_data
720728
res = {}
721729
conn = DataBase.get_conn()
722730
for path in req.paths:
@@ -725,9 +733,11 @@ async def image_geninfo_batch(req: GeninfoBatchReq):
725733
if img:
726734
res[path] = img.exif
727735
else:
728-
res[path] = parse_image_info(path).raw_info
736+
result = get_exif_data(path)
737+
res[path] = result.raw_info or ""
729738
except Exception as e:
730-
logger.error(e, stack_info=True)
739+
logger.error(f"Failed to get geninfo for {path}: {e}", stack_info=True)
740+
res[path] = ""
731741
return res
732742

733743

@@ -919,6 +929,7 @@ class MatchImagesByTagsReq(BaseModel):
919929
cursor: str
920930
folder_paths: List[str] = None
921931
size: Optional[int] = 200
932+
random_sort: Optional[bool] = False
922933

923934
@app.post(db_api_base + "/match_images_by_tags", dependencies=[Depends(verify_secret)])
924935
async def match_image_by_tags(req: MatchImagesByTagsReq):
@@ -933,7 +944,8 @@ async def match_image_by_tags(req: MatchImagesByTagsReq):
933944
tag_dict={"and": req.and_tags, "or": req.or_tags, "not": req.not_tags},
934945
cursor=req.cursor,
935946
folder_paths=folder_paths,
936-
limit=req.size
947+
limit=req.size,
948+
random_sort=req.random_sort
937949
)
938950
return {
939951
"files": filter_allowed_files([x.to_file_info() for x in imgs]),

scripts/iib/db/datamodel.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ def get_images_by_tags(
533533
limit: int = 500,
534534
cursor="",
535535
folder_paths: List[str] = None,
536+
random_sort: bool = False,
536537
) -> tuple[List[Image], Cursor]:
537538
query = """
538539
SELECT image.id, image.path, image.size,image.date
@@ -583,7 +584,7 @@ def get_images_by_tags(
583584
print(folder_path)
584585
where_clauses.append("(" + " OR ".join(folder_clauses) + ")")
585586

586-
if cursor:
587+
if cursor and not random_sort:
587588
where_clauses.append("(image.date < ?)")
588589
params.append(cursor)
589590
if where_clauses:
@@ -593,7 +594,17 @@ def get_images_by_tags(
593594
query += " HAVING COUNT(DISTINCT tag_id) = ?"
594595
params.append(len(tag_dict["and"]))
595596

596-
query += " ORDER BY date DESC LIMIT ?"
597+
if random_sort:
598+
query += " ORDER BY RANDOM() LIMIT ?"
599+
# For random sort, use offset-based pagination
600+
if cursor:
601+
try:
602+
offset = int(cursor)
603+
query = query.replace("LIMIT ?", f"LIMIT ? OFFSET {offset}")
604+
except (ValueError, TypeError):
605+
pass # Invalid cursor, start from beginning
606+
else:
607+
query += " ORDER BY date DESC LIMIT ?"
597608
params.append(limit)
598609
api_cur = Cursor()
599610
with closing(conn.cursor()) as cur:
@@ -610,7 +621,13 @@ def get_images_by_tags(
610621
Image.safe_batch_remove(conn, deleted_ids)
611622
api_cur.has_next = len(rows) >= limit
612623
if images:
613-
api_cur.next = str(images[-1].date)
624+
if random_sort:
625+
# For random sort, use offset-based cursor
626+
current_offset = int(cursor) if cursor else 0
627+
api_cur.next = str(current_offset + len(images))
628+
else:
629+
# For date sort, use date-based cursor
630+
api_cur.next = str(images[-1].date)
614631
return images, api_cur
615632

616633
@classmethod

scripts/iib/db/update_image_data.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
is_dev,
1010
get_modified_date,
1111
is_image_file,
12-
case_insensitive_get
12+
case_insensitive_get,
13+
get_img_geninfo_txt_path,
14+
parse_generation_parameters
1315
)
1416
from scripts.iib.parsers.model import ImageGenerationInfo, ImageGenerationParams
1517
from scripts.iib.logger import logger
@@ -19,6 +21,26 @@
1921
# 定义一个函数来获取图片文件的EXIF数据
2022
def get_exif_data(file_path):
2123
if get_video_type(file_path):
24+
# 对于视频文件,尝试读取对应的txt标签文件
25+
txt_path = get_img_geninfo_txt_path(file_path)
26+
if txt_path:
27+
try:
28+
with open(txt_path, 'r', encoding='utf-8') as f:
29+
content = f.read().strip()
30+
if content:
31+
# 复用现有解析逻辑,添加视频标识
32+
params = parse_generation_parameters(content + "\nSource Identifier: Video Tags")
33+
return ImageGenerationInfo(
34+
content,
35+
ImageGenerationParams(
36+
meta=params["meta"],
37+
pos_prompt=params["pos_prompt"],
38+
extra=params,
39+
),
40+
)
41+
except Exception as e:
42+
if is_dev:
43+
logger.error("Failed to read video txt file %s: %s", txt_path, e)
2244
return ImageGenerationInfo()
2345
try:
2446
return parse_image_info(file_path)

vue/dist/assets/Checkbox-a2afe2f0.js renamed to vue/dist/assets/Checkbox-716ad574.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)