Major League Gaming is an online broadcast network that regularly hosts professional gaming tournaments. While Twitch.tv is still considered the largest streaming network for gamers, MLG has many popular streamers and professional gamers who only broadcast on their network. Many huge tournaments from major gaming titles such as Call of Duty and Counter-Strike: Global Offensive are streamed exclusively on MLG.
Similar to most streaming services, you may experience lag while watching live streams. The solution to this problem is to use a useful utility called livestreamer. This command-line tool helps alleviate a lot of lag you may experience while watching streams. It requires less resources and bandwidth than watching live streams on MLG.tv.
Livestreamer has many powerful options. It can be used to watch streams directly with your personal media player. Livestreamer supports most streaming protocols that are used today. It can access streaming protocols directly instead of relying on plugins to extract streams from URLs. In addition, livestreamer can download and record live streams or videos. All these powerful options can be further enhanced by combining livestreamer with scripts.
Scripts can help automate the entire process and limit the amount of user input needed. You can find direct links automatically and remove the need to manually search for stream links. An entirely automated script can search for streams, determine whether streams are online or offline, and download live streams directly to your computer. This is all made possible by utilizing livestreamer’s impressive tool and plugin system.
- How to Watch/Record Twitch Streams using Livestreamer
- How to Automatically Record Twitch Streams with a Script
What is Livestreamer and why use it?
Livestreamer is a command-line utility that allows you to pipe video streams directly into your personal media player. Livestreamer is a cross platform utility and works with Windows, Mac, and Linux systems. Livestreamer works best with VLC Media Player, which is also cross platform, but many other players are compatible too.
Livestreamer is a useful utility for many people. If you noticed lag or stream stuttering while watching streams on MLG.tv, then consider using livestreamer. It helps alleviate lag and will provide a smoother experience. An additional benefit is livestreamer’s ability to bypass advertisements.
Avoid Lag and Stream Stuttering
Perhaps the main reason to use livestreamer is to avoid lag and stream stuttering. The cause of stream stuttering or video lag can be caused by any number of issues. It could be due to a slow internet connection, your personal computer lagging, or your connection to the streaming server is slow.
Using livestreamer will solve most of these problems. Livestreamer does not use any web plugins such as Java or Adobe Flash Player, instead it connects directly to the stream source. This minimizes the amount of stress on your computer, which allows your computer to run smoother. Livestreamer can be configured to transmit lower quality streams to ensure you don’t exceed your internet bandwidth. You can find the most appropriate speed to match your household’s internet usage and provide the best internet experience.
The wonderful thing about livestreamer is its ability to bypass advertisements. Although it wasn’t meant to circumvent advertisements, it does have the ability to do so. It prevents advertisements from being displayed on livestreams because it transmits only the stream source to your media player. However, advertisements that are displayed by the streamer during live broadcasts will still be shown.
How to watch MLG streams with livestreamer
Once everything is installed correctly, using livestreamer is really easy. All it takes is a few simple steps.
- On Windows, open the run dialog by pressing “Windows Key + R” or open Command Prompt.
- On Mac OS X, open the terminal by pressing ⌘ + Space, type “Terminal” and then hit “Enter”.
- For Linux users, open the terminal (the shortcut or hotkey may differ between linux distros).
The command to run livestreamer is the same for all three operating systems. Type the following command and livestreamer should run smoothly.
livestreamer mlg.tv/stream_name best
Change the stream name and/or parameter to the stream and quality you want. If you have a slow internet connection, you may want to lower the quality.
livestreamer mlg.tv/stream_name high
livestreamer mlg.tv/stream_name medium
livestreamer mlg.tv/stream_name low
livestreamer mlg.tv/stream_name mobile
I recommend watching at the highest quality for the best experience, but if you encounter any lag then adjust accordingly.
How to find MLG stream source (HDS)
In some situations, the MLG plugin for livestreamer may not work. It can be due to an outdated plugin or livestreamer is unable to find a direct link to MLG.tv. If the mlg.tv plugin no longer works and it displays “No streams found on this URL” even if the stream is online, then you will have to manually provide a direct link for livestreamer.
Livestreamer supports the following streaming protocols. In our case, we want to use the Adobe HTTP Dynamic Streaming (HDS) protocol. The Apple HTTP Live Streaming (HLS) protocol also works, but we will use HDS. Here is a full list of streaming protocols that livestreamer supports.
Supported streaming protocols
|Adobe HTTP Dynamic Streaming||hds://|
|Akamai HD Adaptive Streaming||akamaihd://|
|Apple HTTP Live Streaming||hls:// hlsvariant://|
|Real Time Messaging Protocol||rtmp:// rtmpe:// rtmps:// rtmpt:// rtmpte://|
|Progressive HTTP, HTTPS, etc||httpstream://|
Finding the direct link is quite tricky, but here is an easy way to find it. First, you have to be able to recognize the MLG URL. It looks something like this: mlghds-lh.akamaihd.net
Go to the link below and change “STREAM_NAME” to the stream name you want.
- There will be two URLs. You want the HDS URL that ends with manifest.f4m
- Copy the URL and Replace http:// with hds://
Instead of using the standard MLG URL, run livestreamer with the newly acquired link.
livestreamer hds://mlghds-lh.akamaihd.net/z/mlg141_1@60106/manifest.f4m best
Modify the HDS URL and quality, then run the command. Livestreamer should find the stream and start as it normally would.
This method requires finding the direct link for MLG.tv by using your browsers developer tools. Whether you are on Mozilla Firefox or Google Chrome, you can access your developer’s tool by pressing F12.
- Go to MLG.tv and find the channel you want to watch with livestreamer
- Press F12 and click on the Network Tab
- Within the tab, click on Filter
- Search for Manifest.f4m
- Right click and Copy the URL
You should end up with a URL that looks similar to the one above. Now you have to modify the URL and make it readable for livestreamer.
6. Replace http:// with hds://
7. Delete everything after manifest.f4m
The new URL should look something like this:
Now that the link is all cleaned up, you can run livestreamer.
livestreamer hds://mlghds-lh.akamaihd.net/z/mlg396_1@126582/manifest.f4m best
Modify the link and stream quality accordingly. Livestreamer should find the stream source and launch as it normally would.
How to find MLG stream source (HDS) automatically
If you don’t want to go through all the trouble of manually finding the HDS link, there is an automated way to find it. This short python script only requires a channel name and will provide you with a direct HDS link.
Copy the script and name it FindHDS with .py as the file extension.
from urllib.request import urlopen from urllib.error import URLError import json def parseData(user): url_all = 'http://www.majorleaguegaming.com/api/channels/all.js?fields=slug,stream_name' dataset = json.loads(urlopen(url_all, timeout = 15).read().decode('utf-8')) counter = 0 while (counter < len(dataset['data']['items'])-1): counter = counter + 1 slug = dataset['data']['items'][counter]['slug'] stream_id = dataset['data']['items'][counter]['stream_name'] if (slug == user or stream_id == user): stream_name = stream_id return stream_name return False def main(): user = input("Enter Stream Name: ") if (parseData(user) == False): print("Stream is either offline or does not exist.") else: stream_name = parseData(user) url = "http://streamapi.majorleaguegaming.com/service/streams/playback/%s?format=all" % stream_name info = json.loads(urlopen(url, timeout = 15).read().decode('utf-8')) hdsurl = "hds://" + info['data']['items']['url'] print(hdsurl) exitkey = input('Press any key to exit...') if __name__ == "__main__": # execute only if run as a script main()
The link is automatically cleaned up and correctly formatted. Now run livestreamer as you normally would.
livestreamer hds://mlghds-lh.akamaihd.net/z/mlg396_1@126582/manifest.f4m best
How to Record/Capture MLG streams with VLC Player
- Launch VLC Media Player through livestreamer
- Click on the View Tab and select Advanced Controls
- Now advanced controls should pop up at the bottom of the player
- Clicking the red button will record videos
After enabling advanced controls a red button located at the bottom left should pop-up.
It’s simple, click the button and the recording will start, click it again and it will stop.
Changing Recording Directory
You may want to change the recording directory. Here is how to do it.
- Go to Tools -> Preferences -> Input / Codecs
- Under Files -> “Record directory or filename“
- Click Browse and change directories
How to Download MLG streams with Livestreamer
Livestreamer has a built-in parameter to download livestreams. Run livestreamer as you normally would by opening the Run Dialog. Add the download parameter and specify the download location.
- On Windows: Press “Windows Key + R” to open the Run Dialog.
- On Mac OS X: Press ⌘ + Space, type “Terminal” and then hit “Enter”.
- On Linux: open the terminal (the shortcut or hotkey may differ between linux distros).
Next, type in the following command to begin downloading with livestreamer.
livestreamer "MLG URL" best -o "C:\filename.mp4"
- Replace “MLG URL” with mlg.tv stream url
- Modify the directory and/or filename
If the standard MLG.tv link does not work, try using the direct MLG link (HDS).
How to automatically Record/Download MLG streams
Automatically recording and downloading MLG streams is a great way to watch streams at a later date. When compared to Twitch, MLG does not have a good system to save past broadcasts. Most of the time, past broadcasts are not available and MLG only replays broadcasts at certain times.
It is much better to save past broadcasts or VODs directly to your computer and watch it later. The problem is, many times you do not know when a stream is going online. By running this script, you can automatically check whether a stream is live and download the stream directly to your computer.
Copy the script and name it MLGRecorder with .py as the file extension.
from urllib.request import urlopen from urllib.error import URLError from threading import Timer import time import json import sys import subprocess import datetime # returns 0: online, 1: offline, 2: not found, 3: error def check_user(stream_name): url_status = 'http://streamapi.majorleaguegaming.com/service/streams/status/' + stream_name try: info = json.loads(urlopen(url_status, timeout = 15).read().decode('utf-8')) # MLG streams have 3 statuses: -1 = Offline, 1 = Online, 0 = Rebroadcast if info['data']['status'] == -1: status = 1 else: status = 0 except URLError as e: if e.reason == 'Not Found' or e.reason == 'Unprocessable Entity': status = 2 else: status = 3 return status def parseData(user): url_all = 'http://www.majorleaguegaming.com/api/channels/all.js?fields=slug,stream_name,subtitle' dataset = json.loads(urlopen(url_all, timeout = 15).read().decode('utf-8')) # This loop checks whether the user exists # "len(dataset['data']['items'])" is the size of the array counter = 0 while (counter < len(dataset['data']['items'])-1): counter = counter + 1 slug = dataset['data']['items'][counter]['slug'] stream_id = dataset['data']['items'][counter]['stream_name'] subtitle = dataset['data']['items'][counter]['subtitle'] # This if statement checks whether the user exists # If the user exists, it returns three values if (slug == user or stream_id == user): stream_name = stream_id stream_title = subtitle slug_name = slug return stream_name, stream_title, slug_name return False def format_filename(fname): # Removes invalid characters from filename fname = fname.replace("/","") fname = fname.replace("?","") fname = fname.replace(":","-") fname = fname.replace("\\","") fname = fname.replace("<","") fname = fname.replace(">","") fname = fname.replace("*","") fname = fname.replace("\"","") fname = fname.replace("|","") return fname def loopcheck(): while True: status = check_user(stream_name) if status == 2: print("username not found. invalid username?") elif status == 3: print(datetime.datetime.now().strftime("%Hh%Mm%Ss")," ","unexpected error. will try again in 5 minutes.") time.sleep(300) elif status == 1: print(user,"currently offline, checking again in",refresh,"seconds") time.sleep(refresh) # 30 seconds elif status == 0: print(user,"online. stop.") filename = slug_name +" - "+datetime.datetime.now().strftime("%Y-%m-%d %Hh%Mm%Ss")+" - " + stream_title + ".mp4" filename = format_filename(filename) subprocess.call(["livestreamer","mlg.tv/"+slug_name,quality,"-o",directory+filename]) print("Stream is done. Going back to checking..") time.sleep(15) def main(): global user global stream_name, stream_title, slug_name global refresh global quality global directory refresh = 30.0 user = "" quality = "" directory = "C:\\" if not user or not quality: # refresh = input('Enter the refresh rate: ') user = input('Enter the stream name: ') quality = input('Enter the quality (best, high, medium, low): ') # directory = input('Enter the directory: ') if(refresh<15): print("Check interval should not be lower than 15 seconds") refresh=15 parseData(user) if (parseData(user) == False): print("Username not found.") else: stream_name, stream_title, slug_name = parseData(user) print("Checking for",user,"every",refresh,"seconds. Record with",quality,"quality.") loopcheck() if __name__ == "__main__": # execute only if run as a script main()
When you run this script, it will automatically check for live MLG streams. If the stream is live, it will record or download the stream until it goes offline. The script can run forever or until you turn your computer off.
Configuring MLGRecorder.py script
The script is designed to minimize user input. However, there are four variables within the script that needs to be modified. If you choose not to enter any variables, the default values will be preserved and additional user input will be required each time you run the script. The four variables are refresh, user, quality, and directory.
Refresh: The refresh is the number of seconds before MLGRecorder.py checks whether a stream is online or offline. The default value is 30.0 seconds. You can increase or decrease the value (in seconds), but the check interval should not be lower than 15 seconds.
User: Enter the name of the channel you wish to check. MLGRecorder.py will check whether the user exists and whether the user is online or offline. Make sure the username is inside the quotes.
Quality: Here is where you configure the quality of the stream. The quality options are best, high, medium, and low. Again, make sure the quality option is inside the quotes.
Directory: The directory is where you save your downloaded or recorded files. Make sure the directory is valid and within the quotes. The directory requires two backslashes (\\), instead of a single backslash.
How to Run Python Scripts
There are two ways to run python scripts. You can run the script through Python’s IDLE (Integrated Development Environment) or run it using python.exe.
Running on IDLE
- Open the script with IDLE
- Click Run
- Click Run Module or Press F5
If you run into any problems, make sure you have the correct version of Python installed. If Python 3.4 is installed correctly, then make sure the script is properly indented.
Running on Python.exe
Double click the file and the script will run. You may need to set python.exe to open by default.
To set as default application:
- Right click script -> Open With -> Choose Default Program
- Browse for Python.exe. It should be located in C:\Python34
After you set the python as the default application, all you need to do is double click the file.