Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for MediaInfo stuff. Helper works! But View has to be tested (!) #69

Merged
merged 7 commits into from
Dec 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
92 changes: 86 additions & 6 deletions app/Helpers/MediaInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function parse($string)

$output = [];
foreach ($lines as $line) {
$line = trim(strtolower($line));
$line = trim($line); // removed strtolower, unnecessary with the i-switch in the regexp (caseless) and adds problems with values; added it in the required places instead.
if (preg_match($this->regex_section, $line)) {
$section = $line;
$output[$section] = [];
Expand All @@ -46,7 +46,7 @@ private function parseSections(array $sections)
{
$output = [];
foreach ($sections as $key => $section) {
$key_section = explode(' ', $key)[0];
$key_section = strtolower(explode(' ', $key)[0]);
if (!empty($section)) {
if ($key_section == 'general') {
$output[$key_section] = $this->parseProperty($section, $key_section);
Expand All @@ -66,11 +66,11 @@ private function parseProperty($sections, $section)
$value = null;
$info = explode(":", $info, 2);
if (count($info) >= 2) {
$property = trim($info[0]);
$property = trim(strtolower($info[0]));
$value = trim($info[1]);
}
if ($property && $value) {
switch ($section) {
switch (strtolower($section)) {

case 'general':
switch ($property) {
Expand Down Expand Up @@ -164,6 +164,12 @@ private function parseProperty($sections, $section)
case "format profile":
$output['format_profile'] = $value;
break;
case "title":
$output['title'] = $value;
break;
case "color primaries":
$output['title'] = $value;
break;
case "scan type":
$output['scan_type'] = $value;
break;
Expand Down Expand Up @@ -253,14 +259,14 @@ private function parseFileSize($string)

private function parseBitRate($string)
{
$string = str_replace(' ', '', $string);
$string = str_replace(' ', '', strtolower($string));
$string = str_replace('kbps', ' kbps', $string);
return $string;
}

private function parseWidthHeight($string)
{
return str_replace(array('pixels', ' '), null, $string);
return str_replace(array('pixels', ' '), null, strtolower($string));
}

private function parseAudioChannels($string)
Expand All @@ -287,6 +293,80 @@ private function formatOutput($data)
return $output;
}

public function prepareViewCrumbs($data)
{
$output = ["general"=>[],"video"=>[],"audio"=>[]];

$general_crumbs = array("format"=>"ucfirst","duration"=>NULL);

if($data['general'] === NULL){
$output["general"] = NULL;
} else {
if(isset($data['general']['format'])) $output['general'][] = ucfirst($data['general']['format']);
if(isset($data['general']['duration'])) $output['general'][] = $data['general']['duration'];
}

if($data['video'] === NULL){
$output["video"] = NULL;
} else {

$temp_output = array();
foreach($data["video"] as $video_element){

$temp_video_output = array();
if(isset($video_element['format'])) $temp_video_output[] = strtoupper($video_element['format']);
if(isset($video_element['width']) && isset($video_element['height'])) $temp_video_output[] = $video_element['width']." x ".$video_element['height'];
foreach(array("aspect_ratio","frame_rate","bit_depth","bit_rate","format_profile","scan_type","title","color primaries") as $property){
if(isset($video_element[$property])) $temp_video_output[] = $video_element[$property];
}

if(!empty($temp_video_output)) $temp_output[]=$temp_video_output;
}

$output["video"] = !empty($temp_output) ? $temp_output : NULL;
}

if($data['audio'] === NULL){
$output["audio"] = NULL;
} else {

$temp_output = array();
foreach($data["audio"] as $audio_element){

$temp_audio_output = array();
foreach(array("language","format","channels","bit_rate","title") as $property){
if(isset($audio_element[$property])) $temp_audio_output[] = $audio_element[$property];
}

if(!empty($temp_audio_output)) $temp_output[]=$temp_audio_output;
}

$output["audio"] = !empty($temp_output) ? $temp_output : NULL;
}

if($data['text'] === NULL){
$output["text"] = NULL;
} else {

$temp_output = array();
foreach($data["text"] as $text_element){

$temp_text_output = array();
foreach(array("language","format","title") as $property){
if(isset($text_element[$property])) $temp_text_output[] = $text_element[$property];
}
if(isset($text_element['forced']) && strtolower($text_element['forced']) == "yes") $temp_text_output[] = "Forced";

if(!empty($temp_text_output)) $temp_output[]=$temp_text_output;
}

$output["text"] = !empty($temp_output) ? $temp_output : NULL;
}


return $output;
}

private function parseAudioFormat($string)
{

Expand Down
28 changes: 20 additions & 8 deletions app/Http/Controllers/TorrentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,24 +483,36 @@ public function torrent($slug, $id)
$featured = null;
}

$general = null;
$video = null;
$settings = null;
$audio = null;
$general_crumbs = null;
$text_crumbs = null;
$subtitle = null;
$view_crumbs = null;
$video_crumbs = null;
$settings = null;
$audio_crumbs = null;
$subtitle = null;
$subtitle_crumbs = null;
if ($torrent->mediainfo != null) {
$parser = new \App\Helpers\MediaInfo;
$parsed = $parser->parse($torrent->mediainfo);
$view_crumbs = $parser->prepareViewCrumbs($parsed);
$general = $parsed['general'];
$general_crumbs = $view_crumbs['general'];
$video = $parsed['video'];
$settings = $parsed['video'][0];
$video_crumbs = $view_crumbs['video'];
$settings = ($parsed['video'] !== NULL && isset($parsed['video'][0]) && isset($parsed['video'][0]['encoding_settings'])) ? $parsed['video'][0]['encoding_settings'] : NULL;
$audio = $parsed['audio'];
$audio_crumbs = $view_crumbs['audio'];
$subtitle = $parsed['text'];
} else {
$general = null;
$video = null;
$settings = null;
$audio = null;
$subtitle = null;
$subtitle_crumbs = $view_crumbs['text'];
}

return view('torrent.torrent', ['torrent' => $torrent, 'comments' => $comments, 'thanks' => $thanks, 'user' => $user, 'similar' => $similar,
'movie' => $movie, 'total_tips' => $total_tips, 'user_tips' => $user_tips, 'client' => $client, 'featured' => $featured, 'general' => $general,
'movie' => $movie, 'total_tips' => $total_tips, 'user_tips' => $user_tips, 'client' => $client, 'featured' => $featured, 'general' => $general, 'general_crumbs' => $general_crumbs, 'video_crumbs' => $video_crumbs, 'audio_crumbs' => $audio_crumbs, 'text_crumbs' => $text_crumbs,
'video' => $video, 'audio' => $audio, 'subtitle' => $subtitle, 'settings' => $settings, 'uploader' => $uploader]);
}

Expand Down
2 changes: 1 addition & 1 deletion resources/views/torrent/edit_tor.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@

<div class="form-group">
<label for="description">MediaInfo</label>
<textarea name="mediainfo" cols="30" rows="10" class="form-control" disabled>{{ $tor->mediainfo }}</textarea>
<textarea name="mediainfo" cols="30" rows="10" class="form-control">{{ $tor->mediainfo }}</textarea>
</div>

<label for="hidden" class="control-label">Anonymous Upload?</label>
Expand Down
86 changes: 62 additions & 24 deletions resources/views/torrent/torrent.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,36 +267,74 @@
<div class="panel-body torrent-desc">
<center><span class="text-bold text-blue">@emojione(':blue_heart:') Media Info Output @emojione(':blue_heart:')</span></center>
<br>
<span class="text-bold text-blue">@emojione(':name_badge:') FILE:</span>
<span class="text-bold"><em>{{ $general['file_name'] }}</em></span>
<br>
<br>
<span class="text-bold text-blue">@emojione(':information_source:') GENERAL:</span>
<span class="text-bold"><em>{{ ucfirst($general['format']) }} / {{ $general['duration'] }}</em></span>
<br>
<br>
@foreach($video as $key => $v)
<span class="text-bold text-blue">@emojione(':projector:') VIDEO:</span>
<span class="text-bold"><em>{{ strtoupper($v['format']) }} / {{ $v['width'] }} x {{ $v['height'] }} / {{ $v['aspect_ratio'] }} / {{ $v['frame_rate'] }} / {{ $v['bit_depth'] }} / {{ $v['bit_rate'] }} / {{ $v['format_profile'] }} / {{ $v['scan_type'] }}</em></span>
<br>
<br>
@endforeach
@foreach($audio as $key => $a)
@if($general !== null && isset($general['file_name']))
<span class="text-bold text-blue">@emojione(':name_badge:') FILE:</span>
<span class="text-bold"><em>{{ $general['file_name'] }}</em></span>
<br>
<br>
@endif
@if($general_crumbs !== null)
<span class="text-bold text-blue">@emojione(':information_source:') GENERAL:</span>
<span class="text-bold"><em>
@foreach($general_crumbs as $crumb)
{{ $crumb }}
@if(!$loop->last)
/
@endif
@endforeach
</em></span>
<br>
<br>
@endif
@if($video_crumbs !== null)
@foreach($video_crumbs as $key => $v)
<span class="text-bold text-blue">@emojione(':projector:') VIDEO:</span>
<span class="text-bold"><em>
@foreach($v as $crumb)
{{ $crumb }}
@if(!$loop->last)
/
@endif
@endforeach
</em></span>
<br>
<br>
@endforeach
@endif
@if($audio_crumbs !== null)
@foreach($audio_crumbs as $key => $a)
<span class="text-bold text-blue">@emojione(':loud_sound:') AUDIO {{ ++$key }}:</span>
<span class="text-bold"><em>{{ ucfirst($a['language']) }} / {{ strtoupper($a['format']) }} / {{ $a['channels'] }} / {{ $a['bit_rate'] }}</em></span>
<span class="text-bold"><em>
@foreach($a as $crumb)
{{ $crumb }}
@if(!$loop->last)
/
@endif
@endforeach
</em></span>
<br>
@endforeach
@endforeach
@endif
<br>
@foreach($subtitle as $key => $s)
<span class="text-bold text-blue">@emojione(':speech_balloon:') SUBTITLE {{ ++$key }}:</span>
<span class="text-bold"><em>{{ ucfirst($s['language']) }} / {{ $s['codec'] }}</em></span>
<br>
@endforeach
{{--@if($settings['encoding_settings'])
@if($text_crumbs !== null)
@foreach($subtitle as $key => $s)
<span class="text-bold text-blue">@emojione(':speech_balloon:') SUBTITLE {{ ++$key }}:</span>
<span class="text-bold"><em>
@foreach($s as $crumb)
{{ $crumb }}
@if(!$loop->last)
/
@endif
@endforeach
</em></span>
<br>
@endforeach
@endif
{{--@if($settings)
<br>
<span class="text-bold text-blue">@emojione(':gear:') ENCODE SETTINGS:</span>
<br>
<div class="decoda-code text-black">{{ $settings['encoding_settings'] }}</div>
<div class="decoda-code text-black">{{ $settings }}</div>
@endif--}}
<br>
<br>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/torrent/upload.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@

<center>
<button type="submit" name="preview" value="true" id="preview" class="btn btn-warning">Preview</button>
<button id="add" class="btn btn-default" disabled>Add MediaInfo Parser</button>
<button id="add" class="btn btn-default">Add MediaInfo Parser</button>
<button type="submit" name="post" value="true" id="post" class="btn btn-primary">Upload</button>
</center>
<br>
Expand Down