putlocker-vlc

Tired of watching online videos from PutLocker and SockShare in a Flash player? Use this script to play them in VLC Media Player. Will parse the URL, figure out where the video file is located, and start VLC Media Player, playing the right stream automatically. Requires mechanize.

Installation instructions

On Linux, save the script as /bin/putlocker-vlc. On Windows, just put the script in a folder somewhere where you will run it later (proper functioning on Windows is not guaranteed).

Usage instructions

Linux

putlocker-vlc accepts the URL of the video as the first parameter when running it. Example:

putlocker-vlc http://www.putlocker.com/file/D8E5A094E5F59F4D

Since putlocker-vlc runs VLC with the play-and-exit parameter, it's possible to chain together multiple putlocker-vlc commands to create a playlist of sorts. Example:

putlocker-vlc http://www.putlocker.com/file/D8E5A094E5F59F4D && putlocker-vlc http://www.sockshare.com/file/88DF2133C85521BD

Windows

You need Python.

Instructions for installing mechanize on windows can be found here you may need to run the script they point you to at the command line to ensure it installs for the same version of python as you will use later to run the putlocker-vlc.py script. Rather than just double clicking it.

I created a modified version of the script to use the registry to find where VLC is installed as this was what was preventing it working if you use the original version. So the easiest way to get it work is to download the windows edition which can be found at the bottom of the page.

To run it type something like this at the command line:

python putlocker-vlc.py http://www.putlocker.com/file/D8E5A094E5F59F4D

If windows does not recognise python as a command you need to add the python folder to the PATH environment variable or run it using something more like this:

c:\python27\python.exe putlocker-vlc.py http://www.putlocker.com/file/D8E5A094E5F59F4D

Since putlocker-vlc runs VLC with the play-and-exit parameter, it's possible to chain together multiple putlocker-vlc commands to create a playlist of sorts. Example:

python putlocker-vlc http://www.putlocker.com/file/D8E5A094E5F59F4D & python putlocker-vlc http://www.sockshare.com/file/88DF2133C85521BD

Note the use of & to chain commands not && this is because && performs error checking and so may never run commands to the right whereas & will chain all commands regardless of whether the previous one was successful.

The script

putlocker-vlc.py
#!/usr/bin/python
 
import re, mechanize, subprocess, sys
 
if len(sys.argv) < 2:
	print "Syntax: putlocker-vlc <putlocker/sockshare url>"
	sys.exit(1)
 
url = sys.argv[1]
matches = re.search("\/(file|embed)\/([A-Z0-9]+)", url)
 
if matches is None:
	print "The URL you provided does not appear to be a valid PutLocker or SockShare URL."
	sys.exit(1)
 
video_id = matches.group(2)
matches = re.search("(http:\/\/[^/]+)\/", url)
domain = matches.group(1)
print "Video ID: %s | Host: %s" % (video_id, domain)
 
try:
	print "Retrieving ad page..."
	browser = mechanize.Browser()
	browser.set_handle_robots(False)
	browser.open("%s/embed/%s" % (domain, video_id))
except:
	print "Something went wrong; the server might be down."
	sys.exit(1)
 
try:
	print "Skipping ad..."
	browser.select_form(nr=0)
	result = browser.submit()
except:
	print "The file has been removed, or the URL is incorrect."
	sys.exit(1)
 
matches = re.search("playlist: '([^']+)'", result.read())
playlist = matches.group(1)
print "Retrieved playlist URL."
 
browser.open(domain + playlist)
print "Retrieved playlist data."
matches = re.search("url=\"([^\"]+)\" type=\"video\/x-flv\"", browser.response().read())
video_file = matches.group(1)
video_file = video_file.replace("&amp;", "&")
print "Found video URL."
 
print "Launching VLC with the specified video file..."
cmd = ["vlc", "--play-and-exit"]
cmd.append(video_file)
subprocess.call(cmd)

The script (Windows Edition)

putlocker-vlc.py
#!/usr/bin/python
 
import re, mechanize, subprocess, sys, _winreg, platform
 
def getVLCPath():
	if platform.architecture()[0] == '64bit':
		regPath = "Software\\Wow6432Node\\VideoLAN\\VLC"
	else:
		regPath = "Software\\VideoLAN\\VLC"
 
	key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, regPath)
	value = _winreg.QueryValue(key, "")
	_winreg.CloseKey(key)
	return value
 
if len(sys.argv) < 2:
	print "Syntax: putlocker-vlc <putlocker/sockshare url>"
	sys.exit(1)
 
url = sys.argv[1]
matches = re.search("\/(file|embed)\/([A-Z0-9]+)", url)
 
if matches is None:
	print "The URL you provided does not appear to be a valid PutLocker or SockShare URL."
	sys.exit(1)
 
video_id = matches.group(2)
matches = re.search("(http:\/\/[^/]+)\/", url)
domain = matches.group(1)
print "Video ID: %s | Host: %s" % (video_id, domain)
 
try:
	print "Retrieving ad page..."
	browser = mechanize.Browser()
	browser.set_handle_robots(False)
	browser.open("%s/embed/%s" % (domain, video_id))
except:
	print "Something went wrong; the server might be down."
	sys.exit(1)
 
try:
	print "Skipping ad..."
	browser.select_form(nr=0)
	result = browser.submit()
except:
	print "The file has been removed, or the URL is incorrect."
	sys.exit(1)
 
matches = re.search("playlist: '([^']+)'", result.read())
playlist = matches.group(1)
print "Retrieved playlist URL."
 
browser.open(domain + playlist)
print "Retrieved playlist data."
matches = re.search("url=\"([^\"]+)\" type=\"video\/x-flv\"", browser.response().read())
video_file = matches.group(1)
video_file = video_file.replace("&amp;", "&")
print "Found video URL."
 
print "Launching VLC with the specified video file..."
cmd = getVLCPath() + " --play-and-exit " + video_file
subprocess.call(cmd)
projects/putlocker-vlc.txt · Last modified: 2013/12/28 14:38 by bananaman42
Back to top
CC Attribution 3.0 Unported
Donate Valid CSS Driven by DokuWiki Recent changes RSS feed Valid XHTML 1.0