Small python script to rearrange channels.conf.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I wrote a small python script that helps me
keep my channels.conf tidy.

The scripts assumes that I have
(among others) channel groups
":HDTV", ":Deutschsprachig",
":(auch)Englisch", ":Verschiedenes",
":Astra Radio" and ":new channels"
at the end.

It moves all radio channels from
all groups into ":Astra Radio".

It moves channels that have
a HD in their name from ":new channels"
to ":HDTV".

It moves channels that have
geman sound from ":new channels"
to ":Deutschsprachig".

It moves channels that do not have
german sound, but english sound
from ":new channels" to ":(auch)Englisch".

All other new channels are moved from
":new channels" to ":Verschiedenes".

It ignores all non-"S19.2E" channels
(see my other posting).

Finally, all channel groups are sorted
alphabetically.

The script/program is a filter, so
you can do things like
   python sort_channels.py <channels.conf>channels.new

Cheers,
Carsten.






import sys
import string

channel_info = {}
sections = []
for line in sys.stdin:
   stripped_line = line.strip()
   if stripped_line.startswith(':'):
      sections.append(stripped_line)
      channel_info[sections[-1]] = []
   else:
      channel_info[sections[-1]].append(stripped_line)

radio_channels = []
for section in sections:
   tv_channels = []
   for line in channel_info[section]:
      fields = line.split(':')
      if fields[3] == "S19.2E":
         if fields[5] == '0': # VPID = 0 = radio channel
            radio_channels.append(line)
         else:
            tv_channels.append(line)
   channel_info[section] = tv_channels
   
channel_info[":Verschiedenes"] += channel_info[":Astra Radio"]
channel_info[":Astra Radio"] = radio_channels

for line in channel_info[":new channels"]:
   fields = line.split(':')
   if "HD" in fields[0]:
      channel_info[":HDTV"].append(line)
   elif "=deu" in fields[6]:
      channel_info[":Deutschsprachig"].append(line)
   elif "=eng" in fields[6]:
      channel_info[":(auch)Englisch"].append(line)
   else:
      channel_info[":Verschiedenes"].append(line)
channel_info[":new channels"] = []


for section in sections:
   print section
   for line in sorted(channel_info[section], key=string.lower):
      print line
    
_______________________________________________
vdr mailing list
vdr@xxxxxxxxxxx
http://www.linuxtv.org/cgi-bin/mailman/listinfo/vdr

[Index of Archives]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Util Linux NG]     [Xfree86]     [Big List of Linux Books]     [Fedora Users]     [Fedora Women]     [ALSA Devel]     [Linux USB]

  Powered by Linux