Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
TVHeadend tv_grab_url - with automatic setup script for Linux Newbies.
#!/usr/bin/env python
# coding=utf-8
import os
import sys,stat
import urllib2
installto = "/usr/bin/tv_grab_url"
def replace_line(file_name, line_num, text):
#Stolen from
lines = open(file_name, 'r').readlines()
lines[line_num] = text
out = open(file_name, 'w')
if not os.geteuid() == 0:
sys.exit('Script must be run as root')
content = urllib2.urlopen('').read()
save = open(installto, "wb")
st = os.stat(installto)
os.chmod(installto, 0o777) #st.st_mode | stat.S_IEXEC
url = raw_input('Hi, and welcome to this super simple install script!\nThanks for choosing my script.\n\nThe script has been installed here '+installto+'\n\nLets configure it! Just fill in your XMLTV url below. Don\'t worry about whitespaces in front or behind the url. I\'ll strip them away :)\n\nPlease enter your XMLTV url: ')
replace_line(installto, 6, 'url = "'+url.strip()+'"\n')
os.system("/etc/init.d/tvheadend restart")
print "\n\nNow, go to your TVHeadend webgui. Configuration -> XMLTV.\nSelect \"tv_grab_url is a simple python version of the tv_gra...\", and check the checkbox Enable grabbing. Press Save Configuration and that's it!"
print "\nTo link your channels to the XMLTV, go to Configuration -> Channels. Change the dropbox 'XMLTV source' of each channel to the correct one. Press save."
Please note, the following requires wget and python, you can get those with: apt-get install wget python
Do it automaticly (Ubuntu and systems with sudo):
wget -qO && sudo python && rm
Do it automaticly alternative (No sudo? No problem, just make sure you're root.):
wget -qO && python && rm
Manual install and config:
wget -qO /usr/bin/tv_grab_url && chmod +x /usr/bin/tv_grab_url && nano +7 /usr/bin/tv_grab_url && /etc/init.d/tvheadend restart
#!/usr/bin/env python
# coding=utf-8
# Copyright Mathias F. Svendsen -
#Configuration zone start
url = "" #EDIT ME
#Configuration zone end - Do not edit anything below here unless you know what you're doing.
from optparse import OptionParser
import urllib2
parser = OptionParser(version="%prog 1.0b")
parser.add_option("-u", "--url", dest="url", help="Overwrite the hardcoded URL string.", metavar="URL", default=url)
parser.add_option("-d","--description", action="store_true",dest="description",default=False, help="Prints the description of this script")
parser.add_option("-c","--capabilities", dest="capabilities", action="store_true" ,help="Not sure what this is - but saw it in tv_grab_file.", default=False)
(options, args) = parser.parse_args()
if options.description is False and options.capabilities is False:
print urllib2.urlopen(options.url).read()
elif options.description is True:
print "tv_grab_url is a simple python version of the tv_grab_file, but instead of using a file, it downloads from an user specified XMLTV link."
elif options.capabilities is True:
print "baseline"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.