-
Notifications
You must be signed in to change notification settings - Fork 7
/
m3u.pl
61 lines (44 loc) · 1.24 KB
/
m3u.pl
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
#!/usr/bin/perl
# This script parses M3U into tab-separated values (tsv-file)
# Only supports entries with EXTINF tag
# EXTM3U is hard to parse and use from shell scripts
# I couldnt find a working M3U parser so I wrote my own
# Examples:
# cat playlist.m3u | ./m3u.pl | cut -d '\t' -f 3 | sort -u
# gets all groups(categories) from playlist
# ./m3u.pl playlist.m3u | awk -F'\t' '$1 == "My item" {print $2}'
# prints URL of My item
use Text::ParseWords;
use strict;
use warnings;
use v5.22;
use utf8::all;
while ( <> ) {
# m3u parser
# populate opts hash-array
chomp;
next unless /^#EXTINF:/;
my @p = split(/,/, $_, 2);
my @args = shellwords($p[0]);
my %opts = ();
$opts{time} = shift @args;
$opts{time} =~ s/^#EXTINF://;
$opts{name} = $p[1];
my $url = <>;
while($url =~ /^#/) { $url = <>; }
chomp $url;
$opts{url} = $url;
for my $a ( @args ) {
my @kv = split /=/, $a, 2;
$opts{$kv[0]} = $kv[1];
}
# m3u parsed!
# print channels as tab separated values (tsv-file)
# you can modify to add your fields
say join("\t",
$opts{name},
$opts{url},
$opts{'group-title'},
$opts{'tvg-logo'}
);
}