python 速度优化插件_用python给XBMC做的视频插件,运行速度很慢

本文介绍了一个使用Python编写的XBMC视频插件,由于运行速度较慢,作者通过优化HTTP请求、引入第三方库和数据处理等方式提高了插件性能,确保了在XBMC中流畅播放亲宝儿歌和贝瓦儿歌等内容。
摘要由CSDN通过智能技术生成

# coding=utf-8

import os, sys

# 配置第三方python包的路径

lib_path = os.path.join(sys.path[0], 'resources', 'lib')

# print lib_path

sys.path.append(lib_path)

# print sys.path

import urllib2

import gzip

import StringIO

import re

import time, random

import json

from xbmcswift2 import Plugin

from bs4 import BeautifulSoup

from bs4 import SoupStrainer

plugin = Plugin()

# 伪装成浏览器访问

UserAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0'

# UserAgent = 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)'

# 亲宝儿歌url地址

# url = 'http://www.youku.com/show_page/id_z750491c6a69911e2b2ac.html'

# 解析url,返回html_doc文档

def Get_Html_Doc(url):

req = urllib2.Request(url)

req.add_header('User-Agent', UserAgent)

response = urllib2.urlopen(req)

html_doc = response.read()

if response.headers.get('content-encoding', None) == 'gzip':

html_doc = gzip.GzipFile(fileobj=StringIO.StringIO(html_doc)).read()

charset = response.headers.getparam('charset')

response.close()

match = re.compile('

if match:

charset = match[0]

else:

match = re.compile('

if match:

charset = match[0]

if charset:

charset = cha

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值