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,gBAAiB,MAAM,QAAU,IAAI,OAChD,EAAS,EAAE,oBAAqB,MAAM,KAAK,QAC3C,GAAQ,EAAE,QAAS,MAAM,QAAU,IAAI,OAI3C,KACI,EAAO,EAAK,MAAM,MAAM,GAAG,OAAO,MAAM,SAEnC,SAAQ,SAAU,GACf,EAAK,QAAQ,MAAQ,EACrB,EAAW,cAAc,GAClB,EAAK,QAAQ,SAAW,EAC/B,GAAW,EAAK,MAAM,GAAI,GACnB,EAAK,QAAQ,OAAS,IAC7B,GAAQ,EAAK,MAAM,GAAI,GACvB,EAAO,KAAK,KAAY,KAAP,GAEzB,GACJ,CAAE,MAAO,GAGT,CAEA,EAAO,KAAK,CACR,MAAO,EACP,OAAQ,EACR,QAAS,EACT,SAAU,EACV,KAAM,EACN,KAAM,IAAI,WAAW,UAAS,WAC1B,IAAI,EAEJ,OAAK,EAaE,OAAO,IAAI,EAAQ,IAZtB,EAAM,IAAI,OAAO,YAEjB,QAAQ,UAAS,WACb,EAAI,KACA,QACA,IAAI,MAAM,yBAElB,IAEO,EAIf,KAER,IAEA,EAAK,KAAM,EACf,GACJ,CACJ,CAtGS,GAwGT,OAAO,QAAU","file":"/npm/mp3skull@1.0.5/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/mp3skull@1.0.5/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","var format = require('util').format,\n    stream = require('stream'),\n\n    cheerio = require('cheerio'),\n    lazystream = require('lazystream'),\n    needle = require('needle');\n\nvar URL = 'https://mp3skull.is/search_db.php?q=%s&fckh=%s';\n\nvar search;\n\n// Convert the minute:seconds format into seconds.\nfunction parseDuration(time) {\n    var seconds;\n\n    time = time.split(':');\n\n    if (time.length !== 2) {\n        return 0;\n    }\n\n    seconds = (+time[0] || 0) * 60;\n    seconds += +time[1] || 0;\n\n    return seconds;\n}\n\nfunction getSession(options, done) {\n    // It's 4kb vs 16kb using an invalid search instead of the homepage to\n    // fetch the session identifier.\n    needle.get(URL, options, function (err, res, body) {\n        var $, session;\n\n        if (err) {\n            return done(err);\n        }\n\n        try {\n            $ = cheerio.load(body);\n            session = $('input[name=\"fckh\"]').attr('value');\n        } catch (e) {\n            return done(e);\n        }\n\n        if (!session) {\n            done(new Error('No session found.'));\n        } else {\n            done(null, session);\n        }\n    });\n}\n\nsearch = (function () {\n    var session;\n\n    return function (terms, options, done) {\n        var url;\n\n        if (!done) {\n            done = options;\n            options = {};\n        }\n\n        // mp3skull changes domains often, so ensure redirects are allowed\n        options.follow_max = 5;\n\n        if (!session) {\n            return getSession(options, function (err, newSession) {\n                if (err) {\n                    return done(err);\n                }\n\n                session = newSession;\n                search(terms, options, done);\n            });\n        }\n\n        url = format(URL, terms, session);\n\n        needle.get(url, options, function (err, res, body) {\n            var $, tracks;\n\n            if (err) {\n                return done(err);\n            }\n\n            if (/session has expired/i.test(body)) {\n                session = undefined;\n                return search(terms, options, done);\n            }\n\n            try {\n                $ = cheerio.load(body);\n            } catch (e) {\n                return done(e);\n            }\n\n            tracks = [];\n\n            $('#song_html').each(function () {\n                var track = ($('#right_song b', this).text() || '').trim(),\n                    direct = $('a[rel=\"nofollow\"]', this).attr('href'),\n                    meta = ($('.left', this).html() || '').trim(),\n\n                    bitrate, duration, size;\n\n                try {\n                    meta = meta.split('\\n')[1].trim().split('<br>');\n\n                    meta.forEach(function (item) {\n                        if (item.indexOf(':') > -1) {\n                            duration = parseDuration(item);\n                        } else if (item.indexOf('kbps') > -1) {\n                            bitrate = +item.slice(0, -4);\n                        } else if (item.indexOf('mb') > -1) {\n                            size = +item.slice(0, -3);\n                            size = Math.ceil(size * 1024);\n                        }\n                    });\n                } catch (e) {\n                    // none of that information was required so we don't care if\n                    // it isn't available.\n                }\n\n                tracks.push({\n                    track: track,\n                    direct: direct,\n                    bitrate: bitrate,\n                    duration: duration,\n                    size: size,\n                    song: new lazystream.Readable(function () {\n                        var out;\n\n                        if (!direct) {\n                            out = new stream.PassThrough();\n\n                            process.nextTick(function () {\n                                out.emit(\n                                    'error',\n                                    new Error('No direct link found.')\n                                );\n                            });\n\n                            return out;\n                        }\n\n                        return needle.get(direct, options);\n                    })\n                });\n            });\n\n            done(null, tracks);\n        });\n    };\n}());\n\nmodule.exports = search;\n"]}