Categories: Videos

SCRIPT FOR GETTING M3U8 FROM UFC.TV VIDEOS


SCRIPT FOR GETTING M3U8 FROM UFC.TV VIDEOS

For Knowledge only! Here is a small script for ripping M3u8 from the UFC.TV videos. Done with Python3 and use at your own will and risk! Thank you to the authors that posted it online.

#!/usr/bin/env python3

“””
A simple little script for getting at the m3u8 for ufc.tv videos
For free and ethical stream viewing free from proprietary players

Doesn’t circumvent geo-blocks or login requirements
You can get around the ufc.tv 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 //www.ufc.tv/video/belfort-vs-henderson-3
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 //www.ufc.tv/video/belfort-vs-henderson-3 | xargs mpv

Or start ripping with livestreamer
% ufctv m3u8 //www.ufc.tv/video/belfort-vs-henderson-3 | 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
“””)

parser.add_argument(‘operation’,
choices=[‘login’, ‘m3u8’])

parser.add_argument(‘rest’, nargs=’*’)

args = parser.parse_args()

op = args.operation
if op == ‘login’:
return ufctv_login()

if len(args.rest) < 1:
print(“Missing argument: video_url”, file=sys.stderr)
return 1

vid_url = args.rest[0]
uri = get_m3u8(vid_url)
if uri is None:
return 2

if args.operation == ‘m3u8’:
print(uri)
return 0

def fake_mobile_session():
with session() as c:
load_cookies(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 = “//www.ufc.tv/service/publishpoint?type=video&id={}&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)
save_cookies(c)
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)
return

with open(ufctv_sesssion_path, ‘rb’) as f:
session.cookies.update(pickle.load(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:
login(c)
save_cookies(c)

def login(sesh):
username = input(“Please enter your ufc.tv username: “)
password = getpass.getpass(“Please enter your ufc.tv 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 = sesh.post(“//www.ufc.tv/secure/authenticate”, 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 = re.search(“rel=\”image_src\” href=\”.*?([0-9]+?)_.*?\.jpg\””, page_html)
if m is None:
return m
return m.group(1)

if __name__ == “__main__”:
sys.exit(main())

********************************************************************************************************************************************************************************************************************************

  1. #!/usr/bin/env python3
  2. “””
  3.   A simple little script for getting at the m3u8 for ufc.tv videos
  4.   For free and ethical stream viewing free from proprietary players
  5.   Doesn’t circumvent geo-blocks or login requirements
  6.   You can get around the ufc.tv geo blocks via DNS proxies
  7.   I have this saved as ufctv in a bin dir on my $PATH, so I can call it from wherever
  8.   To login, run: ufctv login
  9.   That will begin an interactive login prompt
  10.   The login details themselves aren’t saved, just the cookies for the session
  11.   And the active session is reset any time you login with the “Keep Me Signed In” box anywhere else
  12.   To get a video’s m3u8: ufctv m3u8 $UFCTV-URL
  13.   So for example if I want to go back and watch Belfort vs Hendo 3
  14.   % ufctv m3u8 //www.ufc.tv/video/belfort-vs-henderson-3
  15.   From there you an do what you wish with the m3u8!
  16.   You may wish to pipe the result direct to mpv (which lets you seek around and switch between qualities)
  17.   % ufctv m3u8 //www.ufc.tv/video/belfort-vs-henderson-3 | xargs mpv
  18.   Or start ripping with livestreamer
  19.   % ufctv m3u8 //www.ufc.tv/video/belfort-vs-henderson-3 | xargs -I M3U8 livestreamer hlsvariant://M3U8 best -o belf-vs-hend.ts
  20.   You can also rip the stream with ffmpeg, though I’ve found livestreamer does it a bit cleaner
  21.   You may also wish to expand the program to add commands to do this for you instead of via shell piping
  22. “””
  23. import argparse
  24. import getpass
  25. import json
  26. import os
  27. import pickle
  28. import re
  29. import subprocess
  30. import sys
  31. from requests import session
  32. def main():
  33.     parser = argparse.ArgumentParser(description=
  34.         “””
  35.         This is a command line tool to help enjoy quality UFC Fight Pass
  36.         content in an ethical manner that respects your freedoms
  37.         “””)
  38.     parser.add_argument(‘operation’,
  39.         choices=[‘login’, ‘m3u8’])
  40.     parser.add_argument(‘rest’, nargs=’*’)
  41.     args = parser.parse_args()
  42.     op = args.operation
  43.     if op == ‘login’:
  44.         return ufctv_login()
  45.     if len(args.rest) < 1:
  46.         print(“Missing argument: video_url”, file=sys.stderr)
  47.         return 1
  48.     vid_url = args.rest[0]
  49.     uri = get_m3u8(vid_url)
  50.     if uri is None:
  51.         return 2
  52.     if args.operation == ‘m3u8’:
  53.         print(uri)
  54.         return 0
  55. def fake_mobile_session():
  56.     with session() as c:
  57.         load_cookies(c)
  58.         c.headers.update({‘User-Agent’: (
  59.             “Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us)”
  60.             ” AppleWebKit/528.18 (KHTML, like Gecko)”
  61.             ” Version/4.0 Mobile/7A341 Safari/528.16″)})
  62.         return c
  63. def get_m3u8_by_id(session, vid_id):
  64.     puburi = “//www.ufc.tv/service/publishpoint?type=video&id={}&format=json”
  65.     r = session.get(puburi.format(vid_id))
  66.     stream_info = json.loads(r.text)
  67.     if ‘path’ not in stream_info:
  68.         return None
  69.     return stream_info[‘path’].replace(“_iphone”, “”)
  70. def get_m3u8(uri):
  71.     with fake_mobile_session() as c:
  72.         r = c.get(uri)
  73.         vid_id = find_video_id(r.text)
  74.         if vid_id is None:
  75.             print(“Failed to find video ID in page.”, file=sys.stderr)
  76.             return None
  77.         if not logged_in(r.text):
  78.             print(“Goof Alert: You are not logged in to UFC.TV”, file=sys.stderr)
  79.         if not video_allowed(r.text):
  80.             print(“Video is not available”, file=sys.stderr)
  81.             return None
  82.         res = get_m3u8_by_id(c, vid_id)
  83.         save_cookies(c)
  84.         return res
  85. ufctv_sesssion_path = os.path.expanduser(“~/.ufctv”)
  86. def save_cookies(session):
  87.     with open(ufctv_sesssion_path, ‘wb’) as f:
  88.         pickle.dump(session.cookies, f)
  89. def load_cookies(session):
  90.     if not os.path.isfile(ufctv_sesssion_path):
  91.         print(“No saved cookies file found — starting from scratch”, file=sys.stderr)
  92.         return
  93.     with open(ufctv_sesssion_path, ‘rb’) as f:
  94.         session.cookies.update(pickle.load(f))
  95. def video_allowed(page_html):
  96.     return ‘<div class=”noAccess”>’ not in page_html
  97. def logged_in(page_html):
  98.     return “Sign Out” in page_html
  99. def ufctv_login():
  100.     with fake_mobile_session() as c:
  101.         login(c)
  102.         save_cookies(c)
  103. def login(sesh):
  104.     username = input(“Please enter your ufc.tv username: “)
  105.     password = getpass.getpass(“Please enter your ufc.tv password: “)
  106.     longchoice = input(“Tick the ‘Keep Me Signed In’ box for a long lasting session? [y/n] “)
  107.     longsesh = ‘true’ if longchoice is ‘y’ else ‘false’
  108.     login = {
  109.         ‘username’: username,
  110.         ‘password’: password,
  111.         ‘cookielink’: longsesh
  112.     }
  113.     r = sesh.post(“//www.ufc.tv/secure/authenticate”, data=login)
  114.     if ‘loginsuccess’ not in r.text:
  115.         print(“Login failure — full response:\n{}\n”.format(r.text), file=sys.stderr)
  116.         return False
  117.     return True
  118. def find_video_id(page_html):
  119.     m = re.search(“rel=\”image_src\” href=\”.*?([0-9]+?)_.*?\.jpg\””, page_html)
  120.     if m is None:
  121.         return m
  122.     return m.group(1)
  123. if __name__ == “__main__”:
  124.     sys.exit(main())

Facebook: Xbmc Tips And tricks //www.facebook.com/groups/565124710285772/
VPN SETUP KODI: //vpn.kodi17.com
Forum: //xbmcm3u.com
kodi Evo Tech //www.youtube.com/channel/UCkfg9-oz3rqYVqnyRr7gHyQ
//Funkykitchengadgets.com
IPVanish VPN Link: //www.ipvanish.com/?a_aid=559b2ebabc791&a_bid=48f95966
Twitter: //twitter.com/Miniboxpro
//querisavines.com
Merica Build //kodinews.net/Plugins
Kodi UFC //kodiufc.com


Best Boxes for Kodi

kodi Officail Download //kodi.tv/download/


Facebook: Xbmc Tips And tricks     //www.facebook.com/groups/565124710285772/ VPN SETUP KODI: //vpn.kodi17.com Forum: //xbmcm3u.com kodi Evo Tech //kryptonkodi.com //www.youtube.com/channel/UCkfg9-oz3rqYVqnyRr7gHyQ //Funkykitchengadgets.com IPVanish VPN Link: //www.ipvanish.com/?a_aid=559b2ebabc791&a_bid=48f95966 kodi18 Twitter: //twitter.com/Miniboxpro //querisavines.com Merica Build Kodi UFC //kodiufc.com  
coromi52

Comments are closed.

Share
Published by
coromi52

Recent Posts

👉 KODI 18.3 ON FIRESTICK – HOW TO INSTALL TUTORIAL 100% SAFE INSTALL 2019 AUGUST UPDATE

KODI 18.3 fastest tutorial and safest install watch lots of content using xbmc now known as kodi which is published…

5 days ago

HOW TO JAILBREAK FIRESTICK ALL VERSIONS & INSTALL KODI 19 + BEST APPS AUGUST 2019 UPDATED SETUP

JAILBREAK FIRESTICK TUTORIAL - Instructions also Kodi will work on firestick very good! Today we are going to jailbreak firestick…

6 days ago

Kodi Kodi addons Repos Programs

Muy pronto les dare finalmente un Build Para siempre funcionando Este video lo dedico a PuertoRico

6 days ago

S10 plus Digital camera Check Video Pattern 4K 1080p Portrait Mode

Samsung Galaxy S10 plus Digital camera Check Video Pattern 4K 1080p Portrait Mode. Watch subsequent: Tremendous Gradual Movement S10 <a…

6 days ago

IKEA PAX Nook Wardrobe Meeting – IKEA PAX Nook Closet Assembling!

IKEA PAX Nook Wardrobe Meeting. Methods to assemble the Ikea PAX nook closet. In case you are brief on bed…

2 weeks ago

TERRARIUM TV !! IS BACK 2019 WITH BEST COPY VERSION TO DATE

TERRARIUM TV IS BACK 2019!! BEST CLONE COPY VERSION TO DATE. YOU CAN INSTALL THIS VERSION ON ALL DEVICES (more…)

2 weeks ago