File: dvdtguess

package info (click to toggle)
dvdwizard 0.7.1-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 872 kB
  • ctags: 220
  • sloc: sh: 4,699; makefile: 343
file content (129 lines) | stat: -rwxr-xr-x 4,272 bytes parent folder | download
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
#!/usr/bin/env bash
#
#   dvdtguess
#     - try to guess the title of a DVD by it's MPEG filename
#
#   Copyright (c) 2004-2008 W. Wershofen <itconsult at wershofen.de>
#   Copyright (c) 2010-2011 Markus Kohm <kohm at users.sf.net>
#   Copyright (c) 2009-2012 Joo Martin <joomart2009 at users.sf.net>
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This package is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Changes:
#
#   2004-01-26  Wolfgang Wershofen
#               * initial version
#   2010-06-21  Markus Kohm
#               * renamed dvdwizardrc into dvdwizard_common
#               * usage of gettext features for multilanguage ui
#                 -several `echo' replaced by `printf'
#               * made usage of `tr' portable (POSIX compatible and 
#                 independent of using BSD, GNU or Sytem V `tr').
#               * space added between lowercase immediatly followed by 
#                 an uppercase
#
# Notes:
#   * If you want another heuristic file name to movie title conversion
#     used from dvdwizard, simply add a function named `dvdtguess' to your
#     configurations file `dvdwizard.conf'.  This function should echo
#     the result of the conversion to stdout only.
# -------------------------------------------------------------------------

#
# i18n
#
export TEXTDOMAIN=dvdwizard
export TEXTDOMAINDIR="@LOCALEDIR@"

# We need some sub-routines from dvdwizard_common.
# This file must be found at PATH.
#
. dvdwizard_common || {
    echo $"FATAL ERROR: could not execute common function file \`dvdwizard_common'!
You have to install \`dvdwizard_common' somewhere at PATH." >&2
    exit 1
}

# ------------------------------
# Function specification
#
usagetext=$"
Usage:	${thisscript} filename
	${thisscript} -h|--help
	${thisscript} -v|--version
	
Guessed title string is returned via /dev/stdout.
"

# ------------------------------
# Main Processing
#

#
# Is help wanted?
#
test_versionhelp "$@"

tfile="$@"
tstring=""

#
# Check for needed tools
#
check_tools

#
# Title-Guessing:
#----------------
# This is a terrible hack and the results may be poor. If you don't like it, 
# either supply a title with the -t or -T option or rename your files to give
# better results. Sorry.
#
# Most of the time, we're working on dBox-streams from udrec.
# The name of these files starts with the tv-station (in uppercase) and ends
# with date and time. In addition whitespace and special characters have been
# replaced with underscores.
# First turn underscores into spaces, then ignore everything before the first
# word with lowercase or numerics with more than one digit.
# At the end, remove all words, which are pure numeric with 8 resp. 6 digits.
#
fext=."${tfile##*.}"
fBase=$(basename "$tfile" "$fext")
spacename=`echo "$fBase" | tr -s '_' ' '`
words=`echo "$spacename" | wc -w`
for i in `seq 1 $words`; do
    actword=`echo "$spacename" | cut -d' ' -f$i`
    if [ -z "$tstring" ]; then
	# if we're at the beginning
   	if [ "$(echo $actword | tr -s [A-Z] '[ *]')" != " " ]; then
	    # if the word is not complete upper-case
            if [ "$(echo $actword | tr -s [0-9] '[ *]')" != " " -o ${#actword} -gt 1 ]; then
	        # and not one numeric digit (e.g. PREMIERE 1, SAT 1, PRO 7)
		# then begin writing the title
		tstring=$actword
	    fi
	fi
    elif ! is_integer "$actword" || [ ${#actword} -lt 6 ]; then
	# if they are not numeric or have less the 6 digits
	# append words to title
	tstring="$tstring $actword"
    fi
done

# mjk: I often name movies like `TitleOfTheMovie.mpg', because of this
#      we add a space between each lowercase followed by an uppercase:
tstring=$(echo $tstring | sed -e 's/\([a-z]\)\([A-Z]\)/\1 \2/g')

echo "$tstring"
exit 0