py_tvlive2.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. # coding=utf-8
  2. # !/usr/bin/python
  3. import re
  4. import sys
  5. sys.path.append('..')
  6. from base.spider import Spider
  7. class Spider(Spider): # 元类 默认的元类 type
  8. def getName(self):
  9. return "电视直播"
  10. def init(self, extend=""):
  11. print("============{0}============".format(extend))
  12. pass
  13. def isVideoFormat(self, url):
  14. pass
  15. def manualVideoCheck(self):
  16. pass
  17. def homeContent(self, filter):
  18. result = {}
  19. cateManual = {
  20. "电视直播": "https://agit.ai/138001380000/MHQTV/raw/branch/master/TV/18c.txt"
  21. }
  22. classes = []
  23. for k in cateManual:
  24. classes.append({
  25. 'type_name': k,
  26. 'type_id': cateManual[k]
  27. })
  28. result['class'] = classes
  29. if (filter):
  30. result['filters'] = self.config['filter']
  31. return result
  32. def homeVideoContent(self):
  33. tid = self.homeContent(False)['class'][0]['type_id']
  34. result = self.categoryContent(tid, 1)
  35. return result
  36. def categoryContent(self, tid, pg, filter=False, extend=''):
  37. result = {}
  38. videos = []
  39. rsp = self.fetch(tid, headers=self.header)
  40. if '#EXTM3U' in rsp.text:
  41. txt_str = self.m3utotxt(rsp.text)
  42. else:
  43. txt_str = self.cleanText(rsp.text)
  44. infoList = txt_str.strip('\n').split('\n')
  45. groupposList = []
  46. i = 0
  47. for info in infoList:
  48. if info == '':
  49. i = i + 1
  50. continue
  51. info = info.split(',')
  52. if info[1].strip() == '#genre#' or i == len(infoList) - 1:
  53. if i == len(infoList) - 1:
  54. i = i + 1
  55. groupposList.append(i)
  56. if len(groupposList) == 2:
  57. videos.append({
  58. "vod_id": '{}@@@{}@@@{}@@@{}'.format(groupposList[0] + 1, groupposList[1] - 1, group, tid),
  59. "vod_name": group,
  60. "vod_pic": 'https://i.postimg.cc/dty6NDQ1/zhibo.png',
  61. "vod_remarks": ''
  62. })
  63. del (groupposList[0])
  64. group = info[0].strip()
  65. i = i + 1
  66. result['list'] = videos
  67. result['page'] = 1
  68. result['pagecount'] = 1
  69. result['limit'] = len(videos)
  70. result['total'] = len(videos)
  71. return result
  72. def detailContent(self, array):
  73. ids = array[0].split('@@@')
  74. url = ids[3]
  75. title = ids[2]
  76. end_lint = int(ids[1])
  77. start_line = int(ids[0])
  78. rsp = self.fetch(url,headers=self.header)
  79. if '#EXTM3U' in rsp.text:
  80. txt_str = self.m3utotxt(rsp.text)
  81. else:
  82. txt_str = self.cleanText(rsp.text)
  83. infoList = txt_str.strip('\n').split('\n')[start_line:end_lint]
  84. vod = {
  85. "vod_id": title,
  86. "vod_name": title,
  87. "vod_pic": 'https://i.postimg.cc/dty6NDQ1/zhibo.png',
  88. "vod_tag": '',
  89. "vod_play_from": title
  90. }
  91. purl = ''
  92. for info in infoList:
  93. if info == '':
  94. continue
  95. purl = purl + '{}${}#'.format(info.split(',')[0], info.split(',')[1])
  96. vod['vod_play_url'] = purl.strip('#')
  97. result = {
  98. 'list': [
  99. vod
  100. ]
  101. }
  102. return result
  103. def searchContent(self, key, quick):
  104. result = {
  105. 'list': []
  106. }
  107. return result
  108. def playerContent(self, flag, id, vipFlags):
  109. result = {}
  110. result["parse"] = 0
  111. result["playUrl"] = ''
  112. result["url"] = id
  113. return result
  114. flurl = ''
  115. config = {
  116. "player": {},
  117. "filter": {}
  118. }
  119. header = {}
  120. def m3utotxt(self, m3u_str):
  121. infos = m3u_str.strip('\n').split('\n')
  122. txtDict = {}
  123. txtList = []
  124. groupList = []
  125. txt_str = ''
  126. for info in infos:
  127. if info.startswith('#EXTINF'):
  128. infoList = info.split(',')
  129. channel = infoList[-1]
  130. infoList = infoList[0].strip().split()
  131. url = infos[infos.index(info) + 1]
  132. for iL in infoList:
  133. if iL.startswith('group-title'):
  134. group = iL.split('=', 1)[1]
  135. if group not in groupList:
  136. groupList.append(group)
  137. locals()[group] = '{},#genre#\n'.format(group)
  138. locals()[group] = locals()[group] + '{},{}\n'.format(channel, url)
  139. txt_str = txt_str + '{},{}\n'.format(channel, url)
  140. if len(groupList) != 0:
  141. txt_str = ''
  142. for group in groupList:
  143. txt_str = txt_str + locals()[group]
  144. return txt_str
  145. def localProxy(self, param):
  146. return [200, "video/MP2T", action, ""]