Soundcloud嵌入流URL(Node,JSON) [英] Soundcloud embed stream URL (Node, JSON)

查看:157
本文介绍了Soundcloud嵌入流URL(Node,JSON)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用Node来抓取一个将所选数据存储在JSON文件中的博客。当从Soundcloud中抓取包含嵌入式轨道的博客文章时,我似乎只能收集iframe src而不是实际的跟踪链接(声音云链接或流链接)。



当我刮掉iframe src网址时,我似乎只能获得以下格式的链接:
https://w.soundcloud.com/player/?url=https% 3A // api.soundcloud.com / tracks / 120261008& color = 000000& auto_play = false& show_artwork = false



如果我不能刮掉轨道网址有没有办法让我能够操纵上面的链接如何存储到数组中?为了使这个链接可用,我只需要存储url = https%3A // api.soundcloud.com / tracks / 120261008(减去url =)。



<然而,问题是%3A需要替换为:



操作网址以获得所需输出网址的最佳方式是什么?存储或被调用时?

解决方案

我不确定你计划如何处理跟踪网址一旦你拥有它,但要获得轨道/播放列表的永久链接URL,你需要一个两步的方法。首先,您需要解析iframe src中查询字符串中的 url 参数:

  CLIENT_ID ='client_id = b45b1aa10f1ac2941910a7f0d10f8e28'; 
var src ='https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/120261008&color=000000&auto_play=false&show_artwork=false' ,
match = src.match(/ url =([^&] *)/),
resource = match [0],
stream = decodeURIComponent(match [1])+ '/流/?' + CLIENT_ID;

然后你需要向SoundCloud的解析API发出HTTP请求以实际转换该资源进入固定链接URL:

  var url ='http://api.soundcloud.com/resolve.json?'+ resources + '&安培;' + CLIENT_ID; 
var xhr = new XMLHttpRequest();
xhr.open('GET',url,true);
xhr.onload = function(){
var data = JSON.parse(xhr.responseText);
//使用数据执行某些操作
console.log(data.permalink_url);
};
xhr.send();


I'm currently using Node to scrape a blog that stores selected data in a JSON file. When scraping a blog post that contains an embedded track from Soundcloud I seem to only be able to collect the iframe src and not that actual track link (either soundcloud link or stream link).

When I scrape the iframe src url I seem to only be able to get a link that's in the following format: https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/120261008&color=000000&auto_play=false&show_artwork=false

If I'm not able to scrape the track URL is there a way I'm able to manipulate how the above link is stored into the array? In order for this link to be usable I need to only store the url=https%3A//api.soundcloud.com/tracks/120261008 (minus the url=).

But then the problem with this is that the %3A needs replacing to a :

What's the best way to manipulate the url to achieve the desired output url either when it's being stored or when it's being called?

解决方案

I'm not exactly sure what you're planning on doing with the track URL once you have it, but to get the permalink URL for a track/playlist your going to need a two step approach. First you're going to need to parse the url parameter in the query string in the iframe src:

CLIENT_ID = 'client_id=b45b1aa10f1ac2941910a7f0d10f8e28';
var src = 'https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/120261008&color=000000&auto_play=false&show_artwork=false',
    match = src.match(/url=([^&]*)/),
    resource = match[0],
    stream = decodeURIComponent(match[1])+'/stream/?'+CLIENT_ID;

Then you're going to need to make an HTTP request to SoundCloud's resolve API to actually convert that resource into the permalink URL:

var url = 'http://api.soundcloud.com/resolve.json?'+resource+'&'+CLIENT_ID;
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onload = function(){
  var data = JSON.parse(xhr.responseText);
  // do something with the data
  console.log(data.permalink_url);
};
xhr.send();

这篇关于Soundcloud嵌入流URL(Node,JSON)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆