-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVideoLibrary.pm
More file actions
139 lines (128 loc) · 4.66 KB
/
Copy pathVideoLibrary.pm
File metadata and controls
139 lines (128 loc) · 4.66 KB
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
package MHFS::Plugin::VideoLibrary v0.7.0;
use 5.014;
use strict; use warnings;
use feature 'say';
use Feature::Compat::Try;
use Encode qw(decode);
use URI::Escape qw (uri_escape);
use MHFS::Util qw(output_dir_versatile escape_html uri_escape_path);
sub player_video {
my ($request) = @_;
my $qs = $request->{'qs'};
my $server = $request->{'client'}{'server'};
my $packagename = __PACKAGE__;
my $settings = $server->{'settings'};
my $self = $request->{'client'}{'server'}{'loaded_plugins'}{$packagename};
my $buf = "<html>";
$buf .= "<head>";
$buf .= '<style type="text/css">';
my $temp = do {
try { $server->GetTextResource($settings->{'DOCUMENTROOT'} . '/static/' . 'video_style.css') }
catch ($e) {
say "video_style.css not found";
\''
}
};
$buf .= $$temp;
$buf .= '.searchfield { width: 50%; margin: 30px;}';
$buf .= '</style>';
$buf .= "</head>";
$buf .= "<body>";
$qs->{'action'} //= 'library';
# action=library
$buf .= '<div id="medialist">';
$qs->{'library'} //= 'all';
$qs->{'library'} = lc($qs->{'library'});
my @libraries = ('movies', 'tv', 'other');
if($qs->{'library'} ne 'all') {
@libraries = ($qs->{'library'});
}
my %libraryprint = ( 'movies' => 'Movies', 'tv' => 'TV', 'other' => 'Other');
print "plugin $_\n" foreach keys %{$server->{'loaded_plugins'}};
my $fmt = $server->{'loaded_plugins'}{'MHFS::Plugin::GetVideo'}->video_get_format($qs->{'fmt'});
foreach my $library (@libraries) {
exists $settings->{'MEDIASOURCES'}{$library} or next;
my $lib = $settings->{'MEDIASOURCES'}{$library};
my $libhtmlcontent;
foreach my $sid (@$lib) {
my $sublib = $settings->{'SOURCES'}{$sid};
next if(! -d $sublib->{'folder'});
$libhtmlcontent .= ${video_library_html($sublib->{'folder'}, $library, $sid, {'fmt' => $fmt})};
}
next if(! $libhtmlcontent);
$buf .= "<h1>" . $libraryprint{$library} . "</h1><ul>\n";
$buf .= $libhtmlcontent.'</ul>';
}
$buf .= '</div>';
# add the video player
$temp = do {
try { $server->GetTextResource($server->{'loaded_plugins'}{'MHFS::Plugin::GetVideo'}{'VIDEOFORMATS'}{$fmt}->{'player_html'}) }
catch ($e) {
say "player_html not found";
\''
}
};
$buf .= $$temp;
$buf .= '<script>';
$temp = do {
try { $server->GetTextResource($settings->{'DOCUMENTROOT'} . '/static/' . 'setVideo.js'); }
catch ($e) {
say "setVideo.js not found";
\''
}
};
$buf .= $$temp;
$buf .= '</script>';
$buf .= "</body>";
$buf .= "</html>";
$request->SendHTML($buf);
}
sub video_library_html {
my ($dir, $lib, $sid, $opt) = @_;
my $fmt = $opt->{'fmt'};
my $urlconstant = 'lib='.$lib.'&sid='.$sid;
my $playlisturl = "playlist/video/$sid/";
my $buf;
output_dir_versatile($dir, {
'root' => $dir,
'min_file_size' => 100000,
'on_dir_start' => sub {
my ($realpath, $unsafe_relpath) = @_;
my $relpath = uri_escape($unsafe_relpath);
my $disppath = escape_html(decode('UTF-8', $unsafe_relpath));
$buf .= '<li><div class="row">';
$buf .= '<a href="#' . $relpath . '_hide" class="hide" id="' . $$disppath . '_hide">' . "$$disppath</a>";
$buf .= '<a href="#' . $relpath . '_show" class="show" id="' . $$disppath . '_show">' . "$$disppath</a>";
$buf .= ' <a href="'.$playlisturl . uri_escape_path($unsafe_relpath) . '?fmt=m3u8">M3U</a>';
$buf .= '<div class="list"><ul>';
},
'on_dir_end' => sub {
$buf .= '</ul></div></div></li>';
},
'on_file' => sub {
my ($realpath, $unsafe_relpath, $unsafe_name) = @_;
my $relpath = uri_escape($unsafe_relpath);
my $filename = escape_html(decode('UTF-8', $unsafe_name));
$buf .= '<li><a href="video?'.$urlconstant.'&name='.$relpath.'&fmt=' . $fmt . '" class="mediafile">' . $$filename . '</a> <a href="get_video?'.$urlconstant.'&name=' . $relpath . '&fmt=' . $fmt . '">DL</a> <a href="'.$playlisturl . uri_escape_path($unsafe_relpath) . '?fmt=m3u8">M3U</a></li>';
}
});
return \$buf;
}
sub new {
my ($class, $settings) = @_;
my $self = {};
bless $self, $class;
$self->{'routes'} = [
[
'/video', \&player_video
],
[
'/video/', sub {
my ($request) = @_;
$request->SendRedirect(301, '../video');
}
],
];
return $self;
}
1;