Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【功能建议】请问是否能增加look直播 #584

Open
yiwen985 opened this issue Aug 2, 2023 · 2 comments
Open

【功能建议】请问是否能增加look直播 #584

yiwen985 opened this issue Aug 2, 2023 · 2 comments
Labels
help wanted Extra attention is needed

Comments

@yiwen985
Copy link

yiwen985 commented Aug 2, 2023

https://github.com/wbt5/real-url/blob/master/look.py 可能会有帮助。

网易云音乐app、Look直播app 分享链接均为:https://h5.look.163.com/live?liveId=68961733&id=49627449&pageType=1&ud=5AB50D7A1045FC0144209F1CDFB570AA

@yiwen985
Copy link
Author

yiwen985 commented Aug 5, 2023

import json
import re

import requests

from ..engine.decorators import Plugin
from . import logger
from ..engine.download import DownloadBase

import base64
import binascii
# import json
import random

# import requests
from Crypto.Cipher import AES

modulus = '00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7b725152b3ab17a876aea8a5aa76d2e417629ec4ee34' \
          '1f56135fccf695280104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932575cce10b424d813cfe4875d3e' \
          '82047b97ddef52741d546b8e289dc6935b3ece0462db0a22b8e7'
nonce = b'0CoJUm6Qyw8W8jud'
pubKey = '010001'

# !!!仅支持听听
# 格式
# 手机分享
#   https://h5.look.163.com/live?liveId=68995949&id=532194959&pageType=1&ud=5AB50D7A1045FC0144209F1CDFB570AA
# PC
#   https://look.163.com/live?id=388415721
@Plugin.download(regexp=r'(?:https?://)?h5\.look\.163\.com')
@Plugin.download(regexp=r'(?:https?://)?look\.163\.com')
class Look(DownloadBase):
    def __init__(self, fname, url, suffix='flv'):
        super().__init__(fname, url, suffix)
    
    def check_stream(self, is_check=False):
        rid = re.search(r'id=(\d*)', self.url).group(1)
        try:
            self.raw_stream_url = self.get_real_url(rid)['hlsPullUrl']
        except Exception as e:
            print('Exception:', e)
            return False
        return True
    
    def get_real_url(self, rid):
        try:
            request_data = encrypted_request({"liveRoomNo": rid})
            response = requests.post(url='https://api.look.163.com/weapi/livestream/room/get/v3', data=request_data)
            real_url = response.json()['data']['roomInfo']['liveUrl']
        except Exception:
            raise Exception('直播间不存在或未开播')
        self.room_title = response.json()['data']['roomInfo']['title']
        return real_url
    
        

def aes_encrypt(text, seckey):
    pad = 16 - len(text) % 16

    # aes加密需要byte类型。
    # 因为调用两次,下面还要进行补充位数。
    # 直接用try与if差不多。

    try:
        text = text.decode()
    except Exception as e:
        print(e)

    text = text + pad * chr(pad)
    try:
        text = text.encode()
    except Exception as e:
        print(e)

    encryptor = AES.new(seckey, 2, bytes('0102030405060708', 'utf-8'))
    ciphertext = encryptor.encrypt(text)
    ciphertext = base64.b64encode(ciphertext)
    return ciphertext


def create_secret_key(size):
    # 2中 os.urandom返回是个字符串。3中变成bytes。
    # 不过加密的目的是需要一个字符串。
    # 因为密钥之后会被加密到rsa中一起发送出去。
    # 所以即使是个固定的密钥也是可以的。

    # return (''.join(map(lambda xx: (hex(ord(xx))[2:]), os.urandom(size))))[0:16]
    return bytes(''.join(random.sample('1234567890qwertyuipasdfghjklzxcvbnm', size)), 'utf-8')


def rsa_encrypt(text, pub_key, mod):
    text = text[::-1]
    # 3中将字符串转成hex的函数变成了binascii.hexlify, 2中可以直接 str.encode('hex')
    rs = int(binascii.hexlify(text), 16) ** int(pub_key, 16) % int(mod, 16)
    return format(rs, 'x').zfill(256)


def encrypted_request(text):
    # 这边是加密过程。
    text = json.dumps(text)
    sec_key = create_secret_key(16)
    enc_text = aes_encrypt(aes_encrypt(text, nonce), sec_key)
    enc_sec_key = rsa_encrypt(sec_key, pubKey, modulus)
    # 在那个js中也可以找到。
    # params加密后是个byte,解下码。
    return {'params': enc_text.decode(), 'encSecKey': enc_sec_key}

# def get_real_url(rid):
#     try:
#         request_data = encrypted_request({"liveRoomNo": rid})
#         response = requests.post(url='https://api.look.163.com/weapi/livestream/room/get/v3', data=request_data)
#         real_url = response.json()['data']['roomInfo']['liveUrl']
#     except Exception:
#         raise Exception('直播间不存在或未开播')
#     return real_url

@xxxxuanran xxxxuanran added the help wanted Extra attention is needed label Aug 7, 2023
@xxxxuanran
Copy link
Contributor

image
以你提供的直播间地址为例,目前 Look直播 提供的直播流是纯音频流。而目前可上传的平台仅有 Bilibili,该平台不支持 纯音频流 的媒体文件,故暂时不考虑支持。
Look直播 含视频流的直播流仅限客户端,上述方法已不适用,欢迎其他大佬们提交获取流的方法。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants