class emissionrtl(emission): def __init__(self, name, idpod, rtl2=False): podcasturl = "https://www.rtl.fr/podcast/" + idpod + ".xml" if rtl2: podcasturl = "https://www.rtl2.fr/podcast/" + idpod + ".xml" emission.__init__(self, name, podcasturl, idpod) rtlfr = stationrtl("RTL France", "rtlfr", "https://www.rtl.fr/recherche?type=emission&query=", "https://radio.rtl.fr/rtl.pls", '.show figure a.post-link', True) rtl2fr = stationrtl("RTL2 France", "rtl2fr", "https://www.rtl2.fr/radio/podcasts.html#", "https://streaming.radio.rtl2.fr/rtl2-1-44-128", '.common h3', ".common .rss") funradiofr = station("Fun Radio Fr.", "funradiofr", "https://www.funradio.fr/", "https://streaming.radio.funradio.fr:80/fun-1-44-128", True) belrtlbe = station("BelRTL Belgique", "belrtlbe", "https://www.rtl.be/belrtl/", "https://icy.rtl.nl/belrtl128", True) radiocontactbe = station("Radio Contact Belgique", "radiocontactbe", "https://fr.radiocontact.be/", "https://icy.rtl.nl/contactfr.m3u", True) mintbe = station("Mint", "mintbe", "https://www.mint.be/", "https://icy.rtl.nl/mint.m3u", True) RTL = stationgroup( "RTL", [rtlfr, rtl2fr, funradiofr, belrtlbe, radiocontactbe, mintbe])
x.add_row([ii, e['title'], e['updated'], e['link']]) print(x) def playpodcast(self, Tid): d = feedparser.parse(self.podurl) urltoplay = str(d['entries'][Tid]["link"]) print("mplayer %s" % urltoplay) subprocess.call(["mplayer", urltoplay]) bbc1 = stationbbc('bbc 1', 'bbc1', "radio1", "https://www.bbc.co.uk/radio/listen/live/r1_aaclca.pls", ".pc-result-heading a", ".pc-result-heading a") bbc2 = stationbbc('bbc 2', 'bbc2', "radio2", "https://www.bbc.co.uk/radio/listen/live/r2_aaclca.pls", ".pc-result-heading a", ".pc-result-heading a") bbc3 = stationbbc('bbc 3', 'bbc3', "radio3", "https://www.bbc.co.uk/radio/listen/live/r3_aaclca.pls", ".pc-result-heading a", ".pc-result-heading a") bbc4 = stationbbc('bbc 4', 'bbc4', "radio4", "https://www.bbc.co.uk/radio/listen/live/r4_aaclca.pls", ".pc-result-heading a", ".pc-result-heading a") bbc5 = stationbbc('bbc 5', 'bbc5', "5live", "https://www.bbc.co.uk/radio/listen/live/r5_aaclca.pls", ".pc-result-heading a", ".pc-result-heading a") bbc6 = stationbbc('bbc 6', 'bbc6', "6music", "https://www.bbc.co.uk/radio/listen/live/r6_aaclca.pls", ".pc-result-heading a", ".pc-result-heading a") BBC = stationgroup("BBC", [bbc1, bbc2, bbc3, bbc4, bbc5, bbc6])
import feedparser from lxml import etree,html from cssselect import GenericTranslator, SelectorError import re import subprocess from lib.base_podcast import emission, station, stationgroup from prettytable import PrettyTable import sqlite3 class stationvrt(station): def __init__(self,name,code,url,streamurl="",): station.__init__(self,name,code,url,streamurl,True) self.name=name self.code=code self.url=url self.streamurl=streamurl radio1 = stationvrt("Radio 1" ,"radio1","http://www.radio1.be","http://mp3.streampower.be/radio1-high") radio2 = stationvrt("Radio 2" ,"radio2","http://www.radio2.be","http://mp3.streampower.be/radio2-high") klara = stationvrt("Klara" ,"klara" ,"http://www.klara.be" ,"http://mp3.streampower.be/klara-high" ) stubru = stationvrt("Studio Brussel" ,"stubru","http://www.stubru.be","http://mp3.streampower.be/stubru-high") sporza = stationvrt("Sporza" ,"sporza","http://www.sporza.be","http://mp3.streampower.be/sporza-high") mnm = stationvrt("MNM" ,"mnm" ,"http://www.mnm.be" ,"http://mp3.streampower.be/donna-high" ) VRT = stationgroup("VRT",[radio1,radio2,klara,stubru,sporza,mnm])
except SelectorError: parser.error('Invalid CSS selector') for e,eid in zip(page.xpath(expressiontitle),page.xpath(expressionurl)): try: title =re.search('.* au podcast (.*)', e.text ).group(1) found =re.search('^.*sound/(.*)\.xml', eid.get("href")).group(1) except AttributeError: found = '' etemp = emissioneurope1(title,found) qqq = "INSERT INTO emissions (station, title, podcasturl, idemission) VALUES (\""+self.name+"\",\""+etemp.name+"\",'"+etemp.podcasturl+"','"+str(etemp.idpod)+"')" print qqq c.execute(qqq) conn.commit() conn.close() class emissioneurope1(emission): def __init__(self,name,idpod): podcasturl="http://cdn-new-europe1.ladmedia.fr/var/exports/podcasts/sound/"+str(idpod)+".xml" emission.__init__(self,name,podcasturl,idpod) self.idpod=idpod self.name=name self.podcasturl=podcasturl europe1 = stationeurope1("Europe 1","europe1","http://www.europe1.fr/podcasts","http://vipicecast.yacast.net/europe1",'.popup .title','.popup ul li a.link') Lagardere = stationgroup("Lagardere",[europe1])
found =re.search('http://www.rtl2.fr/podcast/(.*).xml', eid.get("href")).group(1) except AttributeError: found = '' else: found="" # print eid.get("href")+" "+found+" "+e.text etemp = emissionrtl(e.text,found,True) emissions.append(etemp) self.emissions=emissions class emissionrtl(emission): def __init__(self,name,idpod,rtl2=False): podcasturl="http://www.rtl.fr/podcast/"+idpod+".xml" if rtl2: podcasturl="http://www.rtl2.fr/podcast/"+idpod+".xml" emission.__init__(self,name,podcasturl,idpod) rtlfr = stationrtl("RTL France","rtlfr","http://www.rtl.fr/recherche?type=emission&query=","http://radio.rtl.fr/rtl.pls",'.show figure a.post-link',True) rtl2fr = stationrtl("RTL2 France","rtl2fr","http://www.rtl2.fr/radio/podcasts.html#","http://streaming.radio.rtl2.fr/rtl2-1-44-128",'.common h3',".common .rss") funradiofr = station("Fun Radio Fr.","funradiofr","http://www.funradio.fr/","http://streaming.radio.funradio.fr:80/fun-1-44-128",True) belrtlbe = station("BelRTL Belgique","belrtlbe","http://www.rtl.be/belrtl/","http://icy.rtl.nl/belrtl128",True) radiocontactbe = station("Radio Contact Belgique","radiocontactbe","http://fr.radiocontact.be/","http://icy.rtl.nl/contactfr.m3u",True) mintbe = station("Mint","mintbe","http://www.mint.be/","http://icy.rtl.nl/mint.m3u",True) RTL = stationgroup("RTL",[rtlfr,rtl2fr,funradiofr,belrtlbe,radiocontactbe,mintbe])
idpod) + ".xml" emission.__init__(self, name, podcasturl, idpod) self.idpod = idpod self.name = name self.podcasturl = podcasturl inter = stationradiofrance( 'France Inter', "frinter", "https://www.franceinter.fr/podcasts/liste", "https://www.tv-radio.com/station/france_inter_mp3/france_inter_mp3-128k.m3u", ".contenu h2 a", ".podrss") mouv = stationradiofrance( 'Le Mouv', "lemouv", "https://www.lemouv.fr/podcasts", ".row .title", "https://www.tv-radio.com/station/le_mouv_mp3/le_mouv_mp3-128k.m3u", ".row .podcast-links a.podcast-rss") info = stationradiofrance( 'France Info', "frinfo", "https://www.franceinfo.fr/programmes-chroniques/podcasts", "https://www.tv-radio.com/station/france_info/france_info.m3u", ".emission-gdp h2 a", ".podcast .last a") culture = stationradiofrance( 'France culture', "frculture", "https://www.franceculture.fr/podcasts", "https://www.tv-radio.com/station/france_culture_mp3/france_culture_mp3-128k.m3u", "li h3 a", "li h3 a") fip = stationradiofrance( 'FIP', "frfip", "https://www.fipradio.fr/emissions", "https://www.tv-radio.com/station/fip_mp3/fip_mp3-128k.m3u", ".rubrique_emission a h1.title", ".podcast_rss a") RadioFrance = stationgroup("Radio France", [inter, mouv, info, culture, fip])
title = re.search('.* au podcast (.*)', e.text).group(1) found = re.search('^.*sound/(.*)\.xml', eid.get("href")).group(1) except AttributeError: found = '' etemp = emissioneurope1(title, found) qqq = "INSERT INTO emissions (station, title, podcasturl, idemission) VALUES (\"" + self.name + "\",\"" + etemp.name + "\",'" + etemp.podcasturl + "','" + str( etemp.idpod) + "')" print(qqq) c.execute(qqq) conn.commit() conn.close() class emissioneurope1(emission): def __init__(self, name, idpod): podcasturl = "https://cdn-new-europe1.ladmedia.fr/var/exports/podcasts/sound/" + str( idpod) + ".xml" emission.__init__(self, name, podcasturl, idpod) self.idpod = idpod self.name = name self.podcasturl = podcasturl europe1 = stationeurope1("Europe 1", "europe1", "https://www.europe1.fr/podcasts", "https://vipicecast.yacast.net/europe1", '.popup .title', '.popup ul li a.link') Lagardere = stationgroup("Lagardere", [europe1])
print found else: found =re.search('http.*rss_(.*)\.xml', eid.get("href")).group(1) except AttributeError: found = '' else: found="" etemp = emissionradiofrance(e.text,found) qqq = "INSERT INTO emissions (station, title, podcasturl, idemission) VALUES (\""+self.name+"\",\""+etemp.name+"\",'"+etemp.podcasturl+"','"+str(etemp.idpod)+"')" print qqq c.execute(qqq) conn.commit() conn.close() class emissionradiofrance(emission): def __init__(self,name,idpod): podcasturl="http://radiofrance-podcast.net/podcast09/rss_"+str(idpod)+".xml" emission.__init__(self,name,podcasturl,idpod) self.idpod=idpod self.name=name self.podcasturl=podcasturl inter = stationradiofrance('France Inter', "frinter","http://www.franceinter.fr/podcasts/liste","http://www.tv-radio.com/station/france_inter_mp3/france_inter_mp3-128k.m3u",".contenu h2 a",".podrss") mouv = stationradiofrance('Le Mouv',"lemouv","http://www.lemouv.fr/podcasts",".row .title","http://www.tv-radio.com/station/le_mouv_mp3/le_mouv_mp3-128k.m3u",".row .podcast-links a.podcast-rss") info = stationradiofrance('France Info',"frinfo","http://www.franceinfo.fr/programmes-chroniques/podcasts","http://www.tv-radio.com/station/france_info/france_info.m3u",".emission-gdp h2 a", ".podcast .last a") culture = stationradiofrance('France culture',"frculture","http://www.franceculture.fr/podcasts","http://www.tv-radio.com/station/france_culture_mp3/france_culture_mp3-128k.m3u","li h3 a","li h3 a") fip = stationradiofrance('FIP',"frfip","http://www.fipradio.fr/emissions","http://www.tv-radio.com/station/fip_mp3/fip_mp3-128k.m3u",".rubrique_emission a h1.title",".podcast_rss a") RadioFrance = stationgroup("Radio France",[inter,mouv,info,culture,fip])
def searchpodcast(self,query=""): emissions=[] url="https://www.rtbf.be/radio/podcast/fetchall?channel="+self.nomcode+"&tab=tags&category=all&query="+query html_parser = etree.HTMLParser(encoding='utf-8', recover=True,strip_cdata=True) jsonurl = urllib.request.urlopen(url) text = json.loads(jsonurl.read()) x = PrettyTable(["id","Titre", "date","url"]) x.align["Titre"] = "l" # Left align x.align["date"] = "l" # Left align x.align["url"] = "l" # Left align x.padding_width = 1 # One space between column edges and contents (default) for po,ii in zip(text['list'],list(range(len(text['list'])))): x.add_row([ ii,po['title'],time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(po['created'])),po['url'] ]) print(x) class emissionrtbf(emission): def __init__(self,name,idpod): podcasturl="https://rss.rtbf.be/media/rss/audio/c21-"+idpod+".xml" emission.__init__(self,name,podcasturl,idpod) self.idpod=idpod self.name=name self.podcasturl=podcasturl lapremiere = stationrtbf("La premiere","lapremiere","lp") musiq3 = stationrtbf("Musique 3","musiq3","m3") classic21 = stationrtbf("Classic 21","classic21","c21") purefm = stationrtbf("Pure fm","purefm","pu") vivacite = stationrtbf("Vivacite","vivacite","vi") RTBF=stationgroup("RTBF",[lapremiere,musiq3,classic21,purefm,vivacite])
class stationvrt(station): def __init__( self, name, code, url, streamurl="", ): station.__init__(self, name, code, url, streamurl, True) self.name = name self.code = code self.url = url self.streamurl = streamurl radio1 = stationvrt("Radio 1", "radio1", "https://www.radio1.be", "https://mp3.streampower.be/radio1-high") radio2 = stationvrt("Radio 2", "radio2", "https://www.radio2.be", "https://mp3.streampower.be/radio2-high") klara = stationvrt("Klara", "klara", "https://www.klara.be", "https://mp3.streampower.be/klara-high") stubru = stationvrt("Studio Brussel", "stubru", "https://www.stubru.be", "https://mp3.streampower.be/stubru-high") sporza = stationvrt("Sporza", "sporza", "https://www.sporza.be", "https://mp3.streampower.be/sporza-high") mnm = stationvrt("MNM", "mnm", "https://www.mnm.be", "https://mp3.streampower.be/donna-high") VRT = stationgroup("VRT", [radio1, radio2, klara, stubru, sporza, mnm])
def searchpodcast(self,query=""): emissions=[] url="http://www.rtbf.be/radio/podcast/fetchall?channel="+self.nomcode+"&tab=tags&category=all&query="+query html_parser = etree.HTMLParser(encoding='utf-8', recover=True,strip_cdata=True) jsonurl = urllib2.urlopen(url) text = json.loads(jsonurl.read()) x = PrettyTable(["id","Titre", "date","url"]) x.align["Titre"] = "l" # Left align x.align["date"] = "l" # Left align x.align["url"] = "l" # Left align x.padding_width = 1 # One space between column edges and contents (default) for po,ii in zip(text['list'],range(len(text['list']))): x.add_row([ ii,po['title'],time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(po['created'])),po['url'] ]) print x class emissionrtbf(emission): def __init__(self,name,idpod): podcasturl="http://rss.rtbf.be/media/rss/audio/c21-"+idpod+".xml" emission.__init__(self,name,podcasturl,idpod) self.idpod=idpod self.name=name self.podcasturl=podcasturl lapremiere = stationrtbf("La premiere","lapremiere","lp") musiq3 = stationrtbf("Musique 3","musiq3","m3") classic21 = stationrtbf("Classic 21","classic21","c21") purefm = stationrtbf("Pure fm","purefm","pu") vivacite = stationrtbf("Vivacite","vivacite","vi") RTBF=stationgroup("RTBF",[lapremiere,musiq3,classic21,purefm,vivacite])
a=len(d['entries']) else: a=number x = PrettyTable(["id","Titre", "date","url"]) x.align["Titre"] = "l" # Left align x.align["date"] = "l" # Left align x.align["url"] = "l" # Left align x.padding_width = 1 # One space between column edges and contents (default) print "Emission: "+d['channel']['title'] print "Auteur: "+d['channel']['author'] print "podcast xml: "+d['channel']['summary_detail']['base'] for ii,e in zip(range(len(d['entries'])),d['entries'][:a]): x.add_row([ ii, e['title'],e['updated'], e['link'] ]) print x def playpodcast(self,Tid): d = feedparser.parse(self.podurl) urltoplay = str(d['entries'][Tid]["link"]) print "mplayer %s" % urltoplay subprocess.call(["mplayer",urltoplay]) bbc1 = stationbbc('bbc 1','bbc1',"radio1","http://www.bbc.co.uk/radio/listen/live/r1_aaclca.pls",".pc-result-heading a",".pc-result-heading a") bbc2 = stationbbc('bbc 2','bbc2',"radio2","http://www.bbc.co.uk/radio/listen/live/r2_aaclca.pls",".pc-result-heading a",".pc-result-heading a") bbc3 = stationbbc('bbc 3','bbc3',"radio3","http://www.bbc.co.uk/radio/listen/live/r3_aaclca.pls",".pc-result-heading a",".pc-result-heading a") bbc4 = stationbbc('bbc 4','bbc4',"radio4","http://www.bbc.co.uk/radio/listen/live/r4_aaclca.pls",".pc-result-heading a",".pc-result-heading a") bbc5 = stationbbc('bbc 5','bbc5',"5live" ,"http://www.bbc.co.uk/radio/listen/live/r5_aaclca.pls",".pc-result-heading a",".pc-result-heading a") bbc6 = stationbbc('bbc 6','bbc6',"6music","http://www.bbc.co.uk/radio/listen/live/r6_aaclca.pls",".pc-result-heading a",".pc-result-heading a") BBC = stationgroup("BBC",[bbc1,bbc2,bbc3,bbc4,bbc5,bbc6])