吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 3775|回复: 34
收起左侧

[Python 转载] 【更新】<企鹅体育竞技直播>录屏程序v1.6(可双击运行)

[复制链接]
话痨司机啊 发表于 2022-6-14 13:11
本帖最后由 话痨司机啊 于 2023-6-1 23:47 编辑

【1.6成品(更新日期2023.06.01)】 https://www.123pan.com/s/E3kbVv-QLRBH.html提取码:52pj

  • 2022.06.15 更新内容
  • 增加非法字符过滤功能
  • 去除分类(因某些视频无法分类易混乱)
  • 增加无人值守录制视频功能

  • 2022.06.16 更新内容
  • 增加flv格式录制,降低CPU消耗


2022.06.30 更新内容:
1、增加随机请求(headers中的User-Agent随机获取
2、限制无人值守录制的检测直播函数的轮训监控频率,以防被服务器拒绝请求
3、使用短期链接,防止因keep-live时间过长服务器拒绝请求

2022.10.17 解决录制403问题

效果图:
1.png

23.png

4.png

55.png

源码展示:


[Python] 纯文本查看 复制代码
import hashlib
import os
import re
import subprocess as sub
import time
from urllib import parse
from pyfiglet import Figlet
import requests
import urllib3
from loguru import logger as log
from rich.console import Console
import threading
import signal
import urllib
from HEADERS import get_random_UA

urllib3.disable_warnings()


log.add('qi_e_log.log',encoding='utf8',level='INFO')
BASE_PATH = os.path.dirname(__file__)

def filter_title(title):
    """
    过滤文件名
    """
    new_title = re.sub(r"|[\\/:*?\"<>|]+", "", title.strip())
    return new_title

@log.catch
def record_flv(url,rtmp_url):
    '''
    录制flv
    '''
    nick_name,room_name = get_room_info(url)
    path = _mkdir(nick_name)
    time_str = time.strftime('%Y_%m_%d_%H_%M_%S', time.localtime(time.time()))
    file_path_name = os.path.join(path,room_name + '_' + time_str +'.flv')
    log.info('开始录制,播主:{},房间名称:{}\n保存位置:{}'.format(nick_name,room_name,file_path_name))
    opener = urllib.request.build_opener()
    opener.addheaders  = [('Referer','https://live.qq.com/')]
    urllib.request.install_opener(opener)
    urllib.request.urlretrieve(rtmp_url, file_path_name)
  
@log.catch
def figlet_font():
    f = Figlet(font='slant')
    print(f.renderText('Qi-E Record'))
    
@log.catch
def get_room_info(url):
    '''
    获取房间信息
    '''
    res = requests.get(url)
    room_name = re.findall(r'"room_name":"(.+?)","user_chat_level":',res.text)
    nick_name = re.findall(r'"nickname":"(.+?)","child_name"',res.text)
    room_name = filter_title(room_name[0])
    nick_name = filter_title(nick_name[0])
    return nick_name,room_name

@log.catch    
def _mkdir(nickname):
    '''
    创建文件夹
    '''
    path = os.path.join(os.getcwd(),'qi_e',nickname)
    if not os.path.exists(path):
        os.makedirs(path)
    return path 

@log.catch
def get_params(url):
    '''
    获取加密参数
    '''
    key = 'RgP7DW01naDYQSV0'
    room_id = url.split('/')[-1]
    time_params = int((int(time.time()) / 60000)*1000)
    keys = url.split('/')[-1] + key + str(time_params)
    bkeys = keys.encode('utf8')
    sign = hashlib.md5(bkeys).hexdigest()
    return room_id,time_params,sign

@log.catch
def get_video_url(url):
    '''
    获取直播流地址
    '''
    # 'https://live.qq.com/swf_api/room/10165096?cdn=ws&nofan=yes&_t=27741715&sign=b9c7d334d44a7115c20850a5e8667e16'
    room_id,time_params,sign = get_params(url)
    request_url = 'https://live.qq.com/swf_api/room/{room_id}?cdn=ws&nofan=yes&_t={time}&sign={sign}'.format(room_id=room_id, time=time_params,sign=sign)
    global headers
    headers = {'User-Agent': get_random_UA(),'Connection': 'close'}
    res = requests.get(request_url,headers=headers,verify=False).json()
    rtmp_url = parse.urljoin(res.get('data').get('rtmp_url'),res.get('data').get('rtmp_live'))
    return rtmp_url

def start_recording(url,record_url):
    '''
    调用录屏函数
    '''
    nick_name,room_name = get_room_info(url)
    __ffmepg = os.path.join(BASE_PATH,'ffmpeg.exe')
    path = _mkdir(nick_name)
    time_str = time.strftime('%Y_%m_%d_%H_%M_%S', time.localtime(time.time()))
    file_path_name = os.path.join(path,room_name + '_' + time_str +'.mp4')
    log.info('开始录制,播主:{},房间名称:{}\n保存位置:{}'.format(nick_name,room_name,file_path_name))
    cmd = [__ffmepg, "-y",
            "-v","verbose", 
            "-timeout","2000000",
            "-loglevel","error",
            "-hide_banner",
            "-user_agent",headers.get("User-Agent"),
            "-referer",'https://live.qq.com/'
            "-analyzeduration","2147483647",
            "-probesize","2147483647",
            "-i",record_url,
            '-bufsize','5000k',
            "-map","0",
            "-sn","-dn",
            '-max_muxing_queue_size','64',
            file_path_name]
    sub.check_call(cmd)

    
def replay_recording(url,num):
    '''
    循环监控录屏状态
    '''
    while True:
        try:
            if int(num) == 1:
                rtmp_url = get_video_url(url)
                start_recording(url,rtmp_url)
                time.sleep(5)
            elif int(num) == 2:
                rtmp_url = get_video_url(url)
                record_flv(url,rtmp_url)
                time.sleep(5)
        except Exception as e:
            if 'returned non-zero exit status 255.' in str(e):
                break
            elif 'returned non-zero exit status 1' in str(e):
                log.error('录屏失败,主播未开播或者网络异常,8秒重新尝试,如需退出请关闭窗口!')
                time.sleep(8)
            elif 'unknown url type' in str(e):
                log.error('录屏失败,主播未开播或者网络异常,8秒重新尝试,如需退出请关闭窗口!')
                time.sleep(8)
            else:
                log.exception(e)
                
@log.catch
def exit_recording(handler,frame):
    """
    退出录屏
    """
    log.warning('退出录屏')
    os._exit(0)

@log.catch
def main(url,num):
    """
    主逻辑函数
    """
    # 按Ctrl+C 退出
    record = threading.Thread(target=replay_recording,daemon=True,args=(url,num))
    record.start()
    signal.signal(signal.SIGINT, exit_recording)
    record.join()
        
if __name__ == '__main__':
    Console().print(f'[yellow]欢迎使用话痨的企鹅录屏[/yellow]\n[blue]{"=="*50}[/blue]\n[red]请输入这样的的直播间地址\'https://live.qq.com/10163895\'[/red]')
    Console().print("[red]{:*^100}[/red]".format('按下Ctrl+C退出直播录屏'))    
    # url = 'https://live.qq.com/10163895' #  直播间地址
    url = input('请输入直播间地址:').strip()
    num = input('请输入数字->1.录制mp4;->2.录制flv:').strip()
    if int(num) == 2:
        Console().print(f'[yellow]欢迎使用话痨的企鹅录屏[/yellow]\n[blue]{"=="*50}[/blue]\n[red]请输入这样的的直播间地址\'https://live.qq.com/10163895\'[/red]')
        Console().print("[red]{:*^100}[/red]".format('停止录播直接关闭窗口'))
    main(url,num)




突然想到我也没有女朋友,写个鸡儿代码

免费评分

参与人数 3吾爱币 +5 热心值 +3 收起 理由
myqqq + 2 + 1 谢谢@Thanks!
dashengguilai + 1 + 1 谢谢@Thanks!
MYLQG2ZHX + 2 + 1 热心回复!

查看全部评分

本帖被以下淘专辑推荐:

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

ihs 发表于 2023-9-18 12:20
请输入直播地址:https://live.qq.com/10144762
2023-09-18 12:02:15.753 | INFO     | __main__:main:107 - 检测主播是否开播中...
2023-09-18 12:02:26.189 | INFO     | __main__:thread_check_running_live:92 - 直播间状态:False,False==开播,Ture==停播
2023-09-18 12:02:28.266 | INFO     | __main__:home_handle:65 - room_name:_靠哥 斯蒂芬斯 VS 李安_,nickname:_球场裁决者_
Exception in callback SyncBase._sync.<locals>.<lambda>(<Task cancell...twork.py:362>>) at playwright\_impl\_sync_base.py:100
handle: <Handle SyncBase._sync.<locals>.<lambda>(<Task cancell...twork.py:362>>) at playwright\_impl\_sync_base.py:100>
Traceback (most recent call last):
  File "asyncio\events.py", line 80, in _run
  File "playwright\_impl\_sync_base.py", line 100, in <lambda>
  File "playwright\_impl\_helper.py", line 273, in impl
  File "playwright\_impl\_impl_to_api_mapping.py", line 123, in wrapper_func
  File "qezb.py", line 49, in handle
  File "playwright\sync_api\_generated.py", line 817, in fetch
  File "playwright\_impl\_sync_base.py", line 104, in _sync
  File "playwright\_impl\_network.py", line 372, in fetch
  File "playwright\_impl\_fetch.py", line 369, in _inner_fetch
  File "playwright\_impl\_connection.py", line 61, in send
  File "playwright\_impl\_connection.py", line 461, in wrap_api_call
  File "playwright\_impl\_connection.py", line 87, in inner_send
  File "asyncio\tasks.py", line 418, in wait
  File "asyncio\tasks.py", line 525, in _wait
asyncio.exceptions.CancelledError
2023-09-18 12:02:31.169 | INFO     | __main__:main:107 - 检测主播是否开播中...
2023-09-18 12:02:41.477 | INFO     | __main__:thread_check_running_live:92 - 直播间状态:False,False==开播,Ture==停播
2023-09-18 12:02:42.898 | INFO     | __main__:home_handle:65 - room_name:_靠哥 斯蒂芬斯 VS 李安_,nickname:_球场裁决者_
Exception in callback SyncBase._sync.<locals>.<lambda>(<Task cancell...twork.py:394>>) at playwright\_impl\_sync_base.py:100
handle: <Handle SyncBase._sync.<locals>.<lambda>(<Task cancell...twork.py:394>>) at playwright\_impl\_sync_base.py:100>
Traceback (most recent call last):
  File "asyncio\events.py", line 80, in _run
  File "playwright\_impl\_sync_base.py", line 100, in <lambda>
  File "playwright\_impl\_helper.py", line 273, in impl
  File "playwright\_impl\_impl_to_api_mapping.py", line 123, in wrapper_func
  File "qezb.py", line 66, in home_handle
  File "playwright\sync_api\_generated.py", line 1015, in continue_
  File "playwright\_impl\_sync_base.py", line 104, in _sync
  File "playwright\_impl\_network.py", line 404, in continue_
  File "playwright\_impl\_network.py", line 425, in continue_route
  File "playwright\_impl\_connection.py", line 461, in wrap_api_call
  File "playwright\_impl\_network.py", line 456, in _race_with_page_close
  File "asyncio\tasks.py", line 418, in wait
  File "asyncio\tasks.py", line 525, in _wait
asyncio.exceptions.CancelledError
2023-09-18 12:02:48.632 | INFO     | __main__:main:107 - 检测主播是否开播中...
2023-09-18 12:02:58.958 | INFO     | __main__:thread_check_running_live:92 - 直播间状态:False,False==开播,Ture==停播
2023-09-18 12:03:00.470 | INFO     | __main__:home_handle:65 - room_name:_靠哥 斯蒂芬斯 VS 李安_,nickname:_球场裁决者_
Exception in callback SyncBase._sync.<locals>.<lambda>(<Task finishe...msg': '授权过期'}>) at playwright\_impl\_sync_base.py:100
handle: <Handle SyncBase._sync.<locals>.<lambda>(<Task finishe...msg': '授权过期'}>) at playwright\_impl\_sync_base.py:100>
Traceback (most recent call last):
  File "asyncio\events.py", line 80, in _run
  File "playwright\_impl\_sync_base.py", line 100, in <lambda>
  File "playwright\_impl\_helper.py", line 273, in impl
  File "playwright\_impl\_impl_to_api_mapping.py", line 123, in wrapper_func
  File "qezb.py", line 51, in handle
AttributeError: 'str' object has no attribute 'get'
2023-09-18 12:03:03.362 | INFO     | __main__:main:107 - 检测主播是否开播中...

myqqq 发表于 2022-6-29 22:28

大佬,我6月26日出差,期间台式电脑一直运行监控两个主播,出差期间,该主播有正常开播,我29日回来,发现软件是在运行,但是只录制到6月26日的内容,27、28、29日这三天都未录制到,我上传log日记了,您看下是怎么回事「qi_e_log.log」https://www.aliyundrive.com/s/RDAhRN4BKmg
qiuyu2019 发表于 2022-6-14 13:42
MYLQG2ZHX 发表于 2022-6-14 13:47
我以为企鹅电竞复活了
头像被屏蔽
greatday 发表于 2022-6-14 14:25
提示: 作者被禁止或删除 内容自动屏蔽
十二三i 发表于 2022-6-14 14:42
感谢分享
liangqz 发表于 2022-6-14 17:27
感谢分享
hanqingv21 发表于 2022-6-14 17:58
昨天还有人跟你说有没有企鹅体育直播,今天就出来了
qqxiazhitmac 发表于 2022-6-14 18:45
谢谢!支持一下
myqqq 发表于 2022-6-14 18:56
大佬就是效率高,非常感谢,刚测试了一下,win10使用正常,但是win7打开就闪退,这是怎么回事呢?
雨之幽 发表于 2022-6-14 19:14
谢谢分享
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-24 17:48

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表