增加json文件格式导出

This commit is contained in:
EvilCult 2019-06-05 18:52:40 +08:00 committed by GitHub
commit 59a6d82871
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 519 additions and 325 deletions

View File

@ -33,7 +33,17 @@ python main.py
- https://www.jianshu.com/p/2499255c7e79
- https://github.com/billy21/Tvlist-awesome-m3u-m3u8
- V2ex - [Dotpy](https://www.v2ex.com/member/Dotpy) 提供1600+可用播放源
- https://www.sheng521.top/zyfx/zbyfx
- 第五个源还在考虑要不要加....
#### 运行环境
---
python3.7
**python3.7**
人生苦短,我用Docker,本脚本,开发&运行&测试环境均使用docker镜像完成
两行命令构建
```
docker pull python:3.7
docker run -it --name python3 -v {脚本所在滤镜}:{容器里随便你想要的路径} python:3.7
```

2
db.py
View File

@ -36,7 +36,7 @@ class DataBase (object) :
def create (self) :
if self.connStat == False : return False
sql = 'create table ' + self.table + ' (id integer PRIMARY KEY autoincrement, title text, quality text, url text, level integer, enable integer, online integer, delay integer, udTime text)'
sql = 'create table ' + self.table + ' (id integer PRIMARY KEY autoincrement, title text, quality text, url text, level integer, cros integer, enable integer, online integer, delay integer, udTime text)'
self.cur.execute(sql)
def query (self, sql) :

48
main.py
View File

@ -5,6 +5,7 @@ import tools
import db
import time
import re
import json
from plugins import base
from plugins import lista
from plugins import listb
@ -32,12 +33,14 @@ class Iptv (object):
for item in urlList :
self.addData(item)
Dotpy = dotpy.Source()
urlList = Dotpy.getSource()
for item in urlList :
self.addData(item)
# Dotpy = dotpy.Source()
# urlList = Dotpy.getSource()
# for item in urlList :
# self.addData(item)
self.outPut()
self.outJson()
print("DONE!!")
def addData (self, data) :
@ -78,6 +81,43 @@ class Iptv (object):
f.write("#EXTINF:-1, group-title=\"%s\", %s\n" % (className, item[1]))
f.write("%s\n" % (item[3]))
def outJson (self) :
sql = """SELECT * FROM
(SELECT * FROM %s WHERE online = 1 ORDER BY delay DESC) AS delay
GROUP BY LOWER(delay.title)
HAVING delay.title != '' and delay.title != 'CCTV-' AND delay.delay < 500
ORDER BY level ASC, length(title) ASC, title ASC
""" % (self.DB.table)
result = self.DB.query(sql)
fmtList = {
'cctv': [],
'local': [],
'other': [],
'radio': []
}
for item in result :
tmp = {
'title': item[1],
'url': item[3]
}
if item[4] == 1 :
fmtList['cctv'].append(tmp)
elif item[4] == 2 :
fmtList['local'].append(tmp)
elif item[4] == 3 :
fmtList['local'].append(tmp)
elif item[4] == 7 :
fmtList['radio'].append(tmp)
else :
fmtList['other'].append(tmp)
jsonStr = json.dumps(fmtList)
with open('tv.json', 'w') as f:
f.write(jsonStr)
if __name__ == '__main__':
obj = Iptv()
obj.run()

View File

@ -37,6 +37,8 @@ class Source (object) :
netstat = self.T.chkPlayable(item[1])
if netstat > 0 :
cros = 1 if self.T.chkCros(item[1]) else 0
info = self.T.fmtTitle(item[0])
data = {
@ -45,6 +47,7 @@ class Source (object) :
'quality': str(info['quality']),
'delay' : netstat,
'level' : str(info['level']),
'cros' : cros,
'online' : 1,
'udTime' : self.now,
}

View File

@ -26,6 +26,8 @@ class Source (object) :
netstat = self.T.chkPlayable(item[1])
if netstat > 0 :
cros = 1 if self.T.chkCros(item[1]) else 0
info = self.T.fmtTitle(item[0])
data = {
@ -34,6 +36,7 @@ class Source (object) :
'quality': str(info['quality']),
'delay' : netstat,
'level' : info['level'],
'cros' : cros,
'online' : 1,
'udTime' : self.now,
}

View File

@ -34,6 +34,8 @@ class Source (object) :
netstat = self.T.chkPlayable(item[1])
i = i + 1
if netstat > 0 :
cros = 1 if self.T.chkCros(item[1]) else 0
info = self.T.fmtTitle(item[0])
data = {
@ -41,6 +43,7 @@ class Source (object) :
'url' : str(item[1]),
'quality': str(info['quality']),
'delay' : netstat,
'cros' : cros,
'level' : info['level'],
'online' : 1,
'udTime' : self.now,

View File

@ -47,6 +47,8 @@ class Source (object) :
netstat = self.T.chkPlayable(item[1])
if netstat > 0 :
cros = 1 if self.T.chkCros(item[1]) else 0
info = self.T.fmtTitle(item[0])
data = {
@ -55,6 +57,7 @@ class Source (object) :
'quality': str(info['quality']),
'delay' : netstat,
'level' : str(info['level']),
'cros' : cros,
'online' : 1,
'udTime' : self.now,
}

52
plugins/youku.py Normal file
View File

@ -0,0 +1,52 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import tools
import time
import re
class Source (object) :
def __init__ (self):
self.T = tools.Tools()
self.now = int(time.time() * 1000)
def getSource (self) :
urlList = []
url = 'https://list.youku.com/category/show/c_96.html'
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',
'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
'accept-language: zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7',
'upgrade-insecure-requests: 1',
'cookie: __ysuid=1540876852049YWA; __aysid=1559125737129tko; cna=iK1MFHdGNCACAdr3tQLvfWyB; _uab_collina=155912582425707377578055; yseidcount=1; juid=01dc1iku0414jb; ysestep=2; ystep=2; __ayft=1559193264281; __arpvid=1559193264282uJi2mp-1559193264434; __ayscnt=1; __aypstp=1; __ayspstp=9; P_ck_ctl=42B48D36975844B47D704789EF1B626C; isg=BG5utJpDvrYTl8rTl-ad8dTiv8I6b6UxM4jYMJg3inGsew7VAP96ez95Mq8yhyqB',
]
res = self.T.getPage(url, req)
if res['code'] == 200 :
pattern = re.compile(r"window\.__INITIAL_DATA__(.*?)categoryFilter\":{\"", re.I|re.S)
contentJS = pattern.findall(res['body'])
pattern = re.compile(r"\"title\":\"(.*?)\".*?\"videoId\":\"(.*?)\"", re.I|re.S)
movList = pattern.findall(contentJS[0])
movList = movList[1]
for mov in movList :
info = self.getVideoInfo('XNDIwMDAyMzE3Mg==')
print(info)
return urlList
def getVideoInfo (self, videoId) :
infoUrl = 'https://ups.youku.com/ups/get.json?&ccode=0501&client_ip=0.0.0.0&client_ts=1559195109&utid=QM7jEAtFLzkCAdr3tQK%2BqDe4&vid='
info = ''
try:
res = self.T.getPage(infoUrl + videoId, ['Referer:http://c-h5.youku.com/'])
print(res)
if res['body'] == '' :
info = False
except:
info = False
return info

View File

@ -146,3 +146,14 @@ class Tools (object) :
except:
return 0
def chkCros (self, url) :
return 0
# try:
# res = urllib.request.urlopen(url).getheader('Access-Control-Allow-Origin')
# if res == '*' :
# return True
# else :
# return False
# except:
# return 0

1
tv.json Normal file

File diff suppressed because one or more lines are too long

706
tv.m3u8

File diff suppressed because it is too large Load Diff