Commit bdc67afa authored by Jonas's avatar Jonas

Init

parents
# Outils pour hts tvheadend
Quelques outils pour éviter des tâches rébarbatives lors de la
configuration de tvheadend.
## Outils
### FreeBoxTV importer
Importe les IPTVs free.fr sous forme de muxes dans tvheadend.
Exemple d'utilisation (voir --help pour plus d'options)
```
$ #Créer un network adapté
$ ./freeboxtv_importer.py --hts-network-create
$ #Lister les networks
$ ./freeboxtv_importer.py --hts-networks-list
bef9c65f200b2e3d0c1789eab3968124 (TNTnova)
3a400ad0a3c93d03e6050e7824a12532 (FreeBoxTV)
$ #Importer les chaines
$ ./freeboxtv_importer.py --hts-network-uuid 3a400ad0a3c93d03e6050e7824a12532
```
### FreeBoxTv assign number
Assigne les numéros de chaînes "free" à vos chaines tvheadend.
Exemple d'utilisation (voir --help pour plus d'options)
```
$ ./freeboxtv_assign_number.py
```
### Automatics xmltvids
Associe automatiquement les xmltvids (à lancer une fois xmltv configuré).
Exemple d'utilisation (voir --help pour plus d'options)
```
$ ./automatics_xmltvids.py
```
## Support
Gestionnaire de ticket gitlab ou irc (SnouF sur freenode, réculièrement sur
le [#mythtv-fr](http://mythtv-fr.org/forums/chat.php))
#!/usr/bin/env python
# -*- coding: utf8 -*-
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
import sys, re, argparse, requests, json
parser = argparse.ArgumentParser(description = 'Automatics xmltvids find for tvheadhend channel')
parser.add_argument('--hts-url', default = 'http://localhost:9981/', help = 'hts server url (default : http://localhost:9981/)')
parser.add_argument('--hts-user', default = 'admin', help = 'hts user (default admin)')
parser.add_argument('--hts-password', default = 'admin', help = 'hts password (default admin)')
args = parser.parse_args()
r = requests.post(
args.hts_url+'api/channel/grid',
auth=(args.hts_user, args.hts_password),
data={'limit':100000}
)
if r.ok :
channels = r.json()
else :
print 'Error: can\'t load channels list'
r = requests.get(
args.hts_url+'api/epggrab/channel/list',
auth=(args.hts_user, args.hts_password),
data={'limit':100000}
)
if r.ok :
xmltvids = r.json()
else :
print 'Error: can\'t load xmltvid list'
pattern = re.compile('^XMLTV: (.*) \([0-9A-Za-z\.]*\)$')
for ch in channels['entries'] :
if ch['epggrab'] :
print '%(name)s already have xmltvid, pass'%ch
else :
print 'Search xmltvid for %(name)s'%ch
found = False
for xmltvid in xmltvids['entries'] :
chan_name = pattern.search(xmltvid['val']).group(1)
if chan_name.lower() == ch['name'].lower() :
print " - found (%s)"%xmltvid['key']
found = True
r = requests.post(
args.hts_url+'api/idnode/save',
auth=(args.hts_user, args.hts_password),
data={
'node': json.dumps({
"epggrab":[xmltvid['key']],
"uuid":ch['uuid']
})
}
)
if r.ok :
print " - saved"
else :
print " - error"
if not found :
print " - no found"
#!/usr/bin/env python
# -*- coding: utf8 -*-
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
import sys, re, argparse, requests, json
parser = argparse.ArgumentParser(description = 'Assigne le numéro de cannel freeboxtv')
parser.add_argument('--hts-url', default = 'http://localhost:9981/', help = 'url vers le serveur hts (http://localhost:9981 par défaut)')
parser.add_argument('--hts-user', default = 'admin', help = 'nom d\'utilisateur hts (admin par défaut)')
parser.add_argument('--hts-password', default = 'admin', help = 'mot de passe hts (admin par défaut)')
parser.add_argument('--playlist-url', default = 'http://mafreebox.freebox.fr/freeboxtv/playlist.m3u', help = 'url vers la playlist (http://mafreebox.freebox.fr/freeboxtv/playlist.m3u par défaut)')
args = parser.parse_args()
pattern = re.compile("^#EXTINF:0,([0-9]+) - (.*) \(.*\)$")
m3u = {}
r = requests.get(args.playlist_url)
if r.ok :
for l in r.iter_lines() :
if l.startswith('#EXTINF'):
match = pattern.search(l)
elif l.startswith('rtsp'):
m3u[match.group(2).lower()] = match.group(1)
else :
print "Erreur, le téléchargement de la playlist a échoué"
sys.exit(1)
r = requests.post(
args.hts_url+'/api/channel/grid',
auth=(args.hts_user, args.hts_password),
data={'limit':100000}
)
if r.ok :
print r.json()
for chan in r.json()['entries'] :
print 'Recherche no de %s'%chan['name']
if m3u.has_key(chan['name'].lower()) :
print ' - %s'%m3u[chan['name'].lower()]
r = requests.post(
args.hts_url+'/api/idnode/save',
auth=(args.hts_user, args.hts_password),
data={
'node': json.dumps({
"number":m3u[chan['name'].lower()],
"uuid":chan['uuid']
})
}
)
if r.ok :
print ' - sauver'
else :
print ' - erreur'
else :
print ' - no found'
else :
print "Erreur, le téléchargement de la liste de chaînes a échoué"
#!/usr/bin/env python
# -*- coding: utf8 -*-
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
import sys, re, argparse, requests, json
parser = argparse.ArgumentParser(description = 'Importe les freeboxtv dans tvheadend')
parser.add_argument('--hts-url', default = 'http://localhost:9981/', help = 'url vers le serveur hts (http://localhost:9981 par défaut)')
parser.add_argument('--hts-user', default = 'admin', help = 'nom d\'utilisateur hts (admin par défaut)')
parser.add_argument('--hts-password', default = 'admin', help = 'mot de passe hts (admin par défaut)')
parser_grp_create = parser.add_argument_group('Création d\'un network')
parser_grp_create.add_argument('--hts-network-create', action = 'store_true')
parser_grp_create.add_argument('--hts-network-name', default = 'FreeBoxTV', help = 'Nom du netwoark à créer (FreeBoxTV par défaut)')
parser_grp_list = parser.add_argument_group('Liste des networks')
parser_grp_list.add_argument('--hts-networks-list', action = 'store_true')
parser_grp_m3uimport = parser.add_argument_group('Import des chaines')
parser_grp_m3uimport.add_argument('--hts-network-uuid', default = None, help = 'uuid du network (voir --hts-networks-list)')
parser_grp_m3uimport.add_argument('--playlist-url', default = 'http://mafreebox.freebox.fr/freeboxtv/playlist.m3u', help = 'url vers la playlist (http://mafreebox.freebox.fr/freeboxtv/playlist.m3u par défaut)')
parser_grp_m3uimport.add_argument('--prefered_quality', default = 'auto,HD,standard', help = 'Ordre de préférence des qualité de flux (auto,HD,standard par défaut)')
args = parser.parse_args()
if args.hts_network_create :
'''
Créer un "network"
'''
r = requests.post(
args.hts_url+'/api/mpegts/network/create',
auth=(args.hts_user, args.hts_password),
data={
"class":"iptv_network",
"conf":json.dumps({
"networkname":args.hts_network_name,
"autodiscovery":True,
"skipinitscan":True,
"sid_chnum":False,
"ignore_chnum":False,
"satip_source":0,
"max_streams":2,
"max_bandwidth":0,
"max_timeout":15,
"nid":0,
"idlescan":False,
"charset":"",
"localtime":False,
"priority":1,
"spriority":1
})
}
)
if r.ok :
print "Crée"
sys.exit(0)
else :
print "Erreur"
sys.exit(1)
if args.hts_networks_list :
'''
Lister les "networks"
'''
r = requests.get(args.hts_url+'api/mpegts/network/grid',auth=(args.hts_user, args.hts_password))
if r.ok :
for n in r.json()['entries'] :
if n.has_key("networkname") :
print "%(uuid)s (%(networkname)s)"%n
else :
print "%(uuid)s (N/A)"%n
sys.exit(0)
else :
print "Erreur"
sys.exit(1)
if args.hts_network_uuid :
'''
Import m3u
'''
def is_prefered_quality (quality) :
if not m3u.has_key(match.group(1)) :
return True
if not m3u[match.group(1)]['quality'] in prefered_quality :
return True
if not quality in prefered_quality :
return False
if prefered_quality.index(quality) < prefered_quality.index(m3u[match.group(1)]['quality']) :
return True
prefered_quality = args.prefered_quality.split(',')
pattern = re.compile("^#EXTINF:0,([0-9]+) - (.*) \((.*)\)$")
m3u = {}
r = requests.get(args.playlist_url)
if r.ok :
for l in r.iter_lines() :
if l.startswith('#EXTINF'):
match = pattern.search(l)
elif l.startswith('rtsp'):
if is_prefered_quality(match.group(3)) :
print "ok"
m3u[match.group(1)] = {
'num': match.group(1),
'name': match.group(2),
'quality': match.group(3),
'url': l
}
else :
print "Erreur, le téléchargement de la playlist a échoué"
sys.exit(1)
for ch in m3u.values() :
print 'Création du mux %(name)s (url : %(url)s, qualité %(quality)s)'%ch
r = requests.post(
args.hts_url+'/api/mpegts/network/mux_create',
auth=(args.hts_user, args.hts_password),
data={
"uuid":args.hts_network_uuid,
"conf":json.dumps({
"enabled":True,
"epg":1,
"scan_state":0,
"pmt_06_ac3":0,
"iptv_url":ch['url'],
"iptv_interface":"",
"iptv_atsc":False,
"iptv_muxname":ch['name'],
"iptv_sname":ch['name'],
"charset":"",
"priority":0,
"spriority":0,
"iptv_respawn":True,
"iptv_env":""
})
}
)
if not r.ok :
print "Attention, la création du mux a échoué"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment