-
Notifications
You must be signed in to change notification settings - Fork 2
/
manual_process
executable file
·135 lines (117 loc) · 5 KB
/
manual_process
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env bash
#USAGE: manual_process list-of-unmoved_files-filename
# The command displays available info on each recording in the list, giving
# you the possibility, after each recording, to enter a correct subtitle.
# Typically, the process involves copy-pasting the Description field to
# your favourite web search engine to determine the correct episode, then,
# assuming you find it, entering 'y', and entering that episode-subtitle
# back into the terminal and pressing <enter> to initiate processing of
# the recording.
#
#DESCRIPTION:
# This script provides an interactive mechanism to reprocess recordings
# that myth2kodi failed to processes automagically.
# Given a file containing a list of unmoved files (full-path), prints the
# recording information to stderr (using: 'myth2kodi --recording-info'),
# then provides the option of inputting an appropriate subtitle, then uses
# that subtitle to call myth2kodi. Any process calls to myth2kodi are
# appended to a file named ./manual_moves.txt.
#
# Author: Stuart A. Knock
# Originally Written: 2016-12-22
#
########################## BEGIN USER SETTINGS ###############################
#Option to launch a browser and search for the Plot.
LAUNCH_BROWSER='Enabled'
#The browser to use if LAUNCH_BROWSER is Enabled. This selected BROWSER mapped
#to an appropriate BROWSER_CMD in the set_browser_cmd() function.
#Options: firefox(DEFAULT)|chrome|chromium
BROWSER='firefox'
######################### END USER SETTINGS ##################################
#TODO: support list generation that works across processing modes...
#generate_unmoved_list_file(){
# local scandir='/media/video/recordings/TVshows'
# local scanext='mpg'
#
# #For MOVE mode with SYMLINKing Enabled, the following monstrosity works...
# ls --color=never -l1 "$scandir"/*."$scanext" | grep -v -e '->' | cut --complement -f1 -d'/' | xargs printf '/%s\n' > list-of-unmoved_files.txt
#}
######################### BEGIN FUNCTION DEFINITIONS ###########################
# #Set the command for searching against a Plot based on user-setting BROWSER.
# set_browser_cmd(){
# case "$BROWSER" in
# firefox)
# BROWSER_CMD='firefox -search '
# ;;
# chrome)
# BROWSER_CMD='google-chrome https://google.com/search?q='
# ;;
# chromium)
# BROWSER_CMD='chromium https://google.com/search?q='
# ;;
# *)
# printf '%s\n' "${BASH_SOURCE[0]}:${FUNCNAME[0]}() unrecognised BROWSER=$BROWSER."
# return 1
# ;;
# esac
# return 0
# }
#Process a file containing a list of unmoved files, displays recording info
#and provides an opportunity to manually enter the correct subtitle for
#subsequent processing
process_list(){
local rec=''
local yesorno='n'
local subtitle=''
local season=''
local episode=''
local unmoved_list_file="$1"
while read -r rec ; do
#Reset variables
subtitle=''
season=''
episode=''
#Display info for the current recording
myth2kodi --recording-info "$rec" 1>&2
printf '%s\n\n' "ls: $(ls -lh "$rec")" 1>&2
#TODO: need access to Plot here... Either add --manual-process to myth2kodi, or have --recording-info export key fields, say as M2K_<fieldname>, here we'd be interested in M2K_Plot
#if [[ "$LAUNCH_BROWSER" = 'Enabled' && -n "$Plot" ]]; then
# set_browser_cmd ; [[ "$?" != 0 ]] && return 1
# ${BROWSER_CMD}"$Plot" 1>&2 &
#fi
#Allow user to input subtitle
yesorno='n'
read -r -n1 -p ' Do you want to input a subtitle? y|(n):>' yesorno </dev/tty
printf '\n'
if [[ "$yesorno" = 'y' ]]; then
read -r -p ' Enter subtitle:' subtitle </dev/tty
printf '\n'
#TODO: remember to delete the following and add a printf '\n' when enabling season&episode...
# myth2kodi "$rec" '' "$subtitle"
# [[ "$?" = '0' ]] && printf '%s\n' "myth2kodi '$rec' '' \"$subtitle\"" >> ./manual_moves.txt
fi
#Allow user to input season and episode numbers
yesorno='n'
read -r -n1 -p ' What about season and episode numbers? y|(n):>' yesorno </dev/tty
printf '\n'
if [[ "$yesorno" = 'y' ]]; then
read -r -p ' Enter season number:' season </dev/tty
read -r -p ' Enter episode number:' episode </dev/tty
printf '\n'
fi
#If we were provided with subtitle or season & episode numbers, then run myth2kodi
if [[ -n "$subtitle" || ( -n "$season" && -n "$episode" ) ]]; then
#TODO: do checks of season and episode...
myth2kodi "$rec" '' "$subtitle" "$season" "$episode"
[[ "$?" = '0' ]] && printf '%s\n' "myth2kodi '$rec' '' \"$subtitle\" '$season' '$episode'" >> ./manual_moves.txt
fi
done < "$unmoved_list_file"
}
########################### END FUNCTION DEFINITIONS ###########################
######################### BEGIN MAIN PROGRAM ###################################
#Basic checks on how we were called.
(( $# == 1 )) || { printf '%s\n' "${BASH_SOURCE[0]} takes one argument."; exit 1; }
[[ -f "$1" ]] || { printf '%s\n' "${BASH_SOURCE[0]} argument must be a file name."; exit 1; }
#Do the stuff...
process_list "$1"
exit "$?"