#!/usr/bin/python #coding:gbk # @IgnorePep8 import os, sys import urllib, urllib2 server_list = ['http://www.yezibo.com','http://www.dadou.tv','http://www.qso365.com','http://www.qvodso.cc','http://www.6so.cc','http://www.babykan.com','http://www.77sou.net','http://www.yes80.net','http://www.76du.cn','http://www.9ishou.com','http://www.zhiyehui.net','http://www.100soo.cn','http://www.yezibo.com','http://www.ivdy.cc','http://www.h888.net','http://www.kkso.cc','http://www.ediansou.com','http://www.bobo1314.com','http://www.19taoba.com','http://www.36so.com','http://www.dy135.com','http://www.nr54.com']#,'http://www.9skb.com'] pipe_name = '/tmp/START_SIGNAL' def get_html_text(url): text = '' try: responce = urllib2.urlopen(url, timeout=60) html = responce.read() text = urllib.url2pathname(html) except Exception: pass return text def get_play_url(url): play_url = '' res = None try: res = urllib2.urlopen(url, timeout=60) text = res.read() l = text.split('window.location.href=\'',2) if len(l) >= 2: play_url = l[1].split('\'')[0] except Exception: return 'http://' if play_url: return play_url else: return res.geturl() def get_http_url_list(url): url_list = [] text = get_html_text(url) l = text.split('href=\'http://') if len(l) >= 2: l = l[1:] for i in l: u = i.split('\'',2)[0] if u: url_list.append('http://%s' % u) l = text.split('href=\"http://') if len(l) >= 2: l = l[1:] for i in l: u = i.split('\"',2)[0] if u: url_list.append('http://%s' % u) return url_list def get_hid_list(url): hid_list = [] text = get_html_text(url) #l = text.split('openBox(') #if len(l) >= 2: # l = l[1:] # for i in l: # hid = i.split(',',2)[0] # if hid: # hid_list.append(hid) l = text.split('openPlay(\'') if len(l) >= 2: l = l[1:] for i in l: hid = i.split('\')',2)[0] if hid: hid_list.append(hid) l = text.split('openPlay(\"') if len(l) >= 2: l = l[1:] for i in l: hid = i.split('\")',2)[0] if hid: hid_list.append(hid) return hid_list def get_hash_list(url): hash_list = [] text = get_html_text(url) l = text.split('qvod://') if len(l) >= 2: l = l[1:] for i in l: hl = i.split('|',3) if len(hl) >= 3: hash_list.append(hl[1]) return hash_list def get_quote_keyward(keyword): keyword = keyword.decode(sys.stdin.encoding).encode('gbk') keyword = urllib.quote(keyword) return keyword def get_tn(keyword): tn = keyword.decode('utf8') return tn def write_hid_list(hid_list): fout = file('/tmp/hid_list','wb') fout.write(str(hid_list)) fout.close() def read_hid_list(): fin = file('/tmp/hid_list','rb') hid_text = fin.read() fin.close() hid_list = eval(hid_text) return hid_list def write_hash_url_dic(hash_url): fout = file('/tmp/hash_url_dic','wb') fout.write(str(hash_url)) fout.close() def read_hash_url_dic(): fin = file('/tmp/hash_url_dic','rb') hash_url_text = fin.read() fin.close() hash_url = eval(hash_url_text) return hash_url def build_pipe(): fd = os.open(pipe_name, os.O_NONBLOCK | os.O_CREAT | os.O_RDWR) return fd def send_start_signal(fd): os.write(fd,"START") def wait_start_signal(): fd = os.open(pipe_name, os.O_RDONLY) while os.read(fd, 5) <> 'START': continue os.close(fd) os.remove(pipe_name)