• Willkommen im Linux Club - dem deutschsprachigen Supportforum für GNU/Linux. Registriere dich kostenlos, um alle Inhalte zu sehen und Fragen zu stellen.

Radio-Player (Python-Skript)

abgdf

Guru
Hallo,

das folgende Skript spielt ein paar ausgesuchte Radio-Stationen über mplayer ab. Durch Editieren kann man auch weitere/eigene einfügen.

Es benötigt eine korrekte mplayer-Installation und eine DSL-Internetverbindung.
Code:
#!/usr/bin/env python
# coding: iso-8859-1

import os
import sys

# radio.py - Radio-Player
# (C) 2012, abgdf, GNU-GPL 3, http://www.gnu.org/licenses/gpl-3.0

RADIOS = (("Fresh80s",   "http://62.141.52.133:80"),
          ("FFH 80er",   "http://mp3.ffh.de/ffhchannels/hq80er.mp3"),
          ("FFH Top 40", "http://mp3.ffh.de/ffhchannels/hqtop40.mp3"),
          ("FFH Electro Beats", "http://mp3.ffh.de/ffhchannels/hqelectrobeatz.mp3"),
          ("FFH Hits",        "http://mp3.ffh.de/radioffh/hqlivestream.mp3"),
          ("FFH Soundtrack",  "http://mp3.ffh.de/ffhchannels/hqsoundtrack.mp3"),
          ("FFH Eurodance",   "http://mp3.ffh.de/ffhchannels/hqeurodance.mp3"),
          ("FFH Lounge",      "http://mp3.ffh.de/ffhchannels/hqlounge.mp3"),
          ("FFH Deutsch pur", "http://mp3.ffh.de/ffhchannels/hqdeutsch.mp3"),
          ("NDR N-Joy",       "http://ndrstream.ic.llnwd.net/stream/ndrstream_n-joy_hi_mp3"),
          ("NDR 2",           "http://ndrstream.ic.llnwd.net/stream/ndrstream_ndr2_hi_mp3"))

def getChoice(choices, question, defelementnr):

    """ While the input is a number starting from 1,
        the returned result is the number of the element
        of "choices" (which is a tuple of tuples). """

    defelementinrange = False 
    choiceinrange = False 

    if defelementnr >= 0 and defelementnr < len(choices):
        defelementinrange = True 

    if defelementinrange:
        question += " (Default = " + "'"
        question +=  choices[defelementnr][0]
        question +=  "'):"
    print question
    print
    for i in range(len(choices)):
        print str(i + 1) + ". " + choices[i][0]
    print
    choice = ""
    while not choiceinrange:
        choice = raw_input("Choice: ")
        if choice == "q":
            print "Bye."
            sys.exit(0)
        if choice == "" and defelementinrange:
            choice = str(defelementnr + 1)
            break
        if choice.isdigit() and int(choice) >= 1 and int(choice) <= len(choices):
            choiceinrange = True
    return int(choice) - 1

def getFilename(nr):
    x = 1
    xstr = str(x)
    if x < 10:
        xstr = "0" + xstr
    radioname = RADIOS[nr][0]
    radioname = radioname.lower()
    radioname = radioname.replace(" ", "-")
    filename = os.path.join(os.getcwd(), radioname + "_")
    while os.path.exists(filename + xstr + ".stream"):
        x += 1
        xstr = str(x)
        if x < 10:
            xstr = "0" + xstr
    filename += xstr + ".stream"
    return filename

print
radionr = getChoice(RADIOS, "Choose radio-station", 2)
execstr = "mplayer " + "'" + RADIOS[radionr][1] + "' -quiet -nojoystick -af volnorm"
# print execstr
# execstr += askRec()
execstr += " &>/dev/null"
print
if "dumpstream" in execstr:
    print "Recording radio: " + RADIOS[radionr][0] + " (Ctrl+c to quit)."
else:
    print "Playing radio: " + RADIOS[radionr][0] + "."
os.system(execstr)
Radio-Adressen von:

http://www.linupedia.org/opensuse/Radiosender
http://www.ffh.de/musik/webradios/stream-adressen.html
http://www.fresh80s.de/modules/info/index.php?cat=3&id=11

Gruß

abgdf
 
Oben