Last active
April 6, 2016 14:33
-
-
Save skaurus/801e058b4a56f40be1a5c30ed5ddd1dc to your computer and use it in GitHub Desktop.
Simple perl one-liner to fetch entire HLS stream given master playlist URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# all files will be fetched to current directory. | |
# dependencies - curl somewhere in $PATH and URI perl library. | |
perl -e 'use URI; my $m3u_url = shift or die "provide hls playlist url"; sub get { my $path = shift; my $rel = URI->new($path)->rel($m3u_url); `curl $path --progress-bar --create-dirs -o $rel` // die "getting $path failed!"; return $rel }; sub parse_pls { my ($file, $abs) = @_; open(my $fh, $file); return map { chomp; URI->new_abs($_, $abs) } grep { $_ !~ /^#/ } <$fh> }; my $file = get $m3u_url; my @urls = parse_pls($file, $m3u_url); my %loop; while (my $url = shift @urls) { die "loop detected!" if $loop{$url}++; my $file = get $url; push @urls, parse_pls($file, $url) if ($file =~ /\.m3u8$/) }' 'http://www.streambox.fr/playlists/x36xhzz/x36xhzz.m3u8' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment