package joyproxy; use strict; use warnings "all"; use lib qw(./lib ./vendor_perl); use Fcntl qw(O_RDONLY O_WRONLY O_CREAT O_TRUNC); use HTTP::Tiny; use URI::URL; use URI::Escape; use conf; use Exporter qw(import); use vars qw/$VERSION/; $VERSION = "1.0"; our @EXPORT = qw(joyproxy joyurl); my $CONF = loadConf(); sub joyproxy ($) { my $str = shift; chomp($str); return ('500', 'text/plain', 'This is not reactor video') if ($str !~ /^img[0-9]+\.reactor\.cc/); my ($file, $filesize) = __dlfunc("http://$str"); if (defined($file)) { my $buf = ''; if (open(VID, '<', $file)) { read(VID, $buf, $filesize); close VID; if ($file =~ /\.mp4/i) { return ('200', 'video/mp4', $buf); } elsif ($file =~ /\.webm/i) { return ('200', 'video/webm', $buf); } else { return ('200', 'video/mpeg', $buf); } } else { unlink $file if (-f $file); return ('500', 'text/plain', "Unable to open file in temporary loaction: $!\n"); } } else { return ('500', 'text/plain', "Unable to get file from remote source!\n"); } } sub joyurl ($) { my $str = shift; $str = uri_unescape($str); if (length($str) < 60) { $str = ''; } else { $str = substr($str, 14); } if ($str =~ /^img\d+\.reactor\.cc/) { # img1.reactor.cc/pics/post/webm/видосик.webm my @url = split(/\//, $str); if (($url[3] eq 'webm' || $url[3] eq 'mp4') and ($url[4] =~ /\.webm$/ || $url[4] =~ /\.mp4$/)) { # we prefer mp4, right?, so my $fname; $fname = substr($url[4], 0, -4) if (substr($url[4], -4, 4) eq '.mp4'); $fname = substr($url[4], 0, -5) if (substr($url[4], -5, 6) eq '.webm'); $str = sprintf( "https://exs-elm.ru%s/joyproxy/%s/%s/%s/mp4/%s.mp4", $CONF->{api}->{prefix}, $url[0], $url[1], $url[2], $fname ); $str = __urlencode($str); } else { $str = ''; } } else { $str = ''; } my $msg = "