· 7 years ago · Oct 12, 2018, 11:12 PM
1<head>
2 <meta charset="utf-8">
3 <meta http-equiv="X-UA-Compatible" content="IE=edge">
4 <meta name="csrf-token" content="{{ csrf_token() }}">
5 <link rel="icon" href="/img/favicon.ico" type="image/x-icon"/>
6 <meta property="og:url" content="<?php echo url()->current(); ?>" />
7 <script src="/js/app.js" defer></script>
8 <script src="/js/jquery.js"></script>
9 <link href="/css/app.css" rel="stylesheet"><link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
10 <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
11 <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
12 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
13</head>
14<?php
15
16$siteHome = $_ENV['APP_URL'];
17$apiKey = $_ENV['TVDB_APIKEY'];
18
19$tvdbid = Request::get('id');
20$type = Request::get('type');
21$language = Request::get('lang');
22$abledd = Request::get('abled');
23$urlabled = Request::get('abled');
24$trailer = Request::get('trailer');
25$type = Request::get('type');
26$editedby = Auth::user()->name;
27$location = Request::get('location');
28$hardsub = Request::get('hardsub');
29$page = Request::get('page');
30$exec = true;
31$infoLang = Request::get('infolang');
32
33$type1 = ["download","anime", "tv"];
34$type2 = ["Download","Anime", "TV.Shows"];
35$foldertype = str_replace($type1, $type2, $type);
36
37$Language1 = ["en", "jp", "nl", "kr"];
38$Language2 = ["English", "Japanese", "Dutch", "Korean"];
39$Lang = str_replace($Language1, $Language2, $lang);
40
41$root_dir = "/mnt/web420/e1/94/59497294/htdocs/";
42$cache_dir = "$root_dir/lib/cache";
43$media_dir = "/mnt/web420/e1/94/59497294/htdocs/public/lib/media/shows/$tvdbid";
44$url_dir = "$siteHome/lib/media/shows/$tvdbid";
45
46// Check if the directory already exists.
47if (!is_dir($media_dir)) {
48// Directory does not exist, so lets create it.
49 mkdir($media_dir, 0777, true);
50}
51// transcode settings
52require ("/mnt/web420/e1/94/59497294/htdocs/NoMercy/resources/views/variables/codec.blade.php");
53// Load language based string replaces
54require ("/mnt/web420/e1/94/59497294/htdocs/NoMercy/resources/views/variables/locals.blade.php");
55// Load global variables
56require ("/mnt/web420/e1/94/59497294/htdocs/NoMercy/resources/views/variables/globals.blade.php");
57
58// Grab login token for thetvdb.com and grab all json's needed for data retreval
59$token = exec("curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{
60\"apikey\": \"$apiKey\"
61}' 'https://api.thetvdb.com/login'");
62
63$token = json_decode($token, true);
64$header1 = "Accept: application/json";
65$header2 = "Authorization: Bearer " . $token['token'];
66$header3 = "Accept-Language $infoLang";
67
68$imgurl = "https://api.thetvdb.com/series/$tvdbid/images";
69
70$refreshToken = exec("curl -X GET --header '$header1' --header '$header2' 'https://api.thetvdb.com/refresh_token'");
71
72$searchShow = exec("curl -X GET --header '$header1' --header '$header2' --header '$header3' 'https://api.thetvdb.com/series/$tvdbid'");
73$searchShow = json_decode($searchShow, true);
74$searchShow = $searchShow['data'];
75
76$episodes = exec("curl -X GET --header '$header1' --header '$header2' --header '$header3' 'https://api.thetvdb.com/series/$tvdbid/episodes?page=$page'");
77$episodes = json_decode($episodes, true);
78$episodes = $episodes['data'];
79
80$params = exec("curl -X GET --header '$header1' --header '$header2' '$imgurl/query/params'");
81$params = json_decode($params, true);
82$params = $params['data'];
83
84$poster = exec("curl -X GET --header '$header1' --header '$header2' '$imgurl/query?keyType=poster'");
85$poster = json_decode($poster, true);
86if(isset($poster['data'])){
87 $poster = $poster['data'];
88 // Show poster/
89 usort($poster, function($a, $b) {
90 return $a['ratingsInfo']['average'] > $b['ratingsInfo']['average'] ? -1 : 1;
91 });
92 $maxposterid = 1;
93 for ($posterid = 0 ; $posterid < $maxposterid; $posterid++) {
94 if ($poster[$posterid]['ratingsInfo']['average'] > 0) {
95 $poster[$posterid] = "https://www.thetvdb.com/banners/" . $poster[$posterid]['fileName'];
96 DB::statement("UPDATE `shows` SET `poster` = '$poster[$posterid]' WHERE `tvdbid`= $tvdbid");
97 $sql = "UPDATE `shows` SET `poster` = '$poster[$posterid]' WHERE `tvdbid`= $tvdbid";
98 echo $sql . ";<br>";
99 if (isset($exec)) {
100 exec("rm $media_dir/$tvdbid.poster.orig.jpg");
101 exec("wget -nc -O $media_dir/$tvdbid.poster.orig.jpg $poster[$posterid]");
102 }
103 }
104 }
105}
106
107$fanart = exec("curl -X GET --header '$header1' --header '$header2' '$imgurl/query?keyType=fanart'");
108$fanart = json_decode($fanart, true);
109if(isset($fanart['data'])){
110 $fanart = $fanart['data'];
111}
112
113// $posterSeason = exec("curl -X GET --header '$header1' --header '$header2' '$imgurl/query?keyType=season'");
114// $posterSeason = json_decode($posterSeason, true);
115// $posterSeason = $posterSeason['data'];
116
117$banner = exec("curl -X GET --header '$header1' --header '$header2' '$imgurl/query?keyType=series'");
118$banner = json_decode($banner, true);
119$banner = $banner['data'];
120
121// Show Info from controller.... the way it should!
122$year = (new DateTime($firstAired))->format('Y');
123$genre = implode(" ",$client->series()->get($seriesId)->getGenre());
124$seriesName = $searchShow['seriesName'];
125$seriesNamee = addslashes($searchShow['seriesName']);
126$overvieww = addslashes($searchShow['overview']);
127
128// Download youtube video
129if (!file_exists("$media_dir/$tvdbid.trailer.NoMercy.mp4")) {
130 // $cmd = "ytdl $trailer > '$media_dir/$tvdbid.trailer.NoMercy.mp4'";
131 $cmd = "youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio' --merge-output-format mp4 -o '$media_dir/$tvdbid.trailer.NoMercy.mp4' $trailer";
132 exec($cmd);
133}
134
135DB::connection()->enableQueryLog();
136
137DB::statement("INSERT INTO `shows`( `tvdbid`, `seriesName`, `firstAired`, `year`, `network`, `runtime`, `overview`, `airsDayOfWeek`, `imdbId`, `genre`,`status`, `lastUpdated`, `airsTime`, `rating`, `siteRating`, `zap2itId`, `added`, `language`, `trailer`, `abled`, `editedby`, `type`) VALUES ('$tvdbid','$seriesNamee','$firstAired','$year','$network','$runtime','$overvieww','$airsDayOfWeek','$imdbId','$genre', '$status','$lastUpdated','$airsTime', '$rating','$siteRating','$zap2itId','$added', '$language', '$trailer', '$abledd', '$editedby','$type' ) ON DUPLICATE KEY UPDATE `seriesName` = '$seriesNamee', `overview` = '$overvieww', `firstAired` = '$firstAired', `year` = '$year', `network` = '$network', `runtime` = '$runtime', `airsDayOfWeek` = '$airsDayOfWeek', `imdbId` = '$imdbId', `genre` = '$genre', `status` = '$status', `lastUpdated` = '$lastUpdated', `airsTime` = '$airsTime', `rating` = '$rating', `siteRating` = '$siteRating', `zap2itId` = '$zap2itId', `added` = '$added', `addedBy` = '$addedBy', `language` = '$language', `abled` = '$abledd', `editedby` = '$editedby', `type` = '$type', `updated_at` = CURRENT_TIMESTAMP");
138
139Request::get('trailer') ? $trailer = "youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio' --merge-output-format mp4 -o '$media_dir/$tvdbid.trailer.NoMercy.mp4' $trailer" : '';
140
141// Make response for index page on completion
142$overview = substr($overview, 0,200) . '...';
143$query_show = "<table class='table table-sm table-hover table-striped'><tbody><tr><td>tvdbid:</td><td>$tvdbid </td></tr><tr><td>SeriesName: </td><td>$seriesName </td></tr><tr><td>Year: </td><td>$year </td></tr><tr><td>Overview: </td><td>$overview </td></tr><tr><td>Runtime: </td><td>$runtime </td></tr><tr><td>type: </td><td>$type </td></tr><tr><td>Abled: </td><td>$abledd </td></tr><tr><td>EditedBy:</td><td>$editedby </td></tr><tr><td>Youtube-DL: </td><td>$trailer</td></tr></tbody></table>";
144$query_show = json_encode($query_show);
145
146// Show Fanart
147usort($fanart, function($a, $b) {
148 return $a['ratingsInfo']['average'] > $b['ratingsInfo']['average'] ? -1 : 1;
149});
150
151$maxFanartid = 1;
152for ($fanartid = 0 ; $fanartid < $maxFanartid; $fanartid++) {
153 if ($fanart[$fanartid]['ratingsInfo']['average'] > 0) {
154 $fanart[$fanartid] = "https://www.thetvdb.com/banners/" . $fanart[$fanartid]['fileName'];
155 DB::statement("UPDATE `shows` SET `fanart` = '$fanart[$fanartid]' WHERE `tvdbid`= $tvdbid");
156 $sql = "UPDATE `shows` SET `fanart` = '$fanart[$fanartid]' WHERE `tvdbid`= $tvdbid";
157 echo $sql . ";<br>";
158 if (isset($exec)) {
159 exec("rm $media_dir/$tvdbid.fanart.orig.jpg");
160 exec("wget -nc -O $media_dir/$tvdbid.fanart.orig.jpg $fanart[$fanartid]");
161 }
162 }
163}
164
165
166// Show Baner
167$banner = "https://www.thetvdb.com/banners/" . $banner[0]['fileName'];
168DB::statement("UPDATE `shows` SET `banner` = '$banner' WHERE `tvdbid`= $tvdbid");
169 $sql = "UPDATE `shows` SET `banner` = '$banner' WHERE `tvdbid`= $tvdbid";
170 echo $sql . ";<br>";
171if (isset($exec)) {
172 exec("rm $media_dir/$tvdbid.banner.orig.jpg");
173 exec("wget -nc -O $media_dir/$tvdbid.banner.orig.jpg $banner");
174}
175
176
177// Make default Subtitle
178$subfile = "$media_dir/$tvdbid.none.vtt";
179
180if (!file_exists($subfile))
181 {if (isset($exec)) {
182 exec("echo 'WEBVTT' >> $subfile");
183 exec("echo '' >> $subfile");
184
185 exec("echo '00:00:01.000 --> 00:00:06.000' >> $subfile");
186 exec("echo 'NoMercy Entertainment Presents.' >> $subfile");
187 exec("echo '' >> $subfile");
188
189 exec("echo '00:00:06.500 --> 00:00:11.000' >> $subfile");
190 exec("echo '$seriesNamee.' >> $subfile");
191 exec("echo '' >> $subfile");
192
193 exec("echo '00:00:12.500 --> 00:00:19.000' >> $subfile");
194 exec("echo 'Encoded and Hosted With Love.\nEnjoy!' >> $subfile");
195 exec("echo '' >> $subfile");
196 }
197
198}
199
200// Resize images
201if (isset($exec)) {
202 exec("ffmpeg -i $media_dir/$tvdbid.fanart.orig.jpg -vf scale=640x360 $media_dir/$tvdbid.thumbnail.jpg -y");
203 exec("ffmpeg -i $media_dir/$tvdbid.fanart.orig.jpg $media_dir/$tvdbid.fanart.jpg -y");
204 exec("ffmpeg -i $media_dir/$tvdbid.banner.orig.jpg $media_dir/$tvdbid.banner.jpg -y");
205 exec("ffmpeg -i $media_dir/$tvdbid.poster.orig.jpg -vf scale=680x1000 $media_dir/$tvdbid.poster.jpg -y");
206 exec("ffmpeg -i $media_dir/$tvdbid.poster.orig.jpg -vf scale=453x666 $media_dir/$tvdbid.poster.medium.jpg -y");
207 exec("ffmpeg -i $media_dir/$tvdbid.poster.orig.jpg -vf scale=340x500 $media_dir/$tvdbid.poster.small.jpg -y");
208 exec("ffmpeg -i $media_dir/$tvdbid.poster.orig.jpg -vf scale=272x400 $media_dir/$tvdbid.poster.tiny.jpg -y");
209
210 //exec ("rm $media_dir/$tvdbid.poster.orig.jpg");
211 // echo "<img src='/lib/media/shows/$tvdbid/$tvdbid.banner.jpg' width='10%'>";
212 // echo "<img src='/lib/media/shows/$tvdbid/$tvdbid.poster.jpg' width='10%'>";
213 // echo "<img src='/lib/media/shows/$tvdbid/$tvdbid.fanart.jpg' width='10%'><br>";
214
215 // exec("chmod -R 777 $root_dir");
216 // exec("chmod -R 777 $cache_dir");
217 // exec("chmod -R 777 $media_dir");
218}
219
220//Episodes Data
221$max = count($episodes);
222for ($id = 0 ; $id < $max; $id++) {
223
224 // Because it's a loop values need to be cleared.
225 // $lang1 = NULL; $lang2 = NULL; $lang3 = NULL; $lang4 = NULL; $lang5 = NULL;
226
227 // $audio = NULL; $audio0 = NULL; $audio1 = NULL; $audio2 = NULL; $audio3 = NULL; $audio4 = NULL; $audio5 = NULL;
228
229 // $echo1 = NULL; $echo2 = NULL; $echo3 = NULL; $echo4 = NULL; $echo5 = NULL; $echo6 = NULL; $echo7 = NULL; $echo8 = NULL;
230
231 $audioFile = NULL; $ffmpeg = NULL; $audiolang = NULL; $indexFile = NULL; $hls = NULL;
232 $video_map = null; $audio_map = null; $subtitle_map = null; $ffmpeg_audio = null; $ffmpeg_video = null;
233 $abled = NULL; $duration = NULL; $fileOut = NULL; $durationOut = NULL; $audioLangShow = null;
234 $video_height = 0;$videoScale = null;
235
236 $tvdbid = $searchShow['id'];
237 $firstAired = $episodes[$id]['firstAired'];
238 $episodeId = $episodes[$id]['id'];
239 $absoluteNumber = $episodes[$id]['absoluteNumber'];
240 $season = $episodes[$id]['airedSeason'];
241 $episode = $episodes[$id]['airedEpisodeNumber'];
242 $Season = sprintf("%02d", $season);
243 $Episode = sprintf("%02d", $episode);
244 $epTitle = $episodes[$id]['episodeName'];
245 $title = $episodes[$id]['episodeName'];
246 $titlee = addslashes($episodes[$id]['episodeName']);
247 $overview = $episodes[$id]['overview'];
248 $thumbnail = "https://www.thetvdb.com/banners/" .$episodes[$id]['filename'];
249
250 $image = "$siteHome/lib/media/shows/" . $tvdbid . "/" . $tvdbid . ".S" . $Season. "E" . $Episode . ".thumbnail.jpg";
251
252 $thumbnaill = $media_dir . "/" . $tvdbid . ".S" . $Season . "E" . $Episode . ".thumbnail.jpg";
253
254 // Get episode thumbnail
255 exec("wget -nc -O $thumbnaill $thumbnail");
256
257 // Sanitize episode names recieved from tvdb
258 $str1 = [" ", "?", "&", "..", "#", "'", ":", ",", "?", "�", ":", ";", "(", ")", "-.", "/"];
259 $str2 = [".", "", "and", ".", "%23", "", "", "", "", "", "", "", "", "", "", "."];
260 $SeriesName = str_replace($str1, $str2, $searchShow['seriesName']);
261
262 $str1 = [" ", "!", "?", "&", "..", "#", "'", ":", ",", "?", "�", ":", ";", "", "(", ")", "/"];
263 $str2 = [".", "", "", "and", ".", "%23", "", "", "", "", "", "", "", "", "", "", "."];
264 $SeriesName2 = str_replace($str1, $str2, $searchShow['seriesName']);
265
266 $title= rtrim($title);
267 $str1 = [".", " ", "!", "?", "/", "&", "..", "...", "....", ".....", "'", ":", ",", "?", "�", ":", ";", "-.", ".(1)", ".(2)", ".(3)", ".(4)", "(", ")", "’", "*", "'"];
268 $str2 = ["", ".", "", "", ".", "and", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "-", "'"];
269 $title= str_replace($str1, $str2, $title);
270
271 $str1 = [" ", "?", "&", "..", "#", "'", ":", ",", "?", "�", ":", ";", "(", ")", "-.", "/"];
272 $str2 = [".", "", "and", ".", "%23", "", "", "", "", "", "", "", "", "", "", "."];
273 $SeriesNameOrig = str_replace($str1, $str2, $searchShow['seriesName']);
274
275
276 // Set subfolder where file is located from form
277 if (isset($location) && $location == "download") {
278 $foldertype2 = "Download";
279 $vcodec = "-c:v libx264";
280 $acodec = "-c:a aac";
281 }
282 if (isset($location) && $location == "anime") {
283 $foldertype2 = "Anime";
284 $vcodec = "-c:v copy";
285 $acodec = "-c:a copy";
286 }
287
288 if (isset($location) && $location == "tv") {
289 $foldertype2 = "TV.Shows";
290 $vcodec = "-c:v copy";
291 $acodec = "-c:a copy";
292 }
293
294 $fileOrig = null;
295
296 $foldertype2 = "Download";
297 // Check if input file exists and set the one that is found.
298 $fileOrigMkv = "/mnt/vault/media/" . $foldertype . "/" . $foldertype2 . "/" . $SeriesName . ".(" . $year . ")/" . $SeriesName2 . ".S" . $Season . "E" . $Episode . "." . $title . ".NoMercy.mkv";
299 if (file_exists($fileOrigMkv)) {
300 $fileOrig = $fileOrigMkv;
301 }
302
303 $fileOrigAvi = "/mnt/vault/media/" . $foldertype . "/" . $foldertype2 . "/" . $SeriesName . ".(" . $year . ")/" . $SeriesName2 . ".S" . $Season . "E" . $Episode . "." . $title . ".NoMercy.avi";
304 if (file_exists($fileOrigAvi)) {
305 $fileOrig = $fileOrigAvi;
306 }
307
308 $fileOrigMp4 = "/mnt/vault/media/" . $foldertype . "/" . $foldertype2 . "/" . $SeriesName . ".(" . $year . ")/" . $SeriesName2 . ".S" . $Season . "E" . $Episode . "." . $title . ".NoMercy.mp4";
309 if (file_exists($fileOrigMp4)) {
310 $fileOrig = $fileOrigMp4;
311 }
312
313 $fileDoneMp4DL = "/mnt/vault/media/" . $foldertype . "/" . $foldertype2 . "/" . $SeriesName . ".(" . $year . ")/" . $SeriesName2 . ".S" . $Season . "E" . $Episode . "." . $title . ".NoMercy/" . $SeriesName2 . ".S" . $Season . "E" . $Episode . "." . $title . ".NoMercy.mp4";
314 if (file_exists($fileDoneMp4DL)) {
315 $fileOrig = $fileDoneMp4DL;
316 }
317
318 $fileOrigMp4Done = "/mnt/vault/media/" . $foldertype . "/" . $foldertype2 . "/" . $SeriesName . ".(" . $year . ")/" . $SeriesName2 . ".S" . $Season . "E" . $Episode . "." . $title . ".NoMercy/video.mp4";
319 if (file_exists($fileOrigMp4Done)) {
320 $fileOrig = $fileOrigMp4Done;
321 }
322
323 // echo $fileOrig . "<br>";
324 $overvieww = addslashes($episodes[$id]['overview']);
325 $seriesNamee = addslashes($searchShow['seriesName']);
326
327 $folderOut = "/mnt/vault/media/" . $foldertype . "/" . $foldertype . "/" . $SeriesName . ".(" . $year . ")/" . $SeriesName2 . ".S" . $Season . "E" . $Episode . "." . $title . ".NoMercy";
328
329 // Check if the directory already exists.
330 if (!is_dir($folderOut)) {
331 // Directory does not exist, so lets create it.
332 mkdir($folderOut, 0777, true);
333 }
334 $initFile = $folderOut . "/" . $SeriesName2 . ".S" . $Season . "E" . $Episode . "." . $title . ".NoMercy.mp4";
335 $str1 = ["/mnt/vault/media", "#"];
336 $str2 = ["$siteHome/Media", "%23"];
337 $createFileURL= str_replace($str1, $str2, $initFile);
338
339 DB::statement("INSERT INTO `episodes`( `tvdbid`,`season`,`episode`,`title`,`description`,`language`,`abled`,`editedby`, `thumbnail`, `image`, `file`) VALUES ('$tvdbid','$Season','$Episode','$titlee','$overvieww','$language','disabled','$editedby', '$thumbnail', '$image', '$createFileURL') ON DUPLICATE KEY UPDATE `tvdbid` = '$tvdbid' , `season` = '$Season' , `episode` = '$Episode' , `title` = '$titlee' , `description` = '$overvieww' , `language` = '$language', `editedby` = '$editedby' , `thumbnail` = '$thumbnail', `image` = '$image'");
340
341
342
343 $myfile = fopen("/mnt/web420/e1/94/59497294/htdocs/public/active.txt", "w") or die("Unable to open file!");
344 $txt = $searchShow['seriesName'] . " S" . $Season . "E" . $Episode . " " . $title;
345 fwrite($myfile, $txt);
346 fclose($myfile);
347
348 // echo $fileOrig . "<br>";
349
350 // start processing found file
351 if (file_exists($fileOrig)) {
352
353 DB::statement("UPDATE `episodes` SET `abled` = 'disabled', `filetime` = '' WHERE `tvdbid`= $tvdbid and `season` = $Season and `episode` = $Episode");
354
355 // Set hardsub stream if requested in form
356 $hardsubb = null;
357 if (isset($hardsub) && $hardsub == "0") {
358 $hardsubb = "-vf subtitles='$fileOrig:si=0'";
359 }
360 if (isset($hardsub) && $hardsub == "1") {
361 $hardsubb = "-vf subtitles='$fileOrig:si=1'";
362 }
363 if (isset($hardsub) && $hardsub == "2") {
364 $hardsubb = "-vf subtitles='$fileOrig:si=2'";
365 }
366 if (isset($hardsub) && $hardsub == "3") {
367 $hardsubb = "-vf subtitles='$fileOrig:si=3'";
368 }
369 if (isset($hardsub) && $hardsub == "4") {
370 $hardsubb = "-vf subtitles='$fileOrig:si=4'";
371 }
372 if (isset($hardsub) && $hardsub == "5") {
373 $hardsubb = "-vf subtitles='$fileOrig:si=5'";
374 }
375 if (isset($hardsub) && $hardsub == "6") {
376 $hardsubb = "-vf subtitles='$fileOrig:si=6'";
377 }
378
379 $filetime = null;
380
381
382 $thumbFile = $folderOut . "/thumbs/Preview%04d.jpg";
383 $chapterfile = $folderOut . "/chapters.vtt";
384 $thumbnailfile = $folderOut . "/thumbnails.vtt";
385
386 // Unused data for index response because it's to long for an url.
387 $query_episode = "seriesid: $tvdbid<br>SeasonNumber: $Season<br>EpisodeNumber: $Episode<br>pisode_Name: $title<br>Overview: $overview<br>File: $fileOrig<br>filetime: $filetime<br>Thumbnail: $thumbnail";
388 $query_episode = json_encode($query_episode);
389
390 // Make file used by progressbar to show what file is being processed.
391 // echo $filetimename . "<br>";
392 if (isset($location) && $location == "download") {
393 $foldertype2 = "Download";
394 }
395
396 $tune = NULL;
397 if (isset($location) && $type == "anime") {
398 $str1 = ["Download" ,""];
399 $str2 = ["Anime", ""];
400 $filepath2 = str_replace($str1, $str2, $fileOrig);
401 $tune = "-tune animation";
402 }
403
404 if (isset($location) && $type == "tv") {
405 $str1 = ["Download" ," "];
406 $str2 = ["TV.Show", "."];
407 $filepath2 = str_replace($str1, $str2, $fileOrig);
408 }
409
410 // $audio = $fileid["audio"]["streams"];
411
412 $metatitle = $SeriesNameOrig . ".S" . $Season . "E" . $Episode . "." . $title . ".NoMercy";
413
414 // Create video data file
415 $ffprobe = 'ffprobe -v quiet -show_format -show_streams -show_chapters -print_format json "' . $fileOrig . '" 1> /mnt/web420/e1/94/59497294/htdocs/public/ffprobe.json 2>&1';
416 exec($ffprobe);
417
418 $contentJson = file_get_contents("/mnt/web420/e1/94/59497294/htdocs/public/ffprobe.json");
419 $content=json_decode($contentJson,true);
420
421 $duration = $content['format']['duration'];;
422 $duration = gmdate("H:i:s", $duration);
423
424
425 // Create seek thumbnails.
426 $thumbs = "ffmpeg -i '$fileOrig' -threads $threads -ss 00:00:05.000 -vf 'scale=144:-1,fps=2/10' '$thumbFile' -n 1> /mnt/web420/e1/94/59497294/htdocs/public/thumbnail.txt 2>&1";
427
428 if (isset($exec)) {
429 if(!file_exists($thumbnailfile)){
430 DB::statement("UPDATE `episodes` SET `abled` = 'disabled', `filetime` = 'Generating thumbnails <button type=\"button\" class=\"nav_card_image_encoding btn\"><div class=\"nav_card_encoding\"></div></button>' WHERE `tvdbid`= $tvdbid and `season` = $Season and `episode` = $Episode");
431
432 $thumbFolder = $folderOut . "/thumbs";
433 if (!is_dir($thumbFolder)) {
434 mkdir($thumbFolder, 0777, true);
435 }
436
437 exec($thumbs);
438 // Create VTT file to show seek thumbnails in player.
439 $begin = new DateTime("00:00:05.00");
440 $end = new DateTime($duration);
441 $interval = DateInterval::createFromDateString('5 sec');
442 $times = new DatePeriod($begin, $interval, $end);
443 $jpg = 1;
444 $mythumbFile = fopen($thumbnailfile, "w") or die("Unable to open file!");
445 $echoid = 1;
446 $echo[$echoid] = "WEBVTT ";
447 fwrite($mythumbFile, "$echo[$echoid]");
448 $echoid++;
449
450 foreach ($times as $time) {
451
452 $echo[$echoid] = str_replace("000000","000", $time->format('H:i:s.u')) . " --> " . str_replace("000000","000", $time->add($interval)->format('H:i:s.u'));
453 fwrite($mythumbFile, "$echo[$echoid]\n");
454 $echoid++;
455 $echo[$echoid] = "thumbs/Preview" . sprintf("%04d", $jpg) . ".jpg";
456 fwrite($mythumbFile, "$echo[$echoid]\n\n");
457 $echoid++;
458 $jpg++;
459 }
460 fclose($mythumbFile);
461 }
462 }
463
464 $audio_count = 0;
465 $audioLangShow = null;
466 foreach ($content['streams'] as $stream){
467
468 if($stream['codec_type'] == "audio"){
469 $audio_count++;
470 // $audioLangShow = $stream['tags']['language'];
471 if(isset($stream['tags']['language'])){
472 $audioLangShow .= str_replace($languageCode,$langName,$stream['tags']['language']) . " ";
473 }
474 else{
475 $audioLangShow = "English";
476 }
477 }
478 }
479 // echo $audio_count . "<br>";
480 DB::statement("UPDATE `shows` SET `language` = '$audioLangShow' WHERE `tvdbid`= $tvdbid");
481 $sql = "UPDATE `shows` SET `language` = '$audioLangShow' WHERE `tvdbid`= $tvdbid";
482 echo $sql . ";<br>";
483 DB::statement("UPDATE `episodes` SET `language` = '$audioLangShow' WHERE `tvdbid`= $tvdbid and `season` = $Season and `episode` = $Episode");
484 $sql = "UPDATE `episodes` SET `language` = '$audioLangShow' WHERE `tvdbid`= $tvdbid and `season` = $Season and `episode` = $Episode";
485 echo $sql . ";<br>";
486
487 $subtitle_count = 0;
488 foreach ($content['streams'] as $stream){
489 if($stream['codec_type'] == "subtitle"){
490 $subtitle_count++;
491 }
492 }
493 // echo $subtitle_count . "<br>";
494
495 foreach ($content['streams'] as $stream){
496 if($stream['codec_type'] == "video"){
497 if($stream['codec_name'] != "mjpeg"){
498 $video_map = "-map 0:" . $stream['index'] . " ";
499 }
500 }
501 }
502 $default = "+default";
503 $meta = null;
504 $metaid = 0;
505 foreach ($langOrder as $lang){
506 foreach ($content['streams'] as $stream){
507 if($stream['codec_type'] == "audio"){
508 if(isset($stream['tags']['language']) && $stream['tags']['language'] == "$lang"){
509
510 $audio_map .= "-map 0:" . $stream['index'] . " ";
511 $audio_language = $stream['tags']['language'];
512
513 $audio_title = str_replace($languageCode , $langName, $stream['tags']['language']);
514
515 $meta .= "-metadata:s:a:$metaid 'language=$audio_language' -disposition:a:$metaid $default -metadata:s:a:$metaid 'title=$audio_title' ";
516 $default = "-default";
517 }
518 if(!isset($stream['tags']['language']) || $stream['tags']['language'] == ''){
519 $audio_map .= "-map 0:" . $stream['index'] . " ";
520
521 $audio_language = "jpn";
522
523 $audio_title = str_replace($languageCode , $langName, $audio_language);
524
525 $meta .= "'-metadata:s:a:$metaid' 'language=$audio_language' -disposition:a:$metaid $default -metadata:s:a:$metaid 'title=$audio_title' ";
526 $default = "-default";
527 }
528 if(!isset($stream['tags']['language']) || $stream['tags']['language'] == 'und'){
529 $audio_map .= "-map 0:" . $stream['index'] . " ";
530
531 $audio_language = "jpn";
532
533 $audio_title = str_replace($languageCode , $langName, $audio_language);
534
535 $meta .= "'-metadata:s:a:$metaid' 'language=$audio_language' -disposition:a:$metaid $default -metadata:s:a:$metaid 'title=$audio_title' ";
536 $default = "-default";
537 }
538 }
539 }
540 $metaid++;
541 }
542
543 $mapping = $video_map . $audio_map;
544 // echo $meta . "<br>";
545 // echo $mapping . "<br>";
546 if (!empty($content['chapters'])) {
547 if (isset($exec)) {
548 $mychapfile = fopen($chapterfile, "w") or die("Unable to open file!");
549 $echoid = 1;
550 $chapterId = 1;
551 $chap[$echoid] = "WEBVTT ";
552
553 fwrite($mychapfile, "$chap[$echoid]");
554 $echoid++;
555 foreach ($content['chapters'] as $chapter){
556 $chapter_start_time = $chapter['start_time'];
557 $chapter_end_time = $chapter['end_time'];
558 $chapter_title = $chapter['tags']['title'];
559
560 $chap[$echoid] = "Chapter " . $chapterId;
561 fwrite($mychapfile, "$chap[$echoid]\n");
562 $echoid++;
563 $chapterId++;
564
565 $chap[$echoid] = gmdate('H:i:s', $chapter_end_time) . " --> " . gmdate('H:i:s', $chapter_end_time);
566 fwrite($mychapfile, "$chap[$echoid]\n");
567 $echoid++;
568
569 $chap[$echoid] = $chapter_title;
570 fwrite($mychapfile, "$chap[$echoid]\n\n");
571 $echoid++;
572
573 $chapterstart = floor($chapter_start_time);
574
575 DB::statement("UPDATE `episodes` SET `skipnext` = '$chapterstart' WHERE `tvdbid`= $tvdbid and `season` = $Season and `episode` = $Episode");
576 $sql = "UPDATE `episodes` SET `skipnext` = '$chapterstart' WHERE `tvdbid`= $tvdbid and `season` = $Season and `episode` = $Episode";
577 echo $sql . ";<br>";
578 }
579
580 fclose($mychapfile);
581 }
582 }
583
584 foreach ($content['streams'] as $stream){
585
586 if($stream['codec_type'] == "subtitle"){
587 $subtitle_codec_type = $stream['codec_type'];
588 $subtitle_index = $stream['index'];
589 $subtitle_map = "-map 0:" . $stream['index'] . " ";
590 $subtitle_codec_name = $stream['codec_name'];
591 if(isset($stream['tags']['language'])){
592 $subtitle_language = $stream['tags']['language'];
593 }
594 else{
595 $subtitle_language = "eng";
596 }
597 if(isset($stream['tags']['title'])){
598 $subtitle_title = $stream['tags']['title'];
599
600 $subtitle_preg = '/(?<title>\w+)( \[(?<type>\w+)\])?/';
601 preg_match($subtitle_preg, $subtitle_title, $sub_title);
602 // if($stream['tags']['title'] =! "SDH"){
603 $subtitle_title = $sub_title['title'];
604 // } else {
605 // $subtitle_title = null;
606 // }
607 }
608 else {
609 if(isset($stream['tags']['language'])){
610 $subtitle_title = str_replace($languageCode , $langName, $stream['tags']['language']);
611 }
612 else {
613 $subtitle_title = "";
614 }
615
616 }
617
618 // echo $subtitle_title . "<br>";
619
620 if ($subtitle_codec_name == 'subrip' || $subtitle_codec_name == 'ass'){
621
622 $subFolder = NULL;
623 $subUrl = NULL;
624
625 $subLangTitle = str_replace($languageCode, $langName, $subtitle_language);
626
627 if (strpos($subtitle_title, 'Signs') !== false || strpos($subtitle_title, 'signs') !== false || strpos($subtitle_title, 'Song') !== false || strpos($subtitle_title, 'song') !== false) {
628 $subFolder = str_replace(" ", "", str_replace($languageCode , $subLangTitle, $subLangTitle) . "_Sign");
629 $subLangTag = "sub_" . strtolower($subtitle_title) . "_sign";
630 }
631 if (strpos($subtitle_title, 'Full') !== false || strpos($subtitle_title, 'full') !== false) {
632 $subFolder = str_replace(" ", "", str_replace($languageCode , $langName, $subLangTitle) . "_Full");
633 $subLangTag = "sub_" . strtolower($subtitle_title) . "_full";
634 }
635 if (strpos($subtitle_title, 'SDH') !== false || strpos($subtitle_title, 'sdh') !== false){
636 $subFolder = str_replace(" ", "", str_replace($languageCode , $langName, $subLangTitle) . "_SDH");
637 $subLangTag = "sub_" . strtolower($subtitle_title) . "_sdh";
638 }
639 else{
640 if($subtitle_count == 1){
641 $subFolder = str_replace(" ", "", str_replace($languageCode , $langName, $subLangTitle) . "_SDH");
642 $subLangTag = "sub_" . $subtitle_language . "_sdh";
643
644 }
645 if($subtitle_count >=2){
646 $subFolder = str_replace(" ", "", str_replace($languageCode , $langName, $subLangTitle) . "_Full");
647 $subLangTag = "sub_" . $subtitle_language . "_full";
648 }
649 }
650
651 $subRoot = "/mnt/vault/media/" . $foldertype . "/Subtitles/" . $SeriesName . ".(" . $year . ")/VTT/" . $subFolder;
652 $subUrl = $siteHome ."/Media/" . $foldertype . "/Subtitles/" . $SeriesName . ".(" . $year . ")/VTT/" . $subFolder;
653 $subFile = $SeriesName2 . ".S" . $Season . "E" . $Episode . "." . $title . ".NoMercy.vtt";
654 $subtitleFile = $subRoot. "/" . $subFile;
655 $execSub = "ffmpeg -i '$fileOrig' -c:s webvtt $subtitle_map '$subtitleFile' -n 1> /mnt/web420/e1/94/59497294/htdocs/public/subtitle.txt 2>&1";
656 // echo $subLangTag . "<br>";
657 // echo $execSub . "<br>";
658
659 if (isset($exec)) {
660 if(!file_exists($subtitleFile)){
661 if (!is_dir($subRoot)) {
662 mkdir($subRoot, 0777, true);
663 }
664
665 DB::statement("UPDATE `episodes` SET `abled` = 'enabled', `filetime` = 'Fetching subtitles <button type=\"button\" class=\"nav_card_image_encoding btn\"><div class=\"nav_card_encoding\"></div></button>' WHERE `tvdbid`= $tvdbid and `season` = $Season and `episode` = $Episode");
666
667 exec($execSub);
668
669 if (!Schema::hasColumn('shows', "$subLangTag")){
670 DB::statement("ALTER TABLE `shows` ADD COLUMN `$subLangTag` VARCHAR(11) NULL DEFAULT NULL");
671 $sql = "ALTER TABLE `shows` ADD COLUMN `$subLangTag` VARCHAR(11) NULL DEFAULT NULL";
672 echo $sql . ";<br>";
673 }
674
675 if (!Schema::hasColumn('episodes', "$subLangTag")){
676 DB::statement("ALTER TABLE `episodes` ADD COLUMN `$subLangTag` VARCHAR(300) NULL DEFAULT NULL");
677 $sql = "ALTER TABLE `episodes` ADD COLUMN `$subLangTag` VARCHAR(300) NULL DEFAULT NULL";
678 echo $sql . ";<br>";
679 }
680 DB::statement("UPDATE `shows` SET `$subLangTag` = 'true' WHERE `tvdbid`= $tvdbid");
681 $sql = "UPDATE `shows` SET `$subLangTag` = 'true' WHERE `tvdbid`= $tvdbid";
682 echo $sql . ";<br>";
683 DB::statement("UPDATE `episodes` SET `$subLangTag` = '$subUrl/$subFile' WHERE `tvdbid`= $tvdbid and `season` = $Season and `episode` = $Episode");
684 $sql = "UPDATE `episodes` SET `$subLangTag` = '$subUrl/$subFile' WHERE `tvdbid`= $tvdbid and `season` = $Season and `episode` = $Episode";
685 echo $sql . ";<br>";
686 }
687 }
688 }
689
690 if ($subtitle_codec_name == 'ass'){
691
692 $subFolder = NULL;
693 $subUrl = NULL;
694
695 $subLangTitle = str_replace($languageCode, $langName, $subtitle_language);
696
697 if (strpos($subtitle_title, 'Signs') !== false || strpos($subtitle_title, 'signs') !== false || strpos($subtitle_title, 'Song') !== false || strpos($subtitle_title, 'song') !== false) {
698 $subFolder = str_replace(" ", "", str_replace($languageCode , $langName, $subLangTitle) . "_Sign");
699 $subLangTag = "sub_" . strtolower($subtitle_title) . "_sign";
700 }
701 if (strpos($subtitle_title, 'Full') !== false || strpos($subtitle_title, 'full') !== false) {
702 $subFolder = str_replace(" ", "", str_replace($languageCode , $langName, $subLangTitle) . "_Full");
703 $subLangTag = "sub_" . strtolower($subtitle_title) . "_full";
704 }
705 if (strpos($subtitle_title, 'SDH') !== false || strpos($subtitle_title, 'sdh') !== false){
706 $subFolder = str_replace(" ", "", str_replace($languageCode , $langName, $subLangTitle) . "_SDH");
707 $subLangTag = "sub_" . strtolower($subtitle_title) . "_sdh";
708 }
709 else{
710 if($subtitle_count == 1){
711 $subFolder = str_replace(" ", "", str_replace($languageCode , $langName, $subLangTitle) . "_SDH");
712 $subLangTag = "sub_" . $subtitle_language . "_sdh";
713
714 }
715 if($subtitle_count >=2){
716 $subFolder = str_replace(" ", "", str_replace($languageCode , $langName, $subLangTitle) . "_Full");
717 $subLangTag = "sub_" . $subtitle_language . "_full";
718 }
719 }
720
721 $subRoot = "/mnt/vault/media/" . $foldertype . "/Subtitles/" . $SeriesName . ".(" . $year . ")/ASS/" . $subFolder;
722 $subUrl = $siteHome ."/Media/" . $foldertype . "/Subtitles/" . $SeriesName . ".(" . $year . ")/ASS/" . $subFolder;
723 $subFile = $SeriesName2 . ".S" . $Season . "E" . $Episode . "." . $title . ".NoMercy.ass";
724 $subtitleFile = $subRoot. "/" . $subFile;
725 $execSub = "ffmpeg -i '$fileOrig' -c:s ass $subtitle_map '$subtitleFile' -n 1> /mnt/web420/e1/94/59497294/htdocs/public/subtitle.txt 2>&1";
726 // echo $subLangTag . "<br>";
727 // echo $execSub . "<br>";
728
729 if (isset($exec)) {
730 if (!is_dir($subRoot)) {
731 mkdir($subRoot, 0777, true);
732 }
733 exec($execSub);
734 }
735 }
736 }
737
738 if($stream['codec_type'] == "video"){
739 $video_codec_type = $stream['codec_type'];
740 $video_index = $stream['index'];
741 $video_map = "-map 0:" . $stream['index'] . " ";
742 $video_codec_name = $stream['codec_name'];
743 if(isset($stream['width'])){
744 $video_width = $stream['width'];
745 }
746 else{
747 $video_width = "1920";
748 }
749
750 if($video_height < $stream['height']){
751 $video_height = $stream['height'];
752 $str1 = ["1080", "720", "480"];
753 $str2= ["HD1080P", "HD720P", "SD480P"];
754 $quality = str_replace($str1, $str2, $video_height);
755 DB::statement("UPDATE `shows` SET `quality` = '$quality' WHERE `tvdbid`= $tvdbid");
756 $sql = "UPDATE `shows` SET `quality` = '$quality' WHERE `tvdbid`= $tvdbid";
757 echo $sql . ";<br>";
758 }
759 if($stream['height'] >= "1080") {
760 $videoScale = "-vf scale=1920x1080";
761 $quality = "HD1080P";
762 }
763 else {
764 $videoScale = null;
765 }
766 }
767
768 if($audio_count >= 2){
769
770 $indexFile = $folderOut . "/" . $SeriesName2 . ".S" . $Season . "E" . $Episode . "." . $title . ".NoMercy.m3u8";
771
772 $indexFileVideo = $folderOut . "/video.m3u8";
773 $str1 = ["/mnt/vault/media", "#"];
774 $str2 = ["$siteHome/Media", "%23"];
775 $createFileURL= str_replace($str1, $str2, $indexFile);
776
777 $hls = true;
778 $seriesName2 = addslashes($seriesName);
779 $epTitle2 = addslashes($epTitle);
780 $ffmpeg_video = "ffmpeg -i '$fileOrig' -threads $threads $mapping $vcodec $tune $hardsubb $videoScale -movflags +faststart $acodec -crf $crf -c:s mov_text -max_muxing_queue_size 1024 -map_metadata -1 $meta -disposition:v:0 +default -metadata:s:v:0 \"show=$seriesName2\" -metadata:s:v:0 'season_number=$Season' -metadata:s:v:0 'episode_id=$Episode' -metadata:s:v:0 \"title=$epTitle2\" -metadata:s:v:0 'network=$websiteTitle' -metadata:s:v:0 'comment=$encoder' -muxdelay 0 -y -f segment -segment_time 10 -segment_list_size 0 -segment_list '$indexFileVideo' -segment_format mpegts '$folderOut/video-%d.ts' 1> /mnt/web420/e1/94/59497294/htdocs/public/video.txt 2>&1";
781
782 $audio_id = 0;
783
784 // echo $ffmpeg_video . "<br>";
785 // $indexFile = $folderOut . "/" . $SeriesName2 . ".S" . $Season . "E" . $Episode . "." . $title . ".NoMercy.m3u8";
786
787 $myfile = fopen("$indexFile", "w") or die("Unable to open file!");
788
789 $indexId = 1;
790 $echo[$indexId] = "#EXTM3U";
791 fwrite($myfile, "$echo[$indexId]\n");
792 $indexId++;
793
794 $echo[$indexId] = "#EXT-X-VERSION:3";
795 fwrite($myfile, "$echo[$indexId]\n");
796 $indexId++;
797
798 $DEFAULT = "YES";
799 foreach ($langOrder as $lang){
800 foreach ($content['streams'] as $stream){
801 if($stream['codec_type'] == "audio"){
802 if($stream['tags']['language'] == "$lang"){
803 $audio_index = $stream['index'];
804 $audio_map = "-map 0:" . $stream['index'] . " ";
805 $audio_language = $stream['tags']['language'];
806
807 $indexFile = $folderOut . "/audio_$audio_language.m3u8";
808
809 $str1 = ["/mnt/vault/media", "#"];
810 $str2 = ["$siteHome/Media", "%23"];
811 $createFileURL= str_replace($str1, $str2, $folderOut . "/" . $SeriesName2 . ".S" . $Season . "E" . $Episode . "." . $title . ".NoMercy.m3u8");
812
813 $ffmpeg_audio = "ffmpeg -i '$fileOrig' -threads $threads $audio_map $acodec -muxdelay 0 -y -f segment -segment_time 10 -segment_list_size 0 -segment_list '" . $indexFile . "' -segment_format mpegts '" . $folderOut . "/audio_$audio_language-%d.aac' 1> /mnt/web420/e1/94/59497294/htdocs/public/audio$audio_id.txt 2>&1";
814
815 $echo[$indexId] = "#EXT-X-MEDIA:TYPE=\"AUDIO\",GROUP-ID=\"aac\",LANGUAGE=\"$lang\",NAME=" . str_replace($languageCode , $langName, $lang) . ",DEFAULT=\"$DEFAULT\",AUTOSELECT=\"YES\",URI=\"audio_$audio_language.m3u8\"";
816 fwrite($myfile, "$echo[$indexId]\n");
817 $indexId++;
818 $DEFAULT = "NO";
819
820 $audio_id++;
821 if (isset($exec)) {
822 if(!file_exists("$indexFile")){
823 DB::statement("UPDATE `episodes` SET `abled` = 'disabled', `filetime` = 'Encoding <button type=\"button\" class=\"nav_card_image_encoding btn\"><div class=\"nav_card_encoding\"></div></button>' WHERE `tvdbid`= $tvdbid and `season` = $Season and `episode` = $Episode");
824 exec($ffmpeg_audio);
825 }
826 }
827 // echo $ffmpeg_audio . "<br>";
828 }
829 }
830 }
831 }
832
833 $echo[$indexId] = "#EXT-X-STREAM-INF:BANDWIDTH=\"2962000\",NAME=\"Main\",CODECS=\"avc1.66.30\",RESOLUTION=\"$video_width" . "x". "$video_height\",AUDIO=\"aac\"";
834 fwrite($myfile, "$echo[$indexId]\n");
835 $indexId++;
836
837 $echo[$indexId] = "video.m3u8";
838 fwrite($myfile, "$echo[$indexId]\n");
839 $indexId++;
840 fclose($myfile);
841
842 if(!file_exists($indexFileVideo)){
843 DB::statement("UPDATE `episodes` SET `abled` = 'enabled', `filetime` = 'Live <button type=\"button\" class=\"nav_card_image_encoding btn\"><div class=\"nav_card_encoding\"></div></button>', `file` = '$createFileURL' WHERE `tvdbid`= $tvdbid and `season` = $Season and `episode` = $Episode");
844
845 exec($ffmpeg_video);
846 }
847
848
849 $sql = "UPDATE `episodes` SET `abled` = 'disabled', `filetime` = 'Encoding <button type=\"button\" class=\"nav_card_image_encoding btn\"><div class=\"nav_card_encoding\"></div></button>', `file` = '$createFileURL' WHERE `tvdbid`= $tvdbid and `season` = $Season and `episode` = $Episode";
850 echo $sql . ";<br>";
851 }
852 if($audio_count == 1){
853
854 $indexFile = $folderOut . "/" . $SeriesName2 . ".S" . $Season . "E" . $Episode . "." . $title . ".NoMercy.mp4";
855 $hls = false;
856
857
858 $str1 = ["/mnt/vault/media", "#"];
859 $str2 = ["$siteHome/Media", "%23"];
860 $createFileURL= str_replace($str1, $str2, $indexFile);
861
862 $seriesName2 = addslashes($seriesName);
863 $epTitle2 = addslashes($epTitle);
864 $ffmpeg_video = "ffmpeg -i '$fileOrig' -threads $threads $mapping $vcodec $tune $hardsubb $videoScale -movflags +faststart $acodec -crf $crf -c:s mov_text -map_metadata -1 $meta -disposition:v:0 +default -metadata:s:v:0 \"show=$seriesName2\" -metadata:s:v:0 'season_number=$Season' -metadata:s:v:0 'episode_id=$Episode' -metadata:s:v:0 \"title=$epTitle2\" -metadata:s:v:0 'network=$websiteTitle' -metadata:s:v:0 'comment=$encoder' -n -f mp4 '$indexFile' 1> /mnt/web420/e1/94/59497294/htdocs/public/video.txt 2>&1";
865
866 if (isset($exec)) {
867 if(!file_exists("$indexFile")){
868 DB::statement("UPDATE `episodes` SET `abled` = 'disabled', `filetime` = 'Encoding <button type=\"button\" class=\"nav_card_image_encoding btn\"><div class=\"nav_card_encoding\"></div></button>', `file` = '$createFileURL' WHERE `tvdbid`= $tvdbid and `season` = $Season and `episode` = $Episode");
869 $sql = "UPDATE `episodes` SET `abled` = 'disabled', `filetime` = 'Encoding <button type=\"button\" class=\"nav_card_image_encoding btn\"><div class=\"nav_card_encoding\"></div></button>', `file` = '$createFileURL' WHERE `tvdbid`= $tvdbid and `season` = $Season and `episode` = $Episode";
870 echo $sql . ";<br>";
871 exec($ffmpeg_video);
872 }
873 }
874 // echo $ffmpeg_video . "<br>";
875 }
876
877 if (isset($duration)) {
878 $abled = "enabled";
879 }
880 if (!isset($duration) && $Season !== "0") {
881 $abled = "disabled";
882 }
883 if (!isset($duration) && $Season == "0") {
884 $abled = "remove";
885 }
886
887 $str1 = ["/mnt/vault/media", "#"];
888 $str2 = ["$siteHome/Media", "%231"];
889 $thumbnailfileURL= str_replace($str1, $str2, $thumbnailfile);
890
891 DB::statement("UPDATE `episodes` SET `abled` = '$abled', `filetime` = '$duration', `thumbnails` = '$thumbnailfileURL' WHERE `tvdbid`= $tvdbid and `season` = $Season and `episode` = $Episode");
892 $sql = "UPDATE `episodes` SET `abled` = '$abled', `filetime` = '$duration', `thumbnails` = '$thumbnailfileURL' WHERE `tvdbid`= $tvdbid and `season` = $Season and `episode` = $Episode";
893 echo $sql . ";<br>";
894
895 $sql = "UPDATE `episodes` SET `abled` = 'disabled', `filetime` = 'Encoding <button type=\"button\" class=\"nav_card_image_encoding btn\"><div class=\"nav_card_encoding\"></div></button>', `file` = '$createFileURL' WHERE `tvdbid`= $tvdbid and `season` = $Season and `episode` = $Episode";
896 echo $sql . ";<br>";
897//
898// $updateTiletime = "UPDATE `episodes` SET `abled` = '$abled', `filetime` = '$duration', `thumbnails` = '$thumbnailfileURL' WHERE `tvdbid`= $tvdbid and `season` = $Season and `episode` = $Episode";
899// echo $updateTiletime. "<br>";
900 }
901 }
902 if (isset($exec)) {
903
904 $subType = ["Full", "Sign", "SDH",];
905
906 foreach($langName as $subLangName){
907 foreach($subType as $subtype){
908 $subLangTag = "sub_" . str_replace($langName, $languageCode, $subLangName) . "_" . $subtype;
909 $subFolder = $subLangName . "_" . $subtype;
910 $subRoot = "/mnt/vault/media/" . $foldertype . "/Subtitles/" . $SeriesName . ".(" . $year . ")/VTT/" . $subFolder;
911 $subUrl = $siteHome ."/Media/" . $foldertype . "/Subtitles/" . $SeriesName . ".(" . $year . ")/VTT/" . $subFolder;
912 $subFile = $SeriesName2 . ".S" . $Season . "E" . $Episode . "." . $title . ".NoMercy.vtt";
913 $subtitleFile = $subRoot. "/" . $subFile;
914 $subtitleURL = $subUrl. "/" . $subFile;
915 if (file_exists($subtitleFile)){
916 // echo $subtitleURL . "<br>";
917 if (!Schema::hasColumn('shows', "$subLangTag")){
918 DB::statement("ALTER TABLE `shows` ADD COLUMN `$subLangTag` VARCHAR(11) NULL DEFAULT NULL");
919 $sql = "ALTER TABLE `shows` ADD COLUMN `$subLangTag` VARCHAR(11) NULL DEFAULT NULL";
920 echo $sql . ";<br>";
921 }
922
923 if (!Schema::hasColumn('episodes', "$subLangTag")){
924 DB::statement("ALTER TABLE `episodes` ADD COLUMN `$subLangTag` VARCHAR(300) NULL DEFAULT NULL");
925 $sql = "ALTER TABLE `episodes` ADD COLUMN `$subLangTag` VARCHAR(300) NULL DEFAULT NULL";
926 echo $sql . ";<br>";
927 }
928 DB::statement("UPDATE `shows` SET `$subLangTag` = 'true' WHERE `tvdbid`= $tvdbid");
929 $subtitleURL = str_replace("#", "%23", $subtitleURL);
930 $sql = "UPDATE `shows` SET `$subLangTag` = 'true' WHERE `tvdbid`= $tvdbid";
931 echo $sql . ";<br>";
932 DB::statement("UPDATE `episodes` SET `$subLangTag` = '$subtitleURL' WHERE `tvdbid`= $tvdbid and `season` = $Season and `episode` = $Episode");
933 $sql = "UPDATE `episodes` SET `$subLangTag` = '$subtitleURL' WHERE `tvdbid`= $tvdbid and `season` = $Season and `episode` = $Episode";
934 echo $sql . ";<br>";
935
936 }
937
938 if (!file_exists($subtitleFile)){
939 // echo "NOT " . $subtitleFile . "<br>";
940 // if (Schema::hasColumn('shows', "$subLangTag")){
941 // DB::statement("UPDATE `shows` SET `$subLangTag` = NULL WHERE `tvdbid`= $tvdbid");
942 // $sql = "UPDATE `shows` SET `$subLangTag` = NULL WHERE `tvdbid`= $tvdbid";
943 // echo $sql . ";<br>";
944 // }
945
946 // if (Schema::hasColumn('episodes', "$subLangTag")){
947 // DB::statement("UPDATE `episodes` SET `$subLangTag` = '' WHERE `tvdbid`= $tvdbid and `season` = $Season and `episode` = $Episode");
948 // $sql = "UPDATE `episodes` SET `$subLangTag` = '' WHERE `tvdbid`= $tvdbid and `season` = $Season and `episode` = $Episode";
949 // echo $sql . ";<br>";
950 // }
951
952 }
953 }
954 }
955
956 $fileDoneIndexm3u8 = "/mnt/vault/media/" . $foldertype . "/" . $foldertype . "/" . $SeriesName . ".(" . $year . ")/" . $SeriesName2 . ".S" . $Season . "E" . $Episode . "." . $title . ".NoMercy/index.m3u8";
957 if (file_exists($fileDoneIndexm3u8)) {
958 $fileOut = $fileDoneIndexm3u8;
959 }
960
961 $fileDonem3u8 = "/mnt/vault/media/" . $foldertype . "/" . $foldertype . "/" . $SeriesName . ".(" . $year . ")/" . $SeriesName2 . ".S" . $Season . "E" . $Episode . "." . $title . ".NoMercy/" . $SeriesName2 . ".S" . $Season . "E" . $Episode . "." . $title . ".NoMercy.m3u8";
962 if (file_exists($fileDonem3u8)) {
963 $fileOut = $fileDonem3u8;
964 }
965
966 $fileDoneMp4 = "/mnt/vault/media/" . $foldertype . "/" . $foldertype . "/" . $SeriesName . ".(" . $year . ")/" . $SeriesName2 . ".S" . $Season . "E" . $Episode . "." . $title . ".NoMercy/" . $SeriesName2 . ".S" . $Season . "E" . $Episode . "." . $title . ".NoMercy.mp4";
967 if (file_exists($fileDoneMp4)) {
968 $fileOut = $fileDoneMp4;
969 }
970
971 if (isset($fileOut)) {
972
973 // echo $fileOut . "<br>";
974
975 $ffprobeOut = 'ffprobe -v quiet -show_format -show_streams -show_chapters -print_format json "' . $fileOut . '" 1> /mnt/web420/e1/94/59497294/htdocs/public/ffprobeout.json 2>&1';
976 exec($ffprobeOut);
977
978 $contentJsonOut = file_get_contents("/mnt/web420/e1/94/59497294/htdocs/public/ffprobeout.json");
979 $contentOut=json_decode($contentJsonOut,true);
980
981 $durationOut = gmdate("H:i:s", $contentOut['format']['duration']);
982
983 DB::statement("UPDATE `episodes` SET `filetime` = '$durationOut', `abled` = 'enabled' WHERE `tvdbid`= $tvdbid and `season` = $Season and `episode` = $Episode");
984 $sql = "UPDATE `episodes` SET `filetime` = '$durationOut', `abled` = 'enabled' WHERE `tvdbid`= $tvdbid and `season` = $Season and `episode` = $Episode";
985 echo $sql . ";<br>";
986
987 $audio_count = 0;
988 $audioLangShow = null;
989 foreach ($contentOut['streams'] as $stream){
990
991 if($stream['codec_type'] == "audio"){
992 $audio_count++;
993 // $audioLangShow = $stream['tags']['language'];
994 if(isset($stream['tags']['language'])){
995 $audioLangShow .= str_replace($languageCode,$langName,$stream['tags']['language']) . " ";
996 }
997 // else{
998 // $audioLangShow = "English";
999 // }
1000 }
1001 }
1002 // echo $audio_count . "<br>";
1003 DB::statement("UPDATE `shows` SET `language` = '$audioLangShow' WHERE `tvdbid`= $tvdbid");
1004 $sql = "UPDATE `shows` SET `language` = '$audioLangShow' WHERE `tvdbid`= $tvdbid";
1005 echo $sql . ";<br>";
1006 DB::statement("UPDATE `episodes` SET `language` = '$audioLangShow' WHERE `tvdbid`= $tvdbid and `season` = $Season and `episode` = $Episode");
1007 $sql = "UPDATE `episodes` SET `language` = '$audioLangShow' WHERE `tvdbid`= $tvdbid and `season` = $Season and `episode` = $Episode";
1008 echo $sql . ";<br>";
1009
1010
1011 }
1012 // else{
1013 // DB::statement("UPDATE `episodes` SET `filetime` = '', `abled` = 'disabled' WHERE `tvdbid`= $tvdbid and `season` = $Season and `episode` = $Episode");
1014 // }
1015 if (!isset($fileOut) && $Season != 0) {
1016 DB::statement("UPDATE `episodes` SET `filetime` = '', `abled` = 'remove' WHERE `tvdbid`= $tvdbid and `season` = $Season and `episode` = $Episode");
1017 $sql = "UPDATE `episodes` SET `filetime` = '', `abled` = 'remove' WHERE `tvdbid`= $tvdbid and `season` = $Season and `episode` = $Episode";
1018 echo $sql . ";<br>";
1019 }
1020 if (!isset($fileOut) && $Season >= 1) {
1021 DB::statement("UPDATE `episodes` SET `filetime` = '', `abled` = 'disabled' WHERE `tvdbid`= $tvdbid and `season` = $Season and `episode` = $Episode");
1022 $sql = "UPDATE `episodes` SET `filetime` = '', `abled` = 'disabled' WHERE `tvdbid`= $tvdbid and `season` = $Season and `episode` = $Episode";
1023 echo $sql . ";<br>";
1024 }
1025
1026 }
1027 // Cleanup files for progressbar.
1028 if (isset($exec)) {
1029 exec("rm /mnt/web420/e1/94/59497294/htdocs/public/audio0.txt");
1030 exec("rm /mnt/web420/e1/94/59497294/htdocs/public/audio1.txt");
1031 exec("rm /mnt/web420/e1/94/59497294/htdocs/public/audio2.txt");
1032 exec("rm /mnt/web420/e1/94/59497294/htdocs/public/audio3.txt");
1033 exec("rm /mnt/web420/e1/94/59497294/htdocs/public/audio4.txt");
1034 exec("rm /mnt/web420/e1/94/59497294/htdocs/public/video.txt");
1035 exec("rm /mnt/web420/e1/94/59497294/htdocs/public/active.txt");
1036 exec("rm /mnt/web420/e1/94/59497294/htdocs/public/thumbnail.txt");
1037 exec("rm /mnt/web420/e1/94/59497294/htdocs/public/subtitle.txt");
1038 exec("rm /mnt/web420/e1/94/59497294/htdocs/public/ffprobe.txt");
1039 exec("rm /mnt/web420/e1/94/59497294/htdocs/public/ffprobe.json");
1040 exec("rm /mnt/web420/e1/94/59497294/htdocs/public/ffprobeout.json");
1041 }
1042}
1043// Create return URi.
1044$trailer = Request::get('trailer');
1045Request::get('trailer') ? $trailer = "&trailer=$trailer" : '';
1046Request::get('location') ? $location = "&location=$location" : '';
1047Request::get('page') ? $page = "&page=$page" : '';
1048
1049Request::get('hardsub') ? $hardsub = "&hardsub=$hardsub" : '';
1050
1051$debug = Request::get('debug') ? Request::get('debug') : NULL;
1052if(!isset($debug)){
1053 header("Location: ../show?id=$tvdbid&type=$type&lang=$language&abled=$urlabled$trailer$location$page&hardsub=$hardsub&message=success&query_show=$query_show");
1054}