فهرست منبع

Interim file handlers

Zach Isbach 2 سال پیش
والد
کامیت
cc589e0fcb
7فایلهای تغییر یافته به همراه173 افزوده شده و 0 حذف شده
  1. 27 0
      loki/d20.sh
  2. 16 0
      loki/lokiPause.sh
  3. 57 0
      loki/lokiRecode.sh
  4. 13 0
      loki/lokiSubs.sh
  5. 13 0
      loki/lokiTVRename.sh
  6. 17 0
      loki/mergeSubs.py
  7. 30 0
      loki/mergeSubs.sh

+ 27 - 0
loki/d20.sh

@@ -0,0 +1,27 @@
+#!/bin/bash
+set -e
+
+DST="${1}"
+SRC="${2}"
+SUBS="${3}"
+OFFSET="${4}"
+
+# Sanity
+if [ ! -r "${SRC}" ] || [ ! -r "${SUBS}" ]; then
+	echo "Invalid source or subtitles: ${SRC} | ${SUBS}" 1>&2
+	exit 1
+fi
+if [ -e "${DST}" ]; then
+	echo "Invalid destination: ${DST}" 1>&2
+	exit 1
+fi
+if [ -z "${OFFSET}" ]; then
+	OFFSET=0
+fi
+
+SUBS_SRT="`mktemp -t 'd20subs'`"
+dos2unix.pl "${SUBS}" | vtt_srt.pl | srt_shift.pl "${OFFSET}" - > "${SUBS_SRT}"
+
+mkvmerge -o "${DST}" "${SRC}" "${SUBS_SRT}"
+rm -f "${SUBS_SRT}"
+mkvpropedit "${DST}" --edit track:s1 --set language=eng --edit track:a1 --set language=eng

+ 16 - 0
loki/lokiPause.sh

@@ -0,0 +1,16 @@
+#!/bin/bash
+
+# Duration
+H="${1}"
+if [ -z "${H}" ]; then
+  H=$(( 23 - `date +%H` ))
+fi
+
+# Stop
+PID=$(ps Ax | grep -v grep | grep HandBrake | awk '{print $1}' | head -n 1)
+kill -SIGSTOP $PID
+
+# Restart
+(sleep $(( 3600 * $H )) && \
+  kill -SIGCONT $PID ) \
+  & disown

+ 57 - 0
loki/lokiRecode.sh

@@ -0,0 +1,57 @@
+#!/bin/bash
+
+MPATH="/Volumes/Shared/TV"
+if [ -n "${1}" ]; then
+	if [ -d "${1}" ]; then
+		MPATH="${1}"
+	fi
+fi
+echo "Using MPATH: ${MPATH}"
+
+RUNCHECK="`ps auwx | grep xargs | grep video/findRecode0`"
+if [ -z "${RUNCHECK}" ]; then
+	export NO_LAST_RECODE_FILE=1
+	find "${MPATH}" -type d -print0 | \
+		xargs -0 -I RPLSTR -n 1 ~/bin/video/findRecode0 RPLSTR | \
+		xargs -0 -n 1 -t ~/bin/video/recode &
+	RUNCHECK=$!
+	echo "Started recoder as PID: ${RUNCHECK}"
+else
+	echo 'findRecode already running:'
+	echo "${RUNCHECK}"
+fi
+
+# Background this too so we can get HB fully detached
+(while [ 1 ]; do
+	# Slowly
+	for i in {1..2}; do
+		echo
+		sleep 5
+	done
+
+	# Grab a status
+	HB="`ps auwx | grep -v grep | grep -i handbrake`"
+	if [ -z "${HB}" ]; then
+		HB="`ps awux | grep -v grep | grep -i video/findRecode`"
+	fi
+	if [ -z "${HB}" ]; then
+		HB="`ps awux | grep -v grep | grep "${RUNCHECK}"`"
+	fi
+
+	# Stop when we find nothing to monitor
+	if [ -z "${HB}" ]; then
+		echo
+		echo Done
+		date
+		echo
+		echo
+		exit 0
+	fi
+
+	# Display status
+	echo "${HB}"
+	echo
+done) &
+
+echo "Started monitor as PID: ${!}"
+exit 0

+ 13 - 0
loki/lokiSubs.sh

@@ -0,0 +1,13 @@
+#!/bin/sh
+if [ -z "${EXT}" ]; then
+  EXT="mkv"
+fi
+OUT_DIR=""
+if [ -n "${1}" ]; then
+  OUT_DIR="${1}/"
+fi
+
+for i in *".${EXT}"; do
+  j="`echo "${i}" | sed 's%\.'"${EXT}"'$%%'`"
+  mkvmerge -o "${OUT_DIR}${j}.mkv" "${i}" "Subs/${j}/"*'_English.srt'
+done

+ 13 - 0
loki/lokiTVRename.sh

@@ -0,0 +1,13 @@
+#!/bin/sh
+
+BASE_DIR="${HOME}/bin/media/TVDB"
+TV_DIR="/Volumes/Shared/TV"
+
+source "${BASE_DIR}/venv/bin/activate"
+if [ "${1}" == "ALL" ]; then
+  for i in "${TV_DIR}/"*; do
+    python3 "${BASE_DIR}/main.py" "${i}"
+  done
+else
+  python3 "${BASE_DIR}/main.py" "${@}"
+fi

+ 17 - 0
loki/mergeSubs.py

@@ -0,0 +1,17 @@
+#!/usr/bin/python3
+
+# Imports
+import re
+import os
+import pathlib
+import argparse
+
+# CLI config
+parser = argparse.ArgumentParser('MergeSubs')
+parser.add_argument('path', type=pathlib.Path, help='Path to the base media file')
+parser.add_argument('--verbose', '-v', action=count, default=0, help='Increasing verbosity')
+cli = parser.parse_args()
+if not os.path.isdir(cli.path):
+  print('Invalid path: {path}'.format(path=cli.path))
+  exit(1)
+

+ 30 - 0
loki/mergeSubs.sh

@@ -0,0 +1,30 @@
+#!/bin/sh
+
+BASE_FILE="${1}"
+if [ -z "${BASE_FILE}" -o ! -e "${BASE_FILE}" ]; then
+  echo "Invalid base file: ${BASE_FILE}" 1>&2
+  exit 1
+fi
+
+BASE="`basename "${BASE_FILE}"`"
+DIR="`dirname "${BASE_FILE}"`"
+SE="`echo "${BASE}" | sed 's%^.*\(S[0-9][0-9]E[0-9][0-9]*\).*$%\1%'`"
+if [ -z "${SE}" ]; then
+  echo "No SeasonEpisode block in base file: ${BASE}" 1>&2
+  exit 1
+fi
+
+MUX_SUBS=""
+IFS=$'\n'
+for i in \
+  `find "${DIR}" -type f -path "*${SE}*" -a \
+    \( -name '*.srt' -o -name '*.vtt' -o -name '*.idx' \)`;
+do
+  case "${i}" in
+    *.vtt)
+      ;;
+    *)
+      ;;
+  esac
+  echo $i
+done