def xhrun(movies_name): r = search(movies_name) if r == None: failed_output('[x] 返回首页,请稍后再试...') else: title, content = parse_content(r) if title is None or content is None: return with open('history/{}.m3u8'.format(title), 'w') as f: f.write(content)
def search(movies_name): movies_name = quote(movies_name) url = root_url + '/search?s=' + movies_name r = requests.get(url, verify=False) if r.status_code != 200: failed_output("[x] Error! The status code is {}".format(r.status_code)) try: soup = parser(r) urls = soup.find_all('a', class_="fl title") for url in urls: details_url.append(url['href']) except Exception as e: failed_output("[x] {}".format(e))
def search(movies_name): ''' @param {type} 电影名字 @return: ''' movies_name = quote(movies_name, 'utf-8') payload = "wd=" + movies_name + "&submit=" print(" [-] 正在影院中进行搜索...") headers = { 'content-type': "application/x-www-form-urlencoded", } r = requests.post(url, data=payload, headers=headers, verify=False) if r.status_code == 200: succeed_output("[✓] 请求成功") return r else: failed_output("[x] 请求失败") return None
def main(): print(""" [-] 请根据以下序号进行选择: 1. 搜索播放链接 2. 搜索种子 3. 电台FM 4. 搜索音乐 e. exit """) choice = input(" [-] 请输入您的选择: ") if choice == "e": return if choice == "1": movies_name = input(' [-] 请输入视频名称: ') xhrun(movies_name) elif choice == "2": movies_name = input(' [-] 请输入视频名称: ') if os.path.exists(os.path.join('torrent',movies_name+".txt")): os.remove(os.path.join('torrent',movies_name+".txt")) ts = [ threading.Thread(target=dytt_run,args=(movies_name,)), threading.Thread(target=btbtdy_run,args=(movies_name,)) ] for t in ts: t.start() for t in ts: t.join() try: with open('torrent/'+movies_name+".txt",'r')as f: links = f.read() succeed_output("[√] 为您搜索到以下影片: \n{}".format(links)) except: failed_output("[x] 没有内容") elif choice == "3": fm_run(p) elif choice == "4": music_run() main()
def fm_run(p): banner = """ [-] 请输入你要听的电台编号:\t\n""" + " [{}].{} / ".format( 'e', "退出") + "[{}].{}\t\n".format('b', "返回") file = os.path.join(os.getcwd(), 'lib', 'fm.txt') with open(file, 'r', encoding="utf-8") as f: res = f.readlines() urls = [] titles = [] for i in range(1, len(res) + 1): content = res[i - 1].split(":") title = content[0] titles.append(title) urls.append(content[1].strip()) if i % 3 == 0: banner += " [{}].{:<8s}\t\n".format(str(i - 1), title) continue else: banner += " [{}].{:<8s}\t".format(str(i - 1), title) print(banner) ans = input(" [-] 请输入你的选择: ") if ans == "b" or ans == "b": p.stop() return if ans == 'e': p.stop() sys.exit(0) if ans: try: p.start_playing(urls[int(ans)]) succeed_output(" [√] 正在播放: {}...".format(titles[int(ans)])) except: p.stop() failed_output(" [x] 无效选项") fm_run(p)
def parse_content(r): html = r.text soup = BeautifulSoup(html, "html.parser") results = soup.find_all('a', class_="stui-vodlist__thumb lazyload") count = 0 if len(results) == 0: failed_output("[x] 没有找到该视频") return None, None succeed_output("[-] 一共搜索到 {} 部视频,根据输入以下序号进行下载...".format(len(results))) for result in results: title = result['title'] succeed_output("[✓] {} - {}".format(count, title)) count += 1 # 获取播放列表 if len(results) == 1: choice = 0 else: choice = input(" [-] 请输入您的选择: ") if choice == "b": return None, None link = results[int(choice)]['href'] title = results[int(choice)]['title'] content = "" links = get_playlist(link) for url in links: url = url['href'] t, u = get_video(url) succeed_output('[✓] ' + t + " " + u) m3u8_url = get_m3u8(u) content += t + "\n" + m3u8_url + '\n' return title, content