2014-01-16 63 views

回答

14

並不難,

,如果你看看網頁源代碼,你會看到它使用流式傳輸通過Shoutcast的聲音。

這是直播網址

「StreamUrl」: 「http://stream.radiotime.com/listen.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" 
     } 
    ] 
} 

我相信您需要的網址: http://mp3hdfm32.hala.jo:8132

this is the station WebSite

+0

這就是它!在發佈之前,我嘗試檢查元素,並找到類似的東西,但我不能,謝謝 –

+0

'http://mp3hdfm32.hala.jo:8132'已關閉。 – Stallman

+0

我目前有同樣的問題 我需要在[本網站](http://tunein.com/radio/local/)播放音頻 幫我出 –

1

當你轉到流url時,你會得到一個文件。將該文件提供給解析器以從中提取內容。該文件(通常)是純文本幷包含要播放的網址。

4

沙哈爾的回答是真正有用的,但我覺得這是很繁瑣的做這一切我自己,所以我做了一個漂亮的小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.") 

它基本上沙哈爾的解決方案的自動化。

+0

要獲得整個列表替換此**' API_key = re.findall(r「StreamUrl \」:\「(。*?),\」「,raw_file)'**我剛剛在正則表達式 – Vassilis

4

編輯ZygD的答案蟒蛇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") 
+1

上加了'\」'我不得不把'http:'附加到API密鑰:'request2 = urllib.request.Request(「http:%s」%API_key [0]);' – bastian