-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathfilmInfoFormat.php
executable file
·153 lines (127 loc) · 4.77 KB
/
filmInfoFormat.php
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/php
<?
include_once('Debug/debug.php');
include_once('Settings/settings.php');
include_once('template/template_class_2.1.php');
class filmInfo_settings extends settings{
protected $__SETS = array(
'Items' => array( #То, что необходимо заполнить
'Year' => 'год (?:выпуска|выхода)',
'Country' => '(?:страна|производство)',
'Studio' => 'Студия',
'Type' => 'жанр',
'Duration' => 'Продолжительность',
'Translation' => 'Перевод',
'Regisser' => 'Режиссер',
'Scenarist' => 'Сценарий',
'Producer' => 'Продюсер',
'Operator' => 'Оператор',
'Kompositor' => 'Композитор',
'InRoles' => 'В(?: главных)? ролях',
'Description' => '(?:Описание|О фильме)',
'Premies' => 'Премии и награды',
'Quality' => 'Качество',
'OtherNames' => 'Другие названия фильма',
'Notes' => 'Примечание'
),
'TEMPLATE' => '/mnt/maxtor/films_from_net/template.info.htm'
);
}#c filmInfo_settings
class filmInfoItems extends settings{
protected $__SETS = array(
'Name' => '',
'Year' => '',
'Country' => '',
'Type' => '',
'Duration' => '',
'Translation' => '',
'Regisser' => '',
'Scenarist' => '',
'InRoles' => '',
'Description' => '',
'Premies' => '',
'Quality' => '',
'AUDIO' => '',
'VIDEO' => ''
);
}
#$argv[1] - Имя файла-описания
#$argv[2] - Имя файла-видео, чтобы взять параметры с него
class filmInfo extends get_settings{
const TagsRegs = '(?:\s*<[^<>]+>\s*)*';
//protected $_sets = null;
private /* filmInfoItems */ $filmInfo = null;
protected $argv;
function __construct($argv, $sets = null){
$this->argv = $argv;
$this->filmInfo = new filmInfoItems;
if (is_array($sets)) $this->_sets = new filmInfo_settings((array)$sets);
elseif($sets) $this->_sets = $sets;
else $this->_sets = new filmInfo_settings();#Дефолт
#Приведем все к Юникоду!
setlocale(LC_ALL, 'ru_RU.UTF-8');
exec('enconv '.escapeshellarg($this->argv[1]).' -x UTF-8 2>&1');
$this->getFileContent($this->argv[1]);
$this->parseAll();
}#c
function getFileContent ($filename){
$this->filmInfo->setSetting('rawString', file_get_contents($filename));
}#m getFileContent
function parseAll(){
$this->filmInfo->setSetting('Name', $this->parseFilmName());
foreach ($this->settings->Items as $ItemName => $ItemReg){
$this->filmInfo->setSetting($ItemName, $this->parseItem($ItemName, $ItemReg));
}
$this->filmInfo->setSetting('AUDIO', $this->getParseParams('AUDIO'));
$this->filmInfo->setSetting('VIDEO', $this->getParseParams('VIDEO'));
}#m parseAll
function parseFilmName(){
$Name = $this->parseItem('Name', 'название').NON_EMPTY_STR($this->parseItem('Name', 'Оригинальное название'), ' / ');
if (!$Name){
preg_match('#<div class="post_body">'.self::TagsRegs.'(.+?)</#uims', $this->filmInfo->rawString, $Name);
$this->debugInfo('Name', '#<div class="post_body">'.self::TagsRegs.'(.+?)</#uims', $Name);
return @$Name[1];
}
else return $Name;
}#m parseFilmName()
function parseItem($name, $reg){
preg_match('#'.$reg.self::TagsRegs.':'.self::TagsRegs.'(.+?)<#uims', $this->filmInfo->rawString, $Item);
// $this->debugInfo($name, $reg, $Item);
$this->debugInfo($name, '#'.$reg.self::TagsRegs.':'.self::TagsRegs.'(.+?)(?>\s*)<#uims', $Item);
return trim(@$Item[1]);
}#m parseItem
function getParseParams($name){
$str = exec('/home/pasha/bin/aviInfo.'.strtolower($name).' '.escapeshellarg($this->argv[2]).' 2>&1');
preg_match('#'.strtoupper($name).':\s+'.'(.+)$#uims', $str, $Item);
$this->debugInfo($name, '#'.strtoupper($name).':\s+'.'(.+)$#uims', $Item);
return str_replace(' ', ' ', @$Item[1]);
}#m getParseParams
function writeFile($filename, $format = null){
$tmpl = new template($this->settings->TEMPLATE);
$tmpl->assign('Name', $this->filmInfo->Name);
$tmpl->assign('AUDIO', $this->filmInfo->AUDIO);
$tmpl->assign('VIDEO', $this->filmInfo->VIDEO);
foreach ($this->settings->Items as $ItemName => $ItemReg){
$tmpl->assign($ItemName, $this->filmInfo->$ItemName);
}
$tmpl->parse(false);
file_put_contents($filename, $tmpl->content_file);
}
##################
protected function debugInfo($name, $reg, &$res){
if(!@$res[1]){
echo $name . ' не найден'."\n";
dump::a($reg);
dump::a($res);
}
}
}#c filmInfo
if (@$argv[1] and @$argv[2]){
$film = new filmInfo($argv);
# rename($argv[1], $argv[1].'.bak');
# $argv[1] = $argv[1].'.bak';
$film->writeFile('info.htm');
}
// else $cont = file_get_contents('php://stdin');
else exit ('Необходимо указать файл для обработки и файл-видео!'."\n");
?>