试图从流媒体网站下载视频,无法获取我需要的链接

时间:2019-08-28 20:09:22

标签: python video python-requests

所以我只是学习了如何使用请求模块(虽然不多,但是我看了几个视频),所以我尝试下载一个我喜欢的系列剧集-'Bull'。 所以我在这里找到了一个似乎可以用于单个文件的函数:

def download_file(url):
    local_filename = 'bull-season-2-ep-5.mp4'
    # NOTE the stream=True parameter
    r = requests.get(url, stream=True)
    with open(local_filename, 'wb') as f:
        for chunk in r.iter_content(chunk_size=1024): 
            if chunk: # filter out keep-alive new chunks
                f.write(chunk)
                #f.flush() commented by recommendation from J.F.Sebastian
    return local_filename

download_file(https://ww1.123movies.domains/tvseries/bull-season-2/9jpHC3uD/8J1Mx54O/wJbEvBiB-watch-free.html?start_watching=true&_=1567021316534")

但是从下面的照片中可以看到,该文件被分成了很多部分,所以我无法下载整个文件(当我检查网页的Blob时,如您所见,我转到了“网络”标签下面)。

enter image description here

我尝试使用第一个链接,如您所见,但这不起作用。 创建的链接中唯一的区别是'seg'数字

例如,这是一个链接:

https://stream-4-1.loadshare.org/stream/VideoID-5Xjczd53/Ry60dtNEZdzeDHMykqym7Wj-PVhL45OMuxLNI2rIH-0HUjnD6HhzRaxQFTUG3mfRHD-_lj-hgLrzI54m6b0homRf0HJWQVMx4uxcLDIM9tY8iy60-BfUFfNIoRvUuy8O/seg-15-v1-a1.ts?token=ip=93.173.86.29~st=1567021318~exp=1567035718~acl=/ *〜hmac = 6eb03c58be1eb01ce659384c30e67291748d4c86679dfca47f77edcf9ee8ec37

另一个:

https://stream-4-1.loadshare.org/stream/VideoID-5Xjczd53/Ry60dtNEZdzeDHMykqym7Wj-PVhL45OMuxLNI2rIH-0HUjnD6HhzRaxQFTUG3mfRHD-_lj-hgLrzI54m6b0homRf0HJWQVMx4uxcLDIM9tY8iy60-BfUFfNIoRvUuy8O/seg-20-v1-a1.ts?token=ip=93.173.86.29~st=1567021318~exp=1567035718~acl=/ *〜hmac = 6eb03c58be1eb01ce659384c30e67291748d4c86679dfca47f77edcf9ee8ec37

有人修复吗? 谢谢!

1 个答案:

答案 0 :(得分:0)

import requests
import m3u8

def download_file(url):

    local_filename = 'video.ts'
    r = requests.get(url)
    m3u8_master = m3u8.loads(r.text)
    playlist_url = m3u8_master.data['playlists'][0]['uri']
    full_url = url.split('/')
    full_url = "/".join(full_url[0:-2])
    full_url += '/'

    playlist_url = full_url + playlist_url
    new_r = requests.get(playlist_url)
    playlist = m3u8.loads(new_r.text)

    with open(local_filename, 'wb') as f:
        for segment in playlist.data['segments']:
            url = full_url + segment['uri']
            req = requests.get(url)
            f.write(req.content)

download_file("https://stream-4-1.loadshare.org/stream/VideoID-uJzosrrC/JToU5G8Qcw4SHs0l5HOqkCAtsSRhJvI2h2viOe9gMFgxLwl5PZPWQn4kV3zA14s5Opr9Z-poO9unm7L3I2XsjShpoq9CezUZJWqeOBwO8bbM3wFByH_hHteLDBeCi7yF/master.m3u8?token=ip=93.173.86.29~st=1567117245~exp=1567131645~acl=/*~hmac=7926c25f1766c342bd21a2273901ce3b1a83b6b8461a861175efc0588bbaae7e")

因此此功能有效。.如果有人想获得更详细的说明,我从此视频中获得了一些帮助:https://www.youtube.com/watch?v=bytnxnZFLeg&t=232s

我不得不去网络标签找到'master.m3u8'请求,然后从那里尝试分离不同的段并将它们连接成一个文件,例如Offbeatmammal和VC。谢谢。