stash
This commit is contained in:
83
stash/config/scrapers/community/FileMetadata/FileMetadata.py
Normal file
83
stash/config/scrapers/community/FileMetadata/FileMetadata.py
Normal file
@@ -0,0 +1,83 @@
|
||||
import json
|
||||
import sys
|
||||
import subprocess as sp
|
||||
from datetime import datetime
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from py_common import graphql
|
||||
from py_common import log
|
||||
|
||||
|
||||
def parse_url(comment):
|
||||
if urlparse(comment).scheme:
|
||||
return comment
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def get_path(scene_id):
|
||||
scene = graphql.getScene(scene_id)
|
||||
if not scene:
|
||||
log.error(f"Scene with ID '{scene_id}' not found")
|
||||
return
|
||||
|
||||
if not scene["files"]:
|
||||
log.error(f"Scene with ID '{scene_id}' has no files")
|
||||
return
|
||||
|
||||
return scene["files"][0]["path"]
|
||||
|
||||
|
||||
def scrape_file(path):
|
||||
video_data = sp.check_output(
|
||||
[
|
||||
"ffprobe",
|
||||
"-loglevel",
|
||||
"error",
|
||||
"-show_entries",
|
||||
"format_tags",
|
||||
"-of",
|
||||
"json",
|
||||
f"{path}",
|
||||
],
|
||||
text=True,
|
||||
)
|
||||
if not video_data:
|
||||
log.error("Could not scrape video: ffprobe returned null")
|
||||
return
|
||||
|
||||
metadata = json.loads(video_data)["format"]["tags"]
|
||||
metadata_insensitive = {key.lower(): metadata[key] for key in metadata}
|
||||
|
||||
scene = {}
|
||||
if title := metadata_insensitive.get("title"):
|
||||
scene["title"] = title
|
||||
|
||||
if (comment := metadata_insensitive.get("comment")) and (url := parse_url(comment)):
|
||||
scene["url"] = url
|
||||
|
||||
if description := metadata_insensitive.get("description"):
|
||||
scene["details"] = description
|
||||
|
||||
if date := metadata_insensitive.get("date"):
|
||||
scene["date"] = datetime.strptime(date, "%Y%m%d").strftime("%Y-%m-%d")
|
||||
|
||||
if date := metadata_insensitive.get("creation_time"):
|
||||
scene["date"] = date[:10]
|
||||
|
||||
if artist := metadata_insensitive.get("artist"):
|
||||
scene["performers"] = [{"name": artist}]
|
||||
scene["studio"] = {"name": artist}
|
||||
|
||||
return scene
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
fragment = json.loads(sys.stdin.read())
|
||||
path = get_path(fragment["id"])
|
||||
if not path:
|
||||
print("null")
|
||||
sys.exit(1)
|
||||
|
||||
scraped = scrape_file(path)
|
||||
print(json.dumps(scraped))
|
||||
@@ -0,0 +1,9 @@
|
||||
name: File Metadata (ffprobe)
|
||||
# requires: py_common
|
||||
|
||||
sceneByFragment:
|
||||
action: script
|
||||
script:
|
||||
- python
|
||||
- FileMetadata.py
|
||||
# Last Updated April 07, 2024
|
||||
10
stash/config/scrapers/community/FileMetadata/manifest
Executable file
10
stash/config/scrapers/community/FileMetadata/manifest
Executable file
@@ -0,0 +1,10 @@
|
||||
id: FileMetadata
|
||||
name: File Metadata (ffprobe)
|
||||
metadata: {}
|
||||
version: 25612f8
|
||||
date: "2024-04-07 16:03:04"
|
||||
requires: []
|
||||
source_repository: https://stashapp.github.io/CommunityScrapers/stable/index.yml
|
||||
files:
|
||||
- FileMetadata.yml
|
||||
- FileMetadata.py
|
||||
Reference in New Issue
Block a user