Skip to content

Commit 1322291

Browse files
TweeticoatsTweeticoats
andauthored
Adding a new plugin audio-transcodes. (#438)
Co-authored-by: Tweeticoats <[email protected]>
1 parent 198dc58 commit 1322291

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import stashapi.log as log
2+
from stashapi.stashapp import StashInterface
3+
import sys
4+
import json
5+
from pathlib import Path
6+
import os
7+
8+
settings = {"hash_type": "oshash", "transcodes_dir": "/generated/transcodes/"}
9+
10+
11+
def run_ffmpeg(file, hash):
12+
dest = Path(settings["transcodes_dir"]) / "transcodes" / str(hash + ".mp4")
13+
if not dest.exists():
14+
log.debug(
15+
"running ffmpeg on %s to generate %s"
16+
% (
17+
file,
18+
dest,
19+
)
20+
)
21+
command = (
22+
"ffmpeg -f lavfi -i color=c=blue:s=1280x720 -i %s -shortest -fflags +shortest %s"
23+
% (file, dest)
24+
)
25+
log.debug("about to run command: %s " % (command,))
26+
os.system(command)
27+
else:
28+
log.debug(
29+
"transcode already exists %s - %s"
30+
% (
31+
dest,
32+
file,
33+
)
34+
)
35+
36+
37+
def processScene(s):
38+
for f in s["files"]:
39+
if f["width"] == 0:
40+
log.debug("needs to transcode")
41+
for h in f["fingerprints"]:
42+
if h["type"] == settings["hash_type"]:
43+
file = f["path"]
44+
hash = h["value"]
45+
run_ffmpeg(file, hash)
46+
47+
48+
def processAll():
49+
scenes = stash.find_scenes(
50+
f={"resolution": {"modifier": "LESS_THAN", "value": "VERY_LOW"}}
51+
)
52+
for s in scenes:
53+
processScene(s)
54+
55+
56+
json_input = json.loads(sys.stdin.read())
57+
58+
FRAGMENT_SERVER = json_input["server_connection"]
59+
stash = StashInterface(FRAGMENT_SERVER)
60+
config = stash.get_configuration()
61+
62+
log.debug(config)
63+
settings["transcodes_dir"] = config["general"]["generatedPath"]
64+
settings["hash_type"] = config["general"]["videoFileNamingAlgorithm"].lower()
65+
log.debug(settings)
66+
67+
if "mode" in json_input["args"]:
68+
PLUGIN_ARGS = json_input["args"]["mode"]
69+
log.debug(json_input)
70+
if "processScenes" == PLUGIN_ARGS:
71+
processAll()
72+
73+
elif "hookContext" in json_input["args"]:
74+
_id = json_input["args"]["hookContext"]["id"]
75+
_type = json_input["args"]["hookContext"]["type"]
76+
if _type == "Scene.Create.Post":
77+
scene = stash.find_scene(_id)
78+
processScene(scene)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: audio-transcodes
2+
description: Generate a transcode video from an audio file
3+
version: 0.1
4+
url: https://github.com/stashapp/CommunityScripts/
5+
exec:
6+
- python
7+
- "{pluginDir}/audio-transcodes.py"
8+
interface: raw
9+
hooks:
10+
- name: process audio
11+
description: transcode audio files on scan
12+
triggeredBy:
13+
- Scene.Create.Post
14+
tasks:
15+
- name: "Process All"
16+
description: transcode audio to video on all audio files
17+
defaultArgs:
18+
mode: processScenes

0 commit comments

Comments
 (0)