如何使用spotify API修改jQuery的Radio Player?

时间:2019-03-25 13:12:21

标签: jquery api spotify shoutcast

我需要帮助来更新由Manar Kamel创建的jQuery Kast-非凡的SHOUTcast HTML5 Radio Player for jQuery。

我已经具有Spotify API的客户端ID,客户端密钥和重定向URI。

我已经使用app.js示例进行了身份验证测试,并且一切正常。

我不会说英语,所有Spotify开发人员指南都是英语。 我使用Google翻译。

artwork: function (artist, track, callback) {
            // -- Pull album artwork from spotify API
            // -- or artist artwork as fallback
            // -- or Default art as fallback
            // -- return it

            var that = this,
                ot = this.opt;

            if (Array.isArray && Array.isArray(ot.artwork)) {
                return callback(ot.artwork)
            }

            if (artist === ot.language.unknownArtistText) { // If artist is unknown
                return callback(null)
            }

            var artistC = chaRe(artist),
                trackC = chaRe(track),
                processArtworkX = function (data) { // @retuns images array if found or null
                    var imgAr = null;
                    if (data.tracks && data.tracks.items[0]) {
                        var imagesArrayT = data.tracks.items[0].album.images || '',
                            imgLarge,
                            imgSmall = imagesArrayT[2].url || '';

                        if (that.mobileMedium) { // ** Mobile first :)
                            imgLarge = imagesArrayT[1].url || ''; // ** Medium quailty
                        } else {
                            imgLarge = imagesArrayT[0].url || '';
                        }

                        if (imgLarge && imgSmall) {
                            imgAr = [imgLarge, imgSmall];
                        }
                    } else if (data.artists && data.artists.items[0] && data.artists.items[0].images[0]) {
                        var imagesArrayA = data.artists.items[0].images || '',
                            imgLarge = null,
                            imgSmall = null;

                        if (data.artists.items[0].images.length === 4) { // ** Not normal artist images                       
                            if (that.mobileMedium) { // ** Mobile first :)
                                imgLarge = imagesArrayA[2].url || ''; // ** Medium quailty
                            } else {
                                imgLarge = imagesArrayA[1].url || '';
                            }

                            imgSmall = imagesArrayA[3].url || '';

                        } else {
                            if (that.mobileMedium) { // ** Mobile first :)
                                imgLarge = imagesArrayA[1].url || ''; // ** Medium quailty
                            } else {
                                imgLarge = imagesArrayA[0].url || '';
                            }

                            imgSmall = imagesArrayA[2].url || '';
                        }
                        if (imgLarge && imgSmall) {
                            imgAr = [imgLarge, imgSmall];
                        }
                    }

                    return imgAr
                },
                ajaxArtwork = function (artistN, trackN, noLuck) {
                    var spotifyTrackAPI = 'https://api.spotify.com/v1/search?q=artist:' + artistN + '%20track:' + trackN + '&limit=1&type=track',
                        spotifyArtistAPI = 'https://api.spotify.com/v1/search?q=artist:' + artistN + '&limit=1&type=artist',
                        spotifyAPI = noLuck ? spotifyArtistAPI : spotifyTrackAPI;

                    // Smart pulling
                    XHR({
                        url: spotifyAPI,
                        load: function (data) {
                            var dataJSON = JSON.parse(data);
                            var imgAr = processArtworkX(dataJSON); // @returns artwork array or null
                            if (imgAr) {
                                callback(imgAr)
                            } else {

                                if (noLuck) {
                                    callback(null)
                                } else {
                                    ajaxArtwork(artistN, trackN, true) // ** this time get artist art and if !imgAr return null
                                }

                            }
                        },
                        error: function () {
                            callback(null)
                        }
                    })
                },
                iW = ot.irrelevantWords;

            if (iW) {
                var iWL = iW.length;
                for (var i = 0; i < iWL; i++) {
                    artistC = artistC.replace(iW[i], '')
                    trackC = trackC.replace(iW[i], '')
                }

                ajaxArtwork(artistC, trackC) // smart artwork pulling

            } else {
                ajaxArtwork(artistC, trackC) // smart artwork pulling
            }



            return this
        },

此代码当前不起作用,因为Spotify API需要令牌。

我想知道我必须在此代码中插入内容,以便现在对我有用。

我是菜鸟,但我会尽力的。

感谢您的耐心配合,可以帮助我。

胡安

0 个答案:

没有答案