Project

General

Profile

Feature #1632 ยป fixChannelNumbers.pl

remember to fix home of .hts - Chico Zola, 2013-02-19 09:38

 
1
#!/usr/bin/perl
2

    
3
# read all mapped tvheadend channels
4
my @hts_channels = `grep '"name"' /home/xbmc/.hts/tvheadend/channels/* | sed 's/://g' | cut -d'"' -f1,4 | sort -k2 | sed 's/\t"/<->/g'`;
5
$i=0;
6
my $prevChannelName='';
7
foreach my $line (@hts_channels) {
8
        my ($fileid, $htsChannelName) = split("<->",$line);
9
        chomp($htsChannelName);
10
        if ($htsChannelName ne $prevChannelName) {
11
                $prevChannelName=$htsChannelName;
12
                $i++;
13
        }
14
        # For each channel list all xmltv references
15
        printf("\n$htsChannelName - $fileid" );
16
        system("cat $fileid | grep -v '\"channel_number\"' > $fileid.tmp; rm $fileid");
17
        open(IN, "<$fileid.tmp");
18
        open(OUT, ">$fileid");
19
        while(<IN>) {
20
                my($line) = $_;
21
                if ($line =~ m/"dvr_extra_time_post"/) {
22
                        print OUT $line;
23
                        print OUT "\t\"channel_number\": $i\n";
24
                }
25
                else {
26
                        print OUT $line;
27
                }
28
        }
29
        close(IN);
30
        close(OUT);
31
        system("rm $fileid.*");
32
}
    (1-1/1)