Comme promis un script python pour appeler sfr-tv en dehors de firefox
Auparavant, il faut installer des modules pythons
sudo apt-get install python-mechanize
sudo apt-get install python-wxgtk2.8
Il en manque peut-être encore.
Puis il faut ouvrir un fichier texte (gedit par exemple) qui a pour nom "sfr-tv"
copier coller le code à la fin de ce message et sauver le fichier.
Modifiez les droits pour pouvoir l’exécuter avec
chmod +x sfr-tv
puis lancer le script avec
./sfr-tv
Le programme vous demande alors le login et le mot de passe python.
Vous avez la liste des chaines disponibles.
Vous en sélectionnez une et elle se lance dans l'application vlc (l'application qui se trouve dans /opt/vlcsfr/bin) (voir mon post précédent)
Attention, le programme ne gère pas le cas ou vous vous trompez de login et ou mot de passe.
Vous pouvez modifier le programme pour ne pas avoir a taper le login et le mot de passe à chaque fois. Par contre ce n'est pas très safe.
Ca fonctionne chez moi.
C'est une interface vraiment minimaliste, mais libre à vous de la compléter.
Tenez-moi au courant.
#!/usr/bin/python
import mechanize
import urllib, urllib2, cookielib
import os
import getpass
import HTMLParser
from wxPython.wx import *
def choixChaine():
sfrchaines = ['tf1', 'france_2', 'france_3', 'france_5', 'm6', 'arte', 'direct_8', 'w9', 'tmc', 'nt1', 'nrj12', 'lcpan', 'france_4', 'bfm_tv', 'gulli', 'france_o', 'equipe_tv', '6ter', 'numero_23', 'rmc_decouverte', 'cherie_25', 'paris_premiere', 'teva', 'game_one', 'tv5_monde', 'france_24', 'bfm_business', 'lcpan_2424', 'public_senat', 'equidia', 'equidia_life', 'm6_boutique_and_co', 'best_of_shopping', 'disney_channel', 'disney_channel_plus_1', 'm6_music_hits', 'nrj_hits', 'clubbing_tv', 'ofive_tv', 'no_life', 'ma_chaine_etudiante', 'mens_up_tv', 'lucky_jack', 'poker_channel', 'astrocenter_tv', 'tna', 'fashion_tv', 'liberty_tv', 'kto', 'montagne_tv', 'france_24_en', 'cnbc', 'bloomberg', 'al_jazeera_eng', 'al_jazeera', 'france_24_ar', 'medi_1_sat', 'africa_24', 'guysen_tv', 'dw', 'france_3_alpes', 'france_3_alsace', 'france_3_aquitaine', 'france_3_auvergne', 'france_3_basse_normandie', 'france_3_bourgogne', 'france_3_bretagne', 'france_3_centre', 'france_3_champagne_ardenne', 'france_3_corse', 'france_3_cote_d_azur', 'france_3_franche_comte', 'france_3_haute_normandie', 'france_3_languedoc', 'france_3_limousin', 'france_3_lorraine', 'france_3_midi_pyrenees', 'france_3_nord_pas_de_calais', 'france_3_paris_idf', 'france_3_pays_de_la_loire', 'france_3_picardie', 'france_3_poitou_charentes', 'france_3_provences_alpes', 'france_3_rhones_alpes', 'noot_tv', 'tropik_tv', 'idf1', 'canal_21', 'la_locale', 'telif', 'telessone', 'tv_fil_78', 'teleplaisance', 'normandie_tv', 'alsatic_20', 'mirabelle_tv', 'weo', 'grand_lille_tv', 'calaisis_tv', 'telegrenoble_isere', 'tlm', 'tv8_mont_blanc', 'lcm', 'telemiroir', 'tv7_bordeaux', 'tvm_international', '2m_maroc', 'arryadia', 'arrabia', 'al_maghribia', 'assadissa', 'canal_algerie', 'beur_tv', 'tv7_tunisia', 'hannibal_tv', 'nessma', 'al_masraya', 'kuwait_tv', 'jordan_satellite_channel', 'ishtar_tv', 'dubai_tv', 'baraem', 'aljazeera_children', 'vox_africa', '3a_telesud', 'rtpi', 'record_news', 'euskal_telebista', 'ert_world', 'bnt_sat', 'rtcg_sat', 'tv_romania_international', 'tvp_info', 'rtr_planeta', 'armenia_tv', 'armenia_1', 'vtv4', 'cctv_f', 'cctv_news', 'zing']
nomchaines = ['TF1', 'France 2', 'France 3', 'France 5', 'M6', 'Arte', 'Direct 8', 'W9', 'TMC', 'NT1', 'NRJ12', 'LCP', 'France 4', 'BFM TV', 'Gulli', 'France \xc3\x94', "L'\xc3\xa9quipe 21", '6ter', 'Num\xc3\xa9ro 23', 'RMC D\xc3\xa9couverte', 'Ch\xc3\xa9rie 25', 'Paris Premi\xc3\xa8re', 'T\xc3\xa9va', 'Game One', 'TV5 Monde(France -Suisse-Belgique)', 'France 24', 'BFM Business', 'LCP-AN 24/24', 'Public S\xc3\xa9nat', 'Equidia Live', 'Equidia Life', 'M6 Boutique & Co', 'Best of Shopping', 'Disney Channel', 'Disney Channel +1', 'M6 Music', 'NRJ Hits', 'Clubbing TV', 'OFive.TV', 'No Life', 'Ma Chaine Etudiante', "Men's Up TV", 'Lucky Jack', 'The Player Channel', 'Astrocenter.tv', 'T\xc3\xa9l\xc3\xa9vision Num\xc3\xa9rique Alternative', 'Fashion TV', 'Liberty TV', 'KTO', 'MontagneTV', 'France 24 (Anglais)', 'CNBC Europe', 'Bloomberg Pan-European', 'Al Jazeera English', 'Al Jazeera', 'France 24 (Arabe)', 'Medi 1 Sat', 'Africa 24', 'Guysen TV', 'Deutsche Welle', 'France 3 - Alpes', 'France 3 - Alsace', 'France 3 - Aquitaine', 'France 3 - Auvergne', 'France 3 - Basse-Normandie', 'France 3 - Bourgogne', 'France 3 - Bretagne', 'France 3 - Centre', 'France 3 - Champagne-Ardenne', 'France 3 - Corse', "France 3 - C\xc3\xb4te d'Azur", 'France 3 - Franche-Comt\xc3\xa9', 'France 3 - Haute-Normandie', 'France 3 - Languedoc', 'France 3 - Limousin', 'France 3 - Lorraine', 'France 3 - Midi-Pyr\xc3\xa9n\xc3\xa9es', 'France 3 - Nord-Pas-de-Calais', 'France 3 - Paris IDF', 'France 3 - Pays de la Loire', 'France 3 - Picardie', 'France 3 - Poitou-Charentes', 'France 3 - Provence-Alpes', 'France 3 - Rh\xc3\xb4ne-Alpes', 'Noot TV', 'Tropik TV', 'IDF1', 'Canal 21', 'La Locale', 'T\xc3\xa9lif', 'T\xc3\xa9l\xc3\xa9ssonne', 'TV Fil 78', 'T\xc3\xa9l\xc3\xa9Plaisance', 'Normandie TV', 'Alsatic 20', 'Mirabelle TV', 'Weo', 'Grand Lille TV', 'Calaisis TV', 'T\xc3\xa9l\xc3\xa9Grenoble Is\xc3\xa8re', 'TLM', 'TV8 Mont-Blanc', 'LCM', 'TVSUD Camargues Cevennes', 'TV7 Bordeaux', 'Al Aoula', '2M Maroc', 'Arryadia', 'Arrabi\xc3\xa2', 'Al Maghribia', 'Assadissa', 'Canal Alg\xc3\xa9rie', 'Beur FM TV', 'T\xc3\xa9l\xc3\xa9vision Nationale Tunisienne', 'Hannibal TV', 'Nessma', 'Al Masriya', 'Kuwait TV', 'Jordan Satellite Channel', 'Ishtar TV', 'Duba\xc3\xaf TV', 'Baraem', 'Al Jazeera Children', 'Vox Africa', '3A T\xc3\xa9l\xc3\xa9sud', 'RTPI', 'Record News', 'Euskal Telebista', 'ERT World', 'BNT World', 'RTCG Sat', 'TV Romania International', 'TVP Info', 'RTR Planeta', 'Armenia TV', 'Armenia 1', 'VTV 4', 'CCTV-F', 'CCTV News', 'Zing']
application = wxPySimpleApp()
choices = nomchaines
dialog = wxSingleChoiceDialog ( None, 'Pick something....', 'Dialog Title', choices )
if dialog.ShowModal() == wxID_OK:
print 'Position of selection:', dialog.GetSelection()
print 'Selection:', dialog.GetStringSelection()
print 'chaine:', sfrchaines[dialog.GetSelection()]
# The user exited the dialog without pressing the "OK" button
name = sfrchaines[dialog.GetSelection()]
else:
name = ""
print 'You did not select anything.'
dialog.Destroy()
return name
class LinksParser(HTMLParser.HTMLParser):
def __init__(self):
HTMLParser.HTMLParser.__init__(self)
self.recording = 0
self.data = []
def handle_starttag(self, tag, attributes):
if tag != 'div':
return
if self.recording:
self.recording += 1
return
for name, value in attributes:
if name == 'id' and value == 'remository':
break
else:
return
self.recording = 1
def handle_endtag(self, tag):
if tag == 'div' and self.recording:
self.recording -= 1
def handle_data(self, data):
if self.recording:
self.data.append(data)
# Browser
username = raw_input('login sfr :')
password = getpass.getpass('mot de passe sfr :')
br = mechanize.Browser()
# Cookie Jar
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)
# Browser options
br.set_handle_equiv(True)
br.set_handle_gzip(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)
# Follows refresh 0 but not hangs on refresh > 0
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
# Open some site, let's pick a random one, the first that pops in mind:
r = br.open('https://www.sfr.fr/cas/login')
html = r.read()
# Select the first (index zero) form
br.select_form(nr=0)
# Let's search
br.form['username']=username
br.form['password']=password
br.submit()
br.open('http://tv.sfr.fr/television-sur-ordinateur-par-internet/tf1/#sfrintid=P_nav_tv-vod_tv-pc&sfrclicid=P_nav_tv-vod_tv-pc');
name= br.response().read()
p=LinksParser()
p.feed(name)
while True:
reponse=choixChaine()
if reponse=="":
break
br.open('http://tv.sfr.fr/callback/tvpc/flux.php?chaine='+reponse)
name= br.response().read()
cmd='/opt/vlcsfr/bin/vlc "'+ name+ '"'+" --volume 0"
os.system(cmd)