Using PyQt first procedure-bupt IPTV client

系统 1997 0

blog.sina.com.cn/s/blog_5a3640220100b0se.html - Translator


Using PyQt first procedure-bupt IPTV client
[此博文包含图片] (2008-11-11 14:59:14)
Reprint▼
Tags:
qt
iptv
it
    Category: Python
    To practice how to write a Gui program that is relatively simple, is to link hold down on your Web site, and then double-click called MPlayer for playback:
使用pyqt的第一个程序--北邮人IPTV客户端
   (1) get the link code (uses urllib and sgmllib library):
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import urllib
import sys
from sgmllib import SGMLParser
class URLLister(SGMLParser):
    def reset(self):
        SGMLParser.reset(self)
        self.pieces=[]
        self.urls=[]
        self.data=[]
        self.flag = 0

    def start_a(self,attrs):
        href=[v for k,v in attrs if k=="href"]
        if "mms" in str(href):
            self.pieces.extend(href)
            self.flag = 1

    def end_a(self):
        self.flag = 0

    def handle_data(self,text):
        if(self.flag == 1):
            self.pieces.extend([text.decode('GB2312').encode('UTF-8')]) # (sys.stdin.encoding)])

def getplaylist():
    playlist = []
    usock=urllib.urlopen("http://iptv.bupt.edu.cn/")
    parser=URLLister()
    parser.feed(usock.read())
    usock.close()
    parser.close()

    length = len(parser.pieces)/2
    for i in range(length) :
            playlist.extend(["%s %s" % (parser.pieces[i*2+1],parser.pieces[i*2])])
    return playlist

    (2) Gui part of the code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import sys
from PyQt4 import QtCore, QtGui
from iptv import Ui_iptv
import playlist
import string

class StartQt4(QtGui.QMainWindow):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_iptv()
        self.ui.setupUi(self)
        self.codec = QtCore.QTextCodec.codecForName('UTF-8')
        self.tvlist = playlist.getplaylist()
        self.ui.listTable.clear()
        for url in self.tvlist:
            item = QtGui.QListWidgetItem(self.ui.listTable)
            item.setText(QtGui.QApplication.translate("iptv", url, None, QtGui.QApplication.UnicodeUTF8))            
       QtCore.QObject.connect(self.ui.listTable,QtCore.SIGNAL("itemDoubleClicked(QListWidgetItem*)"),
self.play)
        QtCore.QMetaObject.connectSlotsByName(self)


    def play(self):
        import subprocess
        signalList = self.sender()
        Itemcount = signalList.currentRow()
        Itemtext = self.tvlist[Itemcount]
        url = string.split(Itemtext)[1]
        subprocess. Popen(["smplayer",url])
   
if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    myapp = StartQt4()
    myapp.show()
    sys.exit(app.exec_())

Using PyQt first procedure-bupt IPTV client


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论