第一个源分析完毕 & 加入超时设计

This commit is contained in:
EvilCult 2019-05-22 18:34:05 +08:00
parent 2f2e3bfc35
commit a47033e7ce
4 changed files with 51 additions and 9 deletions

5
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"python.pythonPath": "/usr/local/bin/python",
"python.linting.pylintEnabled": true,
"python.linting.enabled": true
}

3
db.py
View File

@ -27,7 +27,7 @@ class DataBase :
try:
if not os.path.exists(self.dbAddress) :
os.makedirs(self.dbAddress)
self.dbAddress += 'database.db'
self.dbAddress += 'db.sqlite3'
self.conn = sqlite3.connect(self.dbAddress)
self.cur = self.conn.cursor()
return True
@ -87,4 +87,3 @@ class DataBase :
if tableStat == False :
self.create()

49
main.py
View File

@ -9,13 +9,49 @@ class Iptv :
def __init__ (self) :
self.T = tools.Tools()
def test (self) :
itemName = 'cctv-高清频道 世界地理 fhd'
result = self.fmtTitle(itemName)
return result
def getSourceA (self) :
url = 'https://www.jianshu.com/p/2499255c7e79'
req = [
'user-agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Mobile Safari/537.36',
]
res = self.T.getPage(url, req)
if res['code'] == 200 :
pattern = re.compile(r"<code(.*?)</code>", re.I|re.S)
tmp = pattern.findall(res['body'])[0]
pattern = re.compile(r"#EXTINF:0,(.*?)\n#EXTVLCOPT:network-caching=1000\n(.*?)\n", re.I|re.S)
sourceList = pattern.findall(tmp)
for item in sourceList :
playable = self.chkPlayable(item[1])
if playable == True :
info = self.fmtTitle(item[0])
print('title: ' + str(info['id']) + ' ' + str(info['title']))
print('url: ' + str(item[1]))
else :
pass # MAYBE later :P
else :
pass # MAYBE later :P
def chkPlayable (self, url) :
try:
res = self.T.getPage(url)
if res['code'] == 200 :
return True
else:
return False
except:
return False
def baseFilter (self) :
pass
def fmtTitle (self, string) :
pattern = re.compile(r"(cctv[-|\s]*\d*)*\s*?([^\w]*)\s*?(fhd|hd|sd)*", re.I)
pattern = re.compile(r"(cctv[-|\s]*\d*)*\s*?([^fhd|^hd|^sd|^\.m3u8]*)\s*?(fhd|hd|sd)*", re.I)
tmp = pattern.findall(string)[0]
result = {
@ -27,5 +63,4 @@ class Iptv :
return result
obj = Iptv()
str = obj.test()
print(str)
obj.getSourceA()

View File

@ -10,6 +10,9 @@ import sys
import StringIO
import gzip
import random
import socket
socket.setdefaulttimeout(5.0)
class Tools :