#!/usr/bin/perl -w
#
# hls-fetch - Download and decrypt HTTP Live Streaming videos.
# Copyright (C) 2012 Oskar Liljeblad
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#
use strict;
use Getopt::Long;
use HTML::Parser;
use LWP::UserAgent;
use JSON;
use File::Temp qw(tempfile);
use URI::URL;
use constant READ_SIZE => 1024;
my %opt = ('bandwidth' => 'max');
Getopt::Long::GetOptions(\%opt, 'embedded', 'svtplay', 'playlist', 'output|o=s', 'bandwidth|b=s', 'quiet|q', 'force|f', 'verbose|v', 'no-decrypt', 'version', 'help') || exit 1;
if ($opt{'version'}) {
print "hls-fetch 0.1\n";
print "Copyright (C) 2012 Oskar Liljeblad\n";
print "License GPLv3+: GNU GPL version 3 or later .\n";
print "This is free software: you are free to change and redistribute it.\n";
print "There is NO WARRANTY, to the extent permitted by law.\n\n";
print "Written by Oskar Liljeblad.\n";
exit 0;
}
if ($opt{'help'}) {
print "Usage: hls-fetch [OPTION]... URL\n";
print "Download and decrypt videos served by the HTTP Live Streaming (HLS) protocol.\n\n";
print " --embedded URL refers to a page with