2008-07-09

eeepc 使用技巧(4) 看电视

用小e在床头看电视在合适不过了,不过我没找到Linux下的网络电视软件。找来找去,发现一些可以用mplayer播放的mms链接,试了一下效果还不错,几个著名的电视台都有对应的链接,比如:凤凰卫视中文台mms://58.22.96.10/litv01;凤凰卫视资讯台mms://58.22.96.10/litv03;但是我的mplayer是基于命令行的,每次要看电视的时候还需把这些链接输入进去,感觉很不方便。刚好这两天对Python这个脚本语言比较感兴趣,于是想用Python写一个脚本来帮我输入这些链接。由于对Python还不熟,所以写的界面很丑,不过也够我用了。具体思路是,将这些链接首先存入一个文本文件里保存为channel.data,内容如下:凤凰卫视中文台|mms://58.22.96.10/litv01;凤凰卫视资讯台|mms://58.22.96.10/litv03;东风卫视|mms://58.22.96.10/litv07;精品影院|mms://218.1.70.72:1755/JingPinYingYuan;东方卫视|mms://live.smgbb.cn/dfws;星空卫视|mms://58.22.96.10/litv06;TVB8|mms://58.22.96.10/litv05; 然后写一个python脚本读取这些链接并将电视台的名称填入界面中的一个列表框里,到时候通过点击名称就可以播放了。

python脚本内容如下:

#!/usr/bin/env python
# -*- coding: UTF-8 -*-

from Tkinter import *
import os
import string


class Application(Frame):

    clist = list({})

    def play_channel(self, channelurl):
        strcmd = 'mplayer ' + channelurl + ' -cache 1024'
        str = os.popen(strcmd).read()
        a = str.split("\n")
        for b in a:
            print b
        print channelurl
   
    def play_tv(self):
        print self.clist[int(self.channellistbox.curselection()[0])]
        self.play_channel(self.clist[int(self.channellistbox.curselection()[0])])

    def initchannellist(self, Listbox):
        channelfile=open('tvchannel.dat', 'r')
        channelinfo=channelfile.readlines()
        channelfile.close()
        for i in range(len(channelinfo)):
            channellist = channelinfo[i].split(';')
            for j in range(len(channellist)):
                channel = channellist[j].split('|')
                channelname = channel[0]
                channelurl = channel[1]
                Listbox.insert(END, channelname)
                self.clist.append(channelurl)

    def createWidgets(self):
        self.quitbutton = Button(self)
        self.quitbutton["text"] = "quit",
        self.quitbutton["command"] = self.quit
        self.quitbutton["width"] = 30
        self.quitbutton["height"] = 10
        self.quitbutton.pack({"side": "left"})
       
        self.playtv = Button(self)
        self.playtv["text"] = "playtv",
        self.playtv["command"] = self.play_tv
        self.playtv["width"] = 30
        self.playtv["height"] = 10
        self.playtv.pack({"side": "left"})
       
        self.channellistbox = Listbox(self)
        self.initchannellist(self.channellistbox)
        self.channellistbox.selection_set(0)
        self.channellistbox.pack()

    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.pack()
        self.createWidgets()

app = Application()
app.mainloop()

保存为playtv.py,和刚才那个channel.dat放在一个目录,运行即可(python ./playtv.py)。

没有评论: