如何获得流媒体的网址从在线流媒体电台

问题描述 投票:10回答:5

我被要求为某电台制作非官方的在线流媒体安卓应用。我有经验的流媒体在Android的某些MP3或什么流。但我不知道 stream url 以提供 mediaPlayer.setDataSource(url).

有什么办法可以得到流的网址从官方流媒体页面,例如:。这个电台流?

javascript android html stream
5个回答
16
投票

没有那么难。

如果你看一下这个页面的源码,你会发现它使用的是shoutcast流媒体。

这是流媒体的网址

"StreamUrl": "http:/stream.radiotime.comlisten.stream?streamIds=3244651&rti=c051HQVbfRc4FEMbKg5RRVMzRU9KUBw%2fVBZHS0dPF1VIExNzJz0CGQtRcX8OS0o0CUkYRFJDDW8LEVRxGAEOEAcQXko%2bGgwSBBZrV1pQZgQZZxkWCA4L%7e%7e%7e。",

它返回一个JSON这样的。

{
    "Streams": [
        {
            "StreamId": 3244651,
            "Reliability": 92,
            "Bandwidth": 64,
            "HasPlaylist": false,
            "MediaType": "MP3",
            "Url": "http://mp3hdfm32.hala.jo:8132",
            "Type": "Live"
        }
    ]
}

我相信这就是你所需要的url:http:/mp3hdfm32.hala.jo:8132

这是本站的网站


5
投票

编辑了ZygD的python 3.x的答案。

import re
import urllib.request
import string
url1 = input("Please enter a URL from Tunein Radio: ");
request = urllib.request.Request(url1);
response = urllib.request.urlopen(request);
raw_file = response.read().decode('utf-8');
API_key = re.findall(r"StreamUrl\":\"(.*?),\"",raw_file);
#print API_key;
#print "The API key is: " + API_key[0];
request2 = urllib.request.Request(str(API_key[0]));
response2 = urllib.request.urlopen(request2);
key_content = response2.read().decode('utf-8');
raw_stream_url = re.findall(r"Url\": \"(.*?)\"",key_content);
bandwidth = re.findall(r"Bandwidth\":(.*?),", key_content);
reliability = re.findall(r"lity\":(.*?),", key_content);
isPlaylist = re.findall(r"HasPlaylist\":(.*?),",key_content);
codec = re.findall(r"MediaType\": \"(.*?)\",", key_content);
tipe = re.findall(r"Type\": \"(.*?)\"", key_content);
total = 0
for element in raw_stream_url:
    total = total + 1
i = 0
print ("I found " + str(total) + " streams.");
for element in raw_stream_url:
    print ("Stream #" + str(i + 1));
    print ("Stream stats:");
    print ("Bandwidth: " + str(bandwidth[i]) + " kilobytes per second.");
    print ("Reliability: " + str(reliability[i]) + "%");
    print ("HasPlaylist: " + str(isPlaylist[i]));
    print ("Stream codec: " + str(codec[i]));
    print ("This audio stream is " + tipe[i].lower());
    print ("Pure streaming URL: " + str(raw_stream_url[i]));
i = i + 1
input("Press enter to close")

4
投票

Shahar的回答真的很有帮助, 但我发现自己做这些事情很繁琐, 所以我做了一个小小的Python程序:

import re
import urllib2
import string
url1 = raw_input("Please enter a URL from Tunein Radio: ");
open_file = urllib2.urlopen(url1);
raw_file = open_file.read();
API_key = re.findall(r"StreamUrl\":\"(.*?),",raw_file);
#print API_key;
#print "The API key is: " + API_key[0];
use_key = urllib2.urlopen(str(API_key[0]));
key_content = use_key.read();
raw_stream_url = re.findall(r"Url\": \"(.*?)\"",key_content);
bandwidth = re.findall(r"Bandwidth\":(.*?),", key_content);
reliability = re.findall(r"lity\":(.*?),", key_content);
isPlaylist = re.findall(r"HasPlaylist\":(.*?),",key_content);
codec = re.findall(r"MediaType\": \"(.*?)\",", key_content);
tipe = re.findall(r"Type\": \"(.*?)\"", key_content);
total = 0
for element in raw_stream_url:
    total = total + 1
i = 0
print "I found " + str(total) + " streams.";
for element in raw_stream_url:
    print "Stream #" + str(i + 1);
    print "Stream stats:";
    print "Bandwidth: " + str(bandwidth[i]) + " kilobytes per second."
    print "Reliability: " + str(reliability[i]) + "%"
    print "HasPlaylist: " + str(isPlaylist[i]) + "."
    print "Stream codec: " + str(codec[i]) + "."
    print "This audio stream is " + tipe[i].lower() + "."
    print "Pure streaming URL: " + str(raw_stream_url[i]) + ".";
    i = i + 1
raw_input("Press enter to close TMUS.")

基本上就是把沙哈尔的解决方案自动化了 It's basically Shahar's solution automated.


1
投票

当你进入一个流网址时,你会得到一个文件.把这个文件喂给一个解析器来提取其中的内容.这个文件是(通常)纯文本,包含要播放的网址。


0
投票

提供的答案对我不起作用。我添加了另一个答案,因为这是我在搜索电台流的URL时结束的地方。

Radio Browser是一个可搜索的网站,提供世界各地电台的流媒体网址。

http:/www.radio-browser.info

搜索一个站,如 FIP, 品冠电台天堂电台然后点击保存按钮,下载一个PLS文件,你可以在你的radioplayer(Rhythmbox)中打开,或者你在文本编辑器中打开文件并复制URL添加到Goodvibes中。

© www.soinside.com 2019 - 2024. All rights reserved.