每隔几秒钟从HTTP源获取并更新文本到HTTPS网站

时间:2021-10-29 01:17:04

So, I have a radio station, my host provider does not have a SSL certificate and I have an website with a SSL certificate on where I want to display the current track name (mentioning again, only the track name, and not the artist) being played on the radio station. The track name can be found here: http://91.121.139.194:8157/currentsong?sid=1

因此,我有一个广播电台,我的主机提供商没有SSL证书,我有一个网站,在那里我想显示广播电台播放的当前曲目名称(再次提到,只有曲目名称,而不是歌手)。可以在这里找到赛道名称:http://91.121.139.194:8157/currentsong?sid=1

The output of the above link displays: X - X - Y

上面链接的输出显示:X - X - Y

X - Artist, Y - Track name. I don't want the first X to be displayed so it won't display the artist two times (one from artist metadata and one from track name metadata)

X -艺术家,Y -赛道名。我不希望第一个X被显示,这样它就不会显示艺术家两次(一个来自艺术家元数据,一个来自跟踪名元数据)

The problem is that I can't get text from HTTP to HTTPS. I tried Ajax and Javascript. Every one of them were blocked.

问题是我无法从HTTP获取文本到HTTPS。我尝试了Ajax和Javascript。他们每个人都被*了。

I know that displaying data from unsecured HTTP will pose a risk to the HTTPS I have, that's why I will hide the track name until the user clicks Play. Playing the audio also poses a risk since it is sent from HTTP....

我知道从无担保的HTTP中显示数据会对HTTPS带来风险,这就是为什么我要隐藏跟踪名称直到用户点击播放。播放音频也带来了风险,因为它是发出HTTP ....

My host provider also offers an API but the javascript that comes with it, also requests data from HTTP, being blocked...

我的主机提供商也提供了一个API,但是它附带的javascript也从HTTP请求数据,被阻塞……

Is there any workaround for this? I think it is pointless to put the Ajax and Javascript I used because both methods don't work. I also heard of using curl or file_get_contents but I really don't want to spend more hours as I did with the first 2 methods I tried just to find that it doesn't work. I need an advice to what to do.

有什么办法吗?我认为使用Ajax和Javascript是没有意义的,因为这两个方法都不能工作。我也听说过使用curl或file_get_contents,但我真的不想花更多的时间,就像我使用前两种方法一样,我只是试图发现它不起作用。我需要一个关于该怎么做的建议。

Also, if there are better ways of getting the track name from a ShoutCast server, I am ok with that.

此外,如果有更好的方法从ShoutCast服务器获取跟踪名,我也可以接受。

On a side note, I don't really know why my host provider does not use OpenSSL... it is free.

另外,我不知道为什么我的主机提供商不使用OpenSSL……它是免费的。

Edit: Another idea I am thinking is to get the track title metadata from the actual .mp3 streaming source. But that source it is from an unsecured HTTP, which again, I am not sure if it would work.

编辑:我正在考虑的另一个想法是从真正的.mp3流源获取曲目标题元数据。但是这个源来自一个不安全的HTTP,我也不确定它是否可以工作。

2 个解决方案

#1


1  

Found an workaround for this. This could be helpful for most of people owning a radio station.

找到了解决办法。这对大多数拥有广播电台的人都有帮助。

I registered my radio station on Internet-Radio. I am not sending you to register your radio station there. You may want to do this with any website you want but make sure that they display every data over HTTPS for this to work.

我在网络电台注册了我的电台。我不会让你在那里注册你的电台。你可能想对任何你想要的网站这样做,但是要确保他们通过HTTPS显示所有的数据。

Most likely they have a proxy to get the data from unsecured HTTP to HTTPS and their entire website is secured. After your radio station is added, search for it on the top search bar and make sure you're only displaying your radio station from your search. This helps file_get_contents to get less HTML, thus loading faster. Get the minimum amount of keywords to display only your radio station, as I did: https://www.internet-radio.com/search/?radio=Riddim+Dubstep+-+Keep

他们很可能有一个代理来从不安全的HTTP获取数据到HTTPS,并且他们的整个网站都是安全的。在你的广播站被添加后,在顶部的搜索栏中搜索它,并确保你只是在你的搜索中显示你的广播站。这有助于file_get_contents获得更少的HTML,从而更快地加载。获取最少的关键字来显示你的广播站,就像我所做的:https://www.internet-radio.com/search/?radio=Riddim+Dubstep+- Keep

Inspect element and find the tag with the track name on it. Right click on it and Copy -> Copy XPath on Chrome, not sure on other browsers. It actually took me some time to find that I can copy the XPath from Right Click -> Inspect...

检查元素并找到带有跟踪名的标记。右击它,复制->复制XPath在Chrome上,不确定在其他浏览器上。实际上,我花了一些时间才发现,我可以从右击->检查中复制XPath…

<?php
libxml_use_internal_errors(false);
$html = file_get_contents('https://www.internet-radio.com/search/?radio=Riddim+Dubstep+-+Keep');
$doc = new DOMDocument;
$doc->loadHTML($html);
$xpath = new DOMXpath($doc);
$node = $xpath->query('/html/body/div[1]/div[1]/div[1]/table/tbody/tr/td[3]/b')->item(0);
echo $node->textContent;
?>

Modify $xpath->query with the XPath you just copyed and the URL with the URL from that page you got the XPath.

修改$xpath->查询的xpath,您只需要复制,并且URL与来自该页面的URL就得到了xpath。

Save this file as

保存这个文件

trackid.php

trackid.php

The following code you will add to your main page.

您将向主页添加以下代码。

<script src="jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
function trackid() {
$.get('trackid.php', function(data) {
$(".TrackTitle").text(data);
}); 
}
trackid()
setInterval(trackid, 5000);
</script>
<div class="TrackTitle">Loading...</div>

The DIV TrackTitlewill be placed where you want the current song to be displayed. You may want to add some CSS to it to format the text to a more well-fitting in page.

DIV tracktitle将放置在您希望显示当前歌曲的位置。您可能想要添加一些CSS到它来格式化文本到一个更合适的页面。

Note: Don't forget to download the latest jquery.min.js from Google's API and update the link to it. I downloaded it on my webhost for faster loading but you can use the direct link to it with no problems.

注意:不要忘记下载最新的jquery.min。来自谷歌API的js,并更新到它的链接。我下载了它在我的webhost更快的加载,但你可以使用直接链接到它没有问题。

#2


1  

If your web hosting provider has the port you use for your Shoutcast station opened, then do what I will explain below. If not, check the other answer below.

如果您的web托管提供者已经打开了您的Shoutcast站点的端口,那么请按照我将在下面解释的那样做。如果没有,检查下面的答案。

Method 1

方法1

Create a file named trackid.php near index.php and put the following code:

创建一个名为trackid的文件。php附近指数。php并放入以下代码:

<?php
$server = "http://91.121.139.194:8157/stats?sid=1";
$srv_url = urlencode($server);
$sc_stats = simplexml_load_file($srv_url);
echo $sc_stats->SONGTITLE
?>

This parses data (song name) from unsecured HTTML to secured HTML by echoit to direct access from a secured connection. Don't forget to replace the IP and Port.

它通过echoit将数据(歌曲名)从不安全的HTTML解析为安全的HTML,以直接从安全的连接进行访问。不要忘记替换IP和端口。

On index.php add this:

在索引。php添加:

<script src="jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
function trackid() {
$.get('trackid.php', function(data) {
$(".TrackTitle").text(data);
}); 
}
trackid()
setInterval(trackid, 5000);
</script>
<div class="TrackTitle">Loading...</div>

Downside for this method is that it will create a background process on your server for every user because javascript requests output of a PHP file for every user.

这种方法的缺点是,它将为每个用户在服务器上创建一个后台进程,因为javascript请求为每个用户输出一个PHP文件。

Method 2

方法2

You can also set trackid.php to save the output (track name) inside a text file on FTP every 6 seconds:

您还可以设置trackid。php将输出(跟踪名)保存在FTP上的一个文本文件中,每6秒:

<?php
$server = "http://91.121.139.194:8157/stats?sid=1";
$LoopMaximum = 10;
$LoopInitial = 0;
Loop: {
    if ($GLOBALS["LoopInitial"] < $GLOBALS["LoopMaximum"]) {
        $srv_url = urlencode($GLOBALS["server"]);
        $sc_stats = simplexml_load_file($srv_url);
        $node = $sc_stats->SONGTITLE;
        $location = fopen("playing.txt","w+");
        fwrite ($location, $node);
        fclose($location);
        $GLOBALS["LoopInitial"]++;
        sleep(6);
        goto LoopFollow;} else if ($GLOBALS["LoopInitial"] == $GLOBALS["LoopMaximum"]){
        exit();}
}
LoopFollow: {
    if ($GLOBALS["LoopInitial"] < $GLOBALS["LoopMaximum"]) {
        $srv_url = urlencode($GLOBALS["server"]);
        $sc_stats = simplexml_load_file($srv_url);
        $node = $sc_stats->SONGTITLE;
        $location = fopen("playing.txt","w+");
        fwrite ($location, $node);
        fclose($location);
        $GLOBALS["LoopInitial"]++;
        sleep(6);
        goto Loop;} else if ($GLOBALS["LoopInitial"] == $GLOBALS["LoopMaximum"]){
        exit();}
}
?>

Add a CronJob for every minute:

每分钟增加一个CronJob:

php /home/user/public_html/trackid.php >/dev/null 2>&1

Note: The path to PHP may differ for each webhost.

注意:PHP的路径可能因每个web主机而异。

Now read the track from the text file every 5 seconds:

现在每5秒从文本文件中读取轨迹:

<script type="text/javascript">
function trackid() {
var client = new XMLHttpRequest();
client.open('GET', '/playing.txt');
client.onreadystatechange = function() {
var trackName = client.responseText;
$(".TrackTitle").text(trackName);
}
client.send();
}
trackid()
</script>
setInterval(trackid, 5000);
<div class="TrackTitle">Loading...</div>

There is no downside for this method but you need to have access to CronJobs and have at least a minimum of 5 background processes allowed. The track name will be as text on the DIV element. You can format it then with CSS.

这种方法没有缺点,但是您需要访问CronJobs并至少允许5个后台进程。跟踪名将作为DIV元素的文本。你可以用CSS来格式化。

#1


1  

Found an workaround for this. This could be helpful for most of people owning a radio station.

找到了解决办法。这对大多数拥有广播电台的人都有帮助。

I registered my radio station on Internet-Radio. I am not sending you to register your radio station there. You may want to do this with any website you want but make sure that they display every data over HTTPS for this to work.

我在网络电台注册了我的电台。我不会让你在那里注册你的电台。你可能想对任何你想要的网站这样做,但是要确保他们通过HTTPS显示所有的数据。

Most likely they have a proxy to get the data from unsecured HTTP to HTTPS and their entire website is secured. After your radio station is added, search for it on the top search bar and make sure you're only displaying your radio station from your search. This helps file_get_contents to get less HTML, thus loading faster. Get the minimum amount of keywords to display only your radio station, as I did: https://www.internet-radio.com/search/?radio=Riddim+Dubstep+-+Keep

他们很可能有一个代理来从不安全的HTTP获取数据到HTTPS,并且他们的整个网站都是安全的。在你的广播站被添加后,在顶部的搜索栏中搜索它,并确保你只是在你的搜索中显示你的广播站。这有助于file_get_contents获得更少的HTML,从而更快地加载。获取最少的关键字来显示你的广播站,就像我所做的:https://www.internet-radio.com/search/?radio=Riddim+Dubstep+- Keep

Inspect element and find the tag with the track name on it. Right click on it and Copy -> Copy XPath on Chrome, not sure on other browsers. It actually took me some time to find that I can copy the XPath from Right Click -> Inspect...

检查元素并找到带有跟踪名的标记。右击它,复制->复制XPath在Chrome上,不确定在其他浏览器上。实际上,我花了一些时间才发现,我可以从右击->检查中复制XPath…

<?php
libxml_use_internal_errors(false);
$html = file_get_contents('https://www.internet-radio.com/search/?radio=Riddim+Dubstep+-+Keep');
$doc = new DOMDocument;
$doc->loadHTML($html);
$xpath = new DOMXpath($doc);
$node = $xpath->query('/html/body/div[1]/div[1]/div[1]/table/tbody/tr/td[3]/b')->item(0);
echo $node->textContent;
?>

Modify $xpath->query with the XPath you just copyed and the URL with the URL from that page you got the XPath.

修改$xpath->查询的xpath,您只需要复制,并且URL与来自该页面的URL就得到了xpath。

Save this file as

保存这个文件

trackid.php

trackid.php

The following code you will add to your main page.

您将向主页添加以下代码。

<script src="jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
function trackid() {
$.get('trackid.php', function(data) {
$(".TrackTitle").text(data);
}); 
}
trackid()
setInterval(trackid, 5000);
</script>
<div class="TrackTitle">Loading...</div>

The DIV TrackTitlewill be placed where you want the current song to be displayed. You may want to add some CSS to it to format the text to a more well-fitting in page.

DIV tracktitle将放置在您希望显示当前歌曲的位置。您可能想要添加一些CSS到它来格式化文本到一个更合适的页面。

Note: Don't forget to download the latest jquery.min.js from Google's API and update the link to it. I downloaded it on my webhost for faster loading but you can use the direct link to it with no problems.

注意:不要忘记下载最新的jquery.min。来自谷歌API的js,并更新到它的链接。我下载了它在我的webhost更快的加载,但你可以使用直接链接到它没有问题。

#2


1  

If your web hosting provider has the port you use for your Shoutcast station opened, then do what I will explain below. If not, check the other answer below.

如果您的web托管提供者已经打开了您的Shoutcast站点的端口,那么请按照我将在下面解释的那样做。如果没有,检查下面的答案。

Method 1

方法1

Create a file named trackid.php near index.php and put the following code:

创建一个名为trackid的文件。php附近指数。php并放入以下代码:

<?php
$server = "http://91.121.139.194:8157/stats?sid=1";
$srv_url = urlencode($server);
$sc_stats = simplexml_load_file($srv_url);
echo $sc_stats->SONGTITLE
?>

This parses data (song name) from unsecured HTTML to secured HTML by echoit to direct access from a secured connection. Don't forget to replace the IP and Port.

它通过echoit将数据(歌曲名)从不安全的HTTML解析为安全的HTML,以直接从安全的连接进行访问。不要忘记替换IP和端口。

On index.php add this:

在索引。php添加:

<script src="jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
function trackid() {
$.get('trackid.php', function(data) {
$(".TrackTitle").text(data);
}); 
}
trackid()
setInterval(trackid, 5000);
</script>
<div class="TrackTitle">Loading...</div>

Downside for this method is that it will create a background process on your server for every user because javascript requests output of a PHP file for every user.

这种方法的缺点是,它将为每个用户在服务器上创建一个后台进程,因为javascript请求为每个用户输出一个PHP文件。

Method 2

方法2

You can also set trackid.php to save the output (track name) inside a text file on FTP every 6 seconds:

您还可以设置trackid。php将输出(跟踪名)保存在FTP上的一个文本文件中,每6秒:

<?php
$server = "http://91.121.139.194:8157/stats?sid=1";
$LoopMaximum = 10;
$LoopInitial = 0;
Loop: {
    if ($GLOBALS["LoopInitial"] < $GLOBALS["LoopMaximum"]) {
        $srv_url = urlencode($GLOBALS["server"]);
        $sc_stats = simplexml_load_file($srv_url);
        $node = $sc_stats->SONGTITLE;
        $location = fopen("playing.txt","w+");
        fwrite ($location, $node);
        fclose($location);
        $GLOBALS["LoopInitial"]++;
        sleep(6);
        goto LoopFollow;} else if ($GLOBALS["LoopInitial"] == $GLOBALS["LoopMaximum"]){
        exit();}
}
LoopFollow: {
    if ($GLOBALS["LoopInitial"] < $GLOBALS["LoopMaximum"]) {
        $srv_url = urlencode($GLOBALS["server"]);
        $sc_stats = simplexml_load_file($srv_url);
        $node = $sc_stats->SONGTITLE;
        $location = fopen("playing.txt","w+");
        fwrite ($location, $node);
        fclose($location);
        $GLOBALS["LoopInitial"]++;
        sleep(6);
        goto Loop;} else if ($GLOBALS["LoopInitial"] == $GLOBALS["LoopMaximum"]){
        exit();}
}
?>

Add a CronJob for every minute:

每分钟增加一个CronJob:

php /home/user/public_html/trackid.php >/dev/null 2>&1

Note: The path to PHP may differ for each webhost.

注意:PHP的路径可能因每个web主机而异。

Now read the track from the text file every 5 seconds:

现在每5秒从文本文件中读取轨迹:

<script type="text/javascript">
function trackid() {
var client = new XMLHttpRequest();
client.open('GET', '/playing.txt');
client.onreadystatechange = function() {
var trackName = client.responseText;
$(".TrackTitle").text(trackName);
}
client.send();
}
trackid()
</script>
setInterval(trackid, 5000);
<div class="TrackTitle">Loading...</div>

There is no downside for this method but you need to have access to CronJobs and have at least a minimum of 5 background processes allowed. The track name will be as text on the DIV element. You can format it then with CSS.

这种方法没有缺点,但是您需要访问CronJobs并至少允许5个后台进程。跟踪名将作为DIV元素的文本。你可以用CSS来格式化。