py_tvlive.py 5.0 KB

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