SoundCloud API PUT method not updating track asset data

六眼飞鱼酱① 提交于 2019-12-08 10:45:19

问题


I can post a new track to soundcloud using their JAVA API Wrapper (I know this is not formally supported) with asset_data and artwork_data and all of the following meta with no issue. When I go to use the update method, it can change everything successfully except for the asset_data (mp3), it even changes the artwork_data. Does anyone have this working in JAVA or any other language. I perused through stackoverflow and SoundClouds example and have't seen one working yet. But it is available as per their developer API documentation. I am a Pro Unlimited User.

POST

@RequestMapping(value = "/submitNewTrack",
    method = RequestMethod.POST,
    produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public ResponseEntity<String> saveNewSCTrack(
    HttpServletRequest req,
    @RequestParam("marketId") String marketId,
    @RequestParam("majorId") String majorId,
    @RequestParam("trackTags") String tags,
    @RequestParam("trackTitle") String title,
    @RequestParam("trackDescription") String description,
    @RequestParam("file") MultipartFile file
) throws IOException {
    ApiWrapper wrapper = new ApiWrapper("client", "secret", null, null);
    wrapper.login("xxxxxx", "xxxxxx");

    HttpResponse resp2 = wrapper.post(Request.to(Endpoints.TRACKS)
        .add(Params.Track.TITLE, title)
        .add(Params.Track.TAG_LIST, tags)
        .add(Params.Track.DESCRIPTION, description)
        .withFile(Params.Track.ASSET_DATA, getFileByteArray(marketId, majorId), title)
        .withFile(Params.Track.ARTWORK_DATA, file.getBytes(), file.getName())
        .setProgressListener(new Request.TransferProgressListener() {
            @Override
            public void transferred(long amount) {
                System.err.print(".");
            }
        }));

    return new ResponseEntity<>("{\"status\":\"ok\"}", HttpStatus.OK);

}

That posts the track successfully.

PUT

@RequestMapping(value = "/updateTrack",
    method = RequestMethod.PUT,
    produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public ResponseEntity<String> updateSCTrack(
    @RequestParam("trackId") Integer id,
    @RequestParam("marketId") String marketId,
    @RequestParam("majorId") String majorId,
    @RequestParam("trackTitle") String title,
    @RequestParam("trackDescription") String description,
    @RequestParam("file") MultipartFile file
) throws IOException {
    ApiWrapper wrapper = new ApiWrapper("client", "secret", null, null);
    wrapper.login("xxxxxx", "xxxxxxxx");

    HttpResponse resp =
        wrapper.put(Request.to(Endpoints.TRACK_DETAILS, id)
            .with(Params.Track.DESCRIPTION, description)
            .withFile(Params.Track.ASSET_DATA, getFileByteArray(marketId, majorId), title)
            .withFile(Params.Track.ARTWORK_DATA, file.getBytes(), file.getOriginalFilename()));

    return new ResponseEntity<>("{\"status\":\"ok\"}", HttpStatus.OK);
}

This method replaces everything in the call with the exception of the track asset data (mp3). And it posts fine with no error. Yet no track is uploaded on the update call. (repeat: post works fine, put does not upload new track).


回答1:


A similar question was asked and answered here. Unfortunately, SoundCloud doesn’t currently provide the ability to update a track’s audio data via the API. One workaround is to delete and then repost the track with the same permalink, however, this will result in losing all stats (e.g. plays), comments, etc. for that track.




回答2:


I understand the frustration you are feeling, esp when you consider all other elements of the track can be updated with the api. To add to the confusion there is no difference in the API documentation btw asset_data and artwork_data, however one support update operations while the other does not via the API.

I suppose there is a rationale behind this but it does not explain why track's audio file can be updated with the web interface. That said & Since the web interface option is available, a workaround would be to leverage HTMLUnit (or something similar) to manually recreate an audio update with code.

The suggested method of deleting and re-creating is not viable bc your metrics are also deleted in the process and there are no export options available.



来源:https://stackoverflow.com/questions/31435256/soundcloud-api-put-method-not-updating-track-asset-data

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!