Here is a script to pull M3u8 from UFC.TV videos. You can stream ufc 202.
Read 150962 times
August 10, 2016, 03:57:14 PM
Here is a script to pull M3u8 from UFC.TV videos. You can stream ufc 202.
Script is in Python3
#!/usr/bin/env python3
  A simple little script for getting at the m3u8 for videos
  For free and ethical stream viewing free from proprietary players
  Doesn’t circumvent geo-blocks or login requirements
  You can get around the geo blocks via DNS proxies
  I have this saved as ufctv in a bin dir on my $PATH, so I can call it from wherever
  To login, run: ufctv login
  That will begin an interactive login prompt
  The login details themselves aren’t saved, just the cookies for the session
  And the active session is reset any time you login with the “Keep Me Signed In” box anywhere else
  To get a video’s m3u8: ufctv m3u8 $UFCTV-URL
  So for example if I want to go back and watch Belfort vs Hendo 3
  % ufctv m3u8
  From there you an do what you wish with the m3u8!
  You may wish to pipe the result direct to mpv (which lets you seek around and switch between qualities)
  % ufctv m3u8 | xargs mpv
  Or start ripping with livestreamer
  % ufctv m3u8 | xargs -I M3U8 livestreamer hlsvariant://M3U8 best -o belf-vs-hend.ts
  You can also rip the stream with ffmpeg, though I’ve found livestreamer does it a bit cleaner
  You may also wish to expand the program to add commands to do this for you instead of via shell piping
import argparse
import getpass
import json
import os
import pickle
import re
import subprocess
import sys
from requests import session
def main():
    parser = argparse.ArgumentParser(description=
        This is a command line tool to help enjoy quality UFC Fight Pass
        content in an ethical manner that respects your freedoms
        choices=[‘login’, ‘m3u8’])
    parser.add_argument(‘rest’, nargs=’*’)
    args = parser.parse_args()
    op = args.operation
    if op == ‘login’:
        return ufctv_login()
    if len( < 1:
        print(“Missing argument: video_url”, file=sys.stderr)
        return 1
    vid_url =[0]
    uri = get_m3u8(vid_url)
    if uri is None:
        return 2
    if args.operation == ‘m3u8’:
        return 0
def fake_mobile_session():
    with session() as c:
        c.headers.update({‘User-Agent’: (
            “Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us)”
            ” AppleWebKit/528.18 (KHTML, like Gecko)”
            ” Version/4.0 Mobile/7A341 Safari/528.16″)})
        return c
def get_m3u8_by_id(session, vid_id):
    puburi = “{}&format=json”
    r = session.get(puburi.format(vid_id))
    stream_info = json.loads(r.text)
    if ‘path’ not in stream_info:
        return None
    return stream_info[‘path’].replace(“_iphone”, “”)
def get_m3u8(uri):
    with fake_mobile_session() as c:
        r = c.get(uri)
        vid_id = find_video_id(r.text)
        if vid_id is None:
            print(“Failed to find video ID in page.”, file=sys.stderr)
            return None
        if not logged_in(r.text):
            print(“Goof Alert: You are not logged in to UFC.TV”, file=sys.stderr)
        if not video_allowed(r.text):
            print(“Video is not available”, file=sys.stderr)
            return None
        res = get_m3u8_by_id(c, vid_id)
        return res
ufctv_sesssion_path = os.path.expanduser(“~/.ufctv”)
def save_cookies(session):
    with open(ufctv_sesssion_path, ‘wb’) as f:
        pickle.dump(session.cookies, f)
def load_cookies(session):
    if not os.path.isfile(ufctv_sesssion_path):
        print(“No saved cookies file found — starting from scratch”, file=sys.stderr)
    with open(ufctv_sesssion_path, ‘rb’) as f:
def video_allowed(page_html):
    return ‘<div class=”noAccess”>’ not in page_html
def logged_in(page_html):
    return “Sign Out” in page_html
def ufctv_login():
    with fake_mobile_session() as c:
def login(sesh):
    username = input(“Please enter your username: “)
    password = getpass.getpass(“Please enter your password: “)
    longchoice = input(“Tick the ‘Keep Me Signed In’ box for a long lasting session? [y/n] “)
    longsesh = ‘true’ if longchoice is ‘y’ else ‘false’
    login = {
        ‘username’: username,
        ‘password’: password,
        ‘cookielink’: longsesh
    r =“”, data=login)
    if ‘loginsuccess’ not in r.text:
        print(“Login failure — full response:\n{}\n”.format(r.text), file=sys.stderr)
        return False
    return True
def find_video_id(page_html):
    m =“rel=\”image_src\” href=\”.*?([0-9]+?)_.*?\.jpg\””, page_html)
    if m is None:
        return m
if __name__ == “__main__”: