def __init__(self, name, sid): """ @param name: The radio station name. @param sid: The broadcast service identifier (SId). """ RadioStation.__init__(self, "amss", name) if re.match('^[0-9A-F]{6}$', sid, re.IGNORECASE): self._sid = sid else: raise RuntimeError, "Invalid sid"
def __init__(self, name, ecc=None, country=None, pi=None, freq=None): """ @param name: The radio station name. @param ecc: The broadcast RDS extended country code. @param country: An ISO country code, if a broadcast ECC is unavailable. @param pi: The broadcast programme identification (PI) code. @param freq: The frequency on which the service is received, in 0.01 MHz units, e.g, 98.8 MHz would be represented as 9880. """ RadioStation.__init__(self, "fm", name) # Programme identification (PI) code is 4 hex digits. if pi is not None and re.match('^[0-9A-F]{4}$', pi, re.IGNORECASE): self._pi = pi else: raise ValueError, "Invalid pi" if country is not None: # Check for 2-letter ISO country code. if re.match('^[A-Z]{2}$', country, re.IGNORECASE): self._country = country else: raise ValueError, "Invalid country" if ecc is not None: raise ValueError, "country and ecc are mutually exclusive" elif ecc is not None: # Check for 2-hex-digit extended country code, and concatenate # with the first character of the RDS PI code. if re.match('^[0-9A-F]{2}$', ecc, re.IGNORECASE): self._country = self._pi[0] + ecc else: raise ValueError, "Invalid extended country code" try: freq = int(freq) except (ValueError, TypeError): raise ValueError, "Invalid freq" if freq >= 0 and freq <= 99999: self._freq = "%05u" % freq else: raise ValueError, "Invalid freq"
def __init__(self, name, ecc = None, country = None, pi = None, freq = None): """ @param name: The radio station name. @param ecc: The broadcast RDS extended country code. @param country: An ISO country code, if a broadcast ECC is unavailable. @param pi: The broadcast programme identification (PI) code. @param freq: The frequency on which the service is received, in 0.01 MHz units, e.g, 98.8 MHz would be represented as 9880. """ RadioStation.__init__(self, "fm", name) # Programme identification (PI) code is 4 hex digits. if pi is not None and re.match('^[0-9A-F]{4}$', pi, re.IGNORECASE): self._pi = pi else: raise ValueError, "Invalid pi" if country is not None: # Check for 2-letter ISO country code. if re.match('^[A-Z]{2}$', country, re.IGNORECASE): self._country = country else: raise ValueError, "Invalid country" if ecc is not None: raise ValueError, "country and ecc are mutually exclusive" elif ecc is not None: # Check for 2-hex-digit extended country code, and concatenate # with the first character of the RDS PI code. if re.match('^[0-9A-F]{2}$', ecc, re.IGNORECASE): self._country = self._pi[0] + ecc else: raise ValueError, "Invalid extended country code" try: freq = int(freq) except (ValueError, TypeError): raise ValueError, "Invalid freq" if freq >= 0 and freq <= 99999: self._freq = "%05u" % freq else: raise ValueError, "Invalid freq"
def read_stations(): stations = [] with open('stations_list.csv') as radio_stations_file: readCSV = csv.reader(radio_stations_file, delimiter=',') for csv_station in readCSV: stations.append(RadioStation.fromCSV(csv_station)) return stations
def startElement(self, name, attributes): if name == "station": self.entry = RadioStation() self.entry.type = "Board" self.entry.id = attributes.get("id") self.entry.server_name = attributes.get("name") self.entry.genre = attributes.get("tags") if (self.entry.genre == None): self.entry.genre = "" self.entry.genre = ",".join(self.entry.genre.split(" ")) self.entry.listen_url = attributes.get("url") self.entry.language = attributes.get("language") self.entry.country = attributes.get("country") self.entry.votes = attributes.get("votes") self.entry.negativevotes = attributes.get("negativevotes") self.entry.homepage = attributes.get("homepage") self.entry.icon_src = attributes.get("favicon") try: self.entry.clickcount = attributes.get("clickcount") except: self.entry.clickcount = 0 self.entries.append(self.entry) if self.entry.country.title() not in self.countries: self.countries.append(self.entry.country.title()) if self.entry.language.title() not in self.languages: self.languages.append(self.entry.language.title())
def load_stations_list(self): """Load radio station list""" with open('radio.json') as f: sts = json.load(f) self.stations = [] for s in sts: self.stations.append(RadioStation(s))
def __init__(self, name, tx, cc): """ @param name: The radio station name. @param tx: The broadcast transmitter identifier. @param cc: The broadcast country code. """ RadioStation.__init__(self, "hd", name) if re.match('^[0-9A-F]{5}$', tx, re.IGNORECASE): self._tx = tx else: raise ValueError, "Invalid tx" if re.match('^[0-9A-F]{3}$', cc, re.IGNORECASE): self._cc = cc else: raise ValueError, "Invalid cc"
def __init__(self): RadioStation.__init__(self, 'test', 'Test')
def __init__(self, name, ecc, eid, sid, scids, appty = None, uatype = None, pa = None): """ @param name: The radio station name. @param ecc: The broadcast extended country code (ECC). @param eid: The broadcast ensemble identifier (EId). @param sid: The broadcast service identifier (SId). @param scids: The broadcast service component identifier within the service (SCIdS). @param appty: The broadcast X-PAD application type (AppTy), if the audio service is delivered as data via X-PAD. @param uatype: The broadcast user application type (UAType). If AppTy is specified, UAType must also be specified. @param pa: The broadcast packet address, which is mandatory if the audio service is delivered as data in an independent service component. """ RadioStation.__init__(self, "dab", name) if re.match('^[0-9A-F]{3}$', ecc, re.IGNORECASE): self._ecc = ecc else: raise ValueError, "Invalid ecc" if re.match('^[0-9A-F]{4}$', eid, re.IGNORECASE): self._eid = eid else: raise ValueError, "Invalid eid" if re.match('^[0-9A-F]{4}$', sid, re.IGNORECASE) \ or re.match('^[0-9A-F]{8}$', sid, re.IGNORECASE): self._sid = sid else: raise ValueError, "Invalid sid" if re.match('^[0-9A-F]{1}$', scids, re.IGNORECASE) \ or re.match('^[0-9A-F]{3}$', scids, re.IGNORECASE): self._scids = scids else: raise ValueError, "Invalid scids" if appty is not None: if re.match('^[0-9A-F]{2}$', appty, re.IGNORECASE): self._appty_uatype = appty else: raise ValueError, "Invalid appty" if uatype is not None: if re.match('^[0-9A-F]{3}$', uatype, re.IGNORECASE): self._appty_uatype += "-" + uatype else: raise ValueError, "Invalid uatype" else: raise ValueError, "Both appty and uatype must be specified" if pa is not None: raise ValueError, "pa and appty-uatype are mutually exclusive" else: if uatype is not None: raise ValueError, "Both appty and uatype must be specified" self._appty_uatype = None if pa is not None: try: pa = int(pa) except (ValueError, TypeError): raise ValueError, "Invalid pa" if pa >= 0 and pa <= 1023: self._pa = pa else: raise ValueError, "Invalid pa" if appty is not None or uatype is not None: raise ValueError, "pa and appty-uatype are mutually exclusive" else: self._pa = None
def startElement(self, name, attributes): self.currentEntry = name if name == "entry": self.entry = RadioStation() self.entry.type = "Icecast"
def __init__(self, name, ecc, eid, sid, scids, appty=None, uatype=None, pa=None): """ @param name: The radio station name. @param ecc: The broadcast extended country code (ECC). @param eid: The broadcast ensemble identifier (EId). @param sid: The broadcast service identifier (SId). @param scids: The broadcast service component identifier within the service (SCIdS). @param appty: The broadcast X-PAD application type (AppTy), if the audio service is delivered as data via X-PAD. @param uatype: The broadcast user application type (UAType). If AppTy is specified, UAType must also be specified. @param pa: The broadcast packet address, which is mandatory if the audio service is delivered as data in an independent service component. """ RadioStation.__init__(self, "dab", name) if re.match('^[0-9A-F]{3}$', ecc, re.IGNORECASE): self._ecc = ecc else: raise ValueError, "Invalid ecc" if re.match('^[0-9A-F]{4}$', eid, re.IGNORECASE): self._eid = eid else: raise ValueError, "Invalid eid" if re.match('^[0-9A-F]{4}$', sid, re.IGNORECASE) \ or re.match('^[0-9A-F]{8}$', sid, re.IGNORECASE): self._sid = sid else: raise ValueError, "Invalid sid" if re.match('^[0-9A-F]{1}$', scids, re.IGNORECASE) \ or re.match('^[0-9A-F]{3}$', scids, re.IGNORECASE): self._scids = scids else: raise ValueError, "Invalid scids" if appty is not None: if re.match('^[0-9A-F]{2}$', appty, re.IGNORECASE): self._appty_uatype = appty else: raise ValueError, "Invalid appty" if uatype is not None: if re.match('^[0-9A-F]{3}$', uatype, re.IGNORECASE): self._appty_uatype += "-" + uatype else: raise ValueError, "Invalid uatype" else: raise ValueError, "Both appty and uatype must be specified" if pa is not None: raise ValueError, "pa and appty-uatype are mutually exclusive" else: if uatype is not None: raise ValueError, "Both appty and uatype must be specified" self._appty_uatype = None if pa is not None: try: pa = int(pa) except (ValueError, TypeError): raise ValueError, "Invalid pa" if pa >= 0 and pa <= 1023: self._pa = pa else: raise ValueError, "Invalid pa" if appty is not None or uatype is not None: raise ValueError, "pa and appty-uatype are mutually exclusive" else: self._pa = None
# To change this license header, choose License Headers in Project Properties. # To change this template file, choose Tools | Templates # and open the template in the editor. from radio_station import RadioStation __author__ = "HP Envy" __date__ = "$Nov 19, 2014 4:16:15 PM$" if __name__ == "__main__": radio_station = RadioStation(12) radio_station.run() #radio_station.__init__(radio_station, 8)
def record_play_button_handler(self,button,uri): station = RadioStation() station.server_name = self.stream_name station.listen_url = "http://127.0.0.1:"+self.relay_port station.type = "local" self.play_cb(station)
import logging from logging.handlers import TimedRotatingFileHandler from rootio.extensions import db telephony_server = Flask("ResponseServer") telephony_server.debug = True telephony_server.config[ 'SQLALCHEMY_DATABASE_URI'] = 'postgresql://*****:*****@localhost/rootio' if __name__ == "__main__": #setup logging app_logger = logging.getLogger('station_runner') hdlr = TimedRotatingFileHandler('/var/log/rootio/stations.log', when='midnight', interval=1) formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') hdlr.setFormatter(formatter) app_logger.addHandler(hdlr) app_logger.setLevel(logging.DEBUG) db = SQLAlchemy(telephony_server) stations = db.session.query(Station).all() for station in stations: radio_station = RadioStation(station.id, app_logger) app_logger.info('launching station : {0}'.format(station.id)) t = threading.Thread(target=radio_station.run, args=()) t.start() print "================ service started at {0} ==============".format( datetime.utcnow())
def record_play_button_handler(self, button, uri): station = RadioStation() station.server_name = self.stream_name station.listen_url = "http://127.0.0.1:" + self.relay_port station.type = "local" self.play_cb(station)
# To change this license header, choose License Headers in Project Properties. # To change this template file, choose Tools | Templates # and open the template in the editor. from radio_station import RadioStation __author__="HP Envy" __date__ ="$Nov 19, 2014 4:16:15 PM$" if __name__ == "__main__": radio_station = RadioStation(12) radio_station.run() #radio_station.__init__(radio_station, 8)