-
Notifications
You must be signed in to change notification settings - Fork 0
/
vcaluniq
executable file
·71 lines (68 loc) · 1.19 KB
/
vcaluniq
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
70
71
#!/usr/bin/perl
my %events = ();
my @lines = ();
my $id = undef;
my @headerLines = ();
while(<>) {
if(/BEGIN:VEVENT/) {
@lines=[$_];
last;
}
if(/X-WR-CALNAME:.*/) {
s/:.*/:TVshows\r/;
}
push @headerLines, $_;
}
while(<>) {
if(/BEGIN:VEVENT/) {
@lines=($_);
next;
}
if(/END:VEVENT/) {
push @lines, $_;
next unless defined($id);
$events{$id} = [ @lines ];
@lines=();
$id = undef;
next;
}
if(/UID:(.*)/) {
$id = $1;
chomp($id);
}
if(/(BEGIN|END):VCALENDAR/) {
# skip
next;
}
# my $line = $_;
# my $nextline = undef;
# if(/URL:.*$/) {
# $nextline = <>;
# if($nextline =~ /^\s+/) {
# $nextline =~ s/^\s+//;
# $line =~ s/\r//;
# chomp($line);
# $line .= $nextline;
# $nextline = undef;
# }
# }
push @lines, $_;
# push @lines, $nextline if defined($nextline);
}
print @headerLines;
foreach my $key (sort keys %events) {
print @{$events{$key}};
}
print "END:VCALENDAR\r\n";
__DATA__
BEGIN:VEVENT
UID:episode1584504@ical.tvmaze.com
DTSTART:20181227T170000Z
SEQUENCE:0
TRANSP:OPAQUE
DTEND:20181227T170000Z
URL:http://www.tvmaze.com/episodes/1584504/dc-daily-1x74-episode-74
SUMMARY:DC Daily: 1x74
DESCRIPTION:Episode 74
DTSTAMP:20190125T020546Z
END:VEVENT