aboutsummaryrefslogtreecommitdiffstats
path: root/web/stream.gathering.org/embed.pl
blob: 91fc413e3ecabc37b6179b66b4bad337d6ebba1f (plain)
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
#!/usr/bin/perl -I /root/tgmanage/web/stream.gathering.org/streamlib
use warnings;
use strict;
use CGI;
use Geo::IP;
use NetAddr::IP;
use Net::IP;
# apt-get install libnet-ip-perl libnetaddr-ip-perl 
use HTML::Template;
use stream;
use stream::config;

my $client = CGI->new;

my $v4net = $stream::config::v4net;
my $v6net = $stream::config::v6net;
my $tg = $stream::config::tg;
my $tg_full = $stream::config::tg_full;
my %streams = %stream::config::streams;

my $force_unicast = $client->param('forceunicast');
my $no_header = $client->param('noheader');

my $location = undef;

print $client->header();

my $clip = $client->remote_addr();
my $template = HTML::Template->new(filename => 'embed.tmpl');
my $is_local = &is_ip_local($clip, $v4net, $v6net);

my @streams = &html_local_test();
$template->param(TG => $tg);
$template->param(TG_FULL => $tg_full);
$template->param(STREAMS => \@streams);
$template->param(NOHEADER => $no_header);
print $template->output();


sub html_local_test() {
	my @s = ();
	foreach my $name (sort { $streams{$a}->{priority} <=> $streams{$b}->{priority} } keys %streams) {
		my $title_link = "http://stream.tg$tg.gathering.org/stream.pl?delivery=%s&stream=${name}&interlaced=%s";
		my $multicast_link = $streams{$name}->{has_multicast} ? "multicast" : "unicast";
		$multicast_link = "unicast" if ($force_unicast == 1 || not $is_local);

		if ($streams{$name}->{external}) {
			 $title_link = $streams{$name}->{url};
		} else {
			$title_link = sprintf($title_link, $multicast_link, $streams{$name}->{interlaced});
		}
		my %hash = (
			'title_link' => $title_link,
			'title' => $streams{$name}->{title},
			'quality' => $streams{$name}->{quality},
			'type' => $streams{$name}->{type},
		);
		if ($multicast_link eq "multicast") {
			$hash{'is_multicast'} .= 1; 
			my $unicast_link = $title_link;
			$unicast_link=~s/multicast/unicast/g;
			$hash{'unicast_link'} .= $unicast_link;
		}
		$hash{'description'} .= $streams{$name}->{description} if exists($streams{$name}->{description});
		push(@s, \%hash);

	}
	return @s;
}