Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions plugins/audio-transcodes/audio-transcodes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import stashapi.log as log
from stashapi.stashapp import StashInterface
import sys
import json
from pathlib import Path
import os

settings = {"hash_type": "oshash", "transcodes_dir": "/generated/transcodes/"}


def run_ffmpeg(file, hash):
dest = Path(settings["transcodes_dir"]) / "transcodes" / str(hash + ".mp4")
if not dest.exists():
log.debug(
"running ffmpeg on %s to generate %s"
% (
file,
dest,
)
)
command = (
"ffmpeg -f lavfi -i color=c=blue:s=1280x720 -i %s -shortest -fflags +shortest %s"
% (file, dest)
)
log.debug("about to run command: %s " % (command,))
os.system(command)
else:
log.debug(
"transcode already exists %s - %s"
% (
dest,
file,
)
)


def processScene(s):
for f in s["files"]:
if f["width"] == 0:
log.debug("needs to transcode")
for h in f["fingerprints"]:
if h["type"] == settings["hash_type"]:
file = f["path"]
hash = h["value"]
run_ffmpeg(file, hash)


def processAll():
scenes = stash.find_scenes(
f={"resolution": {"modifier": "LESS_THAN", "value": "VERY_LOW"}}
)
for s in scenes:
processScene(s)


json_input = json.loads(sys.stdin.read())

FRAGMENT_SERVER = json_input["server_connection"]
stash = StashInterface(FRAGMENT_SERVER)
config = stash.get_configuration()

log.debug(config)
settings["transcodes_dir"] = config["general"]["generatedPath"]
settings["hash_type"] = config["general"]["videoFileNamingAlgorithm"].lower()
log.debug(settings)

if "mode" in json_input["args"]:
PLUGIN_ARGS = json_input["args"]["mode"]
log.debug(json_input)
if "processScenes" == PLUGIN_ARGS:
processAll()

elif "hookContext" in json_input["args"]:
_id = json_input["args"]["hookContext"]["id"]
_type = json_input["args"]["hookContext"]["type"]
if _type == "Scene.Create.Post":
scene = stash.find_scene(_id)
processScene(scene)
18 changes: 18 additions & 0 deletions plugins/audio-transcodes/audio-transcodes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: audio-transcodes
description: Generate a transcode video from an audio file
version: 0.1
url: https://github.com/stashapp/CommunityScripts/
exec:
- python
- "{pluginDir}/audio-transcodes.py"
interface: raw
hooks:
- name: process audio
description: transcode audio files on scan
triggeredBy:
- Scene.Create.Post
tasks:
- name: "Process All"
description: transcode audio to video on all audio files
defaultArgs:
mode: processScenes