mirror of
https://gitlab.com/RemixDev/deemix-js.git
synced 2024-12-29 10:56:18 +00:00
Implemented new url system
This commit is contained in:
parent
facb2a72d1
commit
e2d4a831ec
|
@ -23,6 +23,17 @@ const extensions = {
|
||||||
[TrackFormats.MP4_RA1]: '.mp4'
|
[TrackFormats.MP4_RA1]: '.mp4'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const formatsName = {
|
||||||
|
[TrackFormats.FLAC]: 'FLAC',
|
||||||
|
[TrackFormats.LOCAL]: 'MP3_MISC',
|
||||||
|
[TrackFormats.MP3_320]: 'MP3_320',
|
||||||
|
[TrackFormats.MP3_128]: 'MP3_128',
|
||||||
|
[TrackFormats.DEFAULT]: 'MP3_MISC',
|
||||||
|
[TrackFormats.MP4_RA3]: 'MP4_RA3',
|
||||||
|
[TrackFormats.MP4_RA2]: 'MP4_RA2',
|
||||||
|
[TrackFormats.MP4_RA1]: 'MP4_RA1'
|
||||||
|
}
|
||||||
|
|
||||||
const TEMPDIR = tmpdir()+`/deemix-imgs`
|
const TEMPDIR = tmpdir()+`/deemix-imgs`
|
||||||
fs.mkdirSync(TEMPDIR, { recursive: true })
|
fs.mkdirSync(TEMPDIR, { recursive: true })
|
||||||
|
|
||||||
|
@ -89,8 +100,10 @@ async function getPreferredBitrate(track, bitrate, shouldFallback, uuid, listene
|
||||||
async function testBitrate(track, formatNumber, formatName){
|
async function testBitrate(track, formatNumber, formatName){
|
||||||
let request
|
let request
|
||||||
try {
|
try {
|
||||||
|
if (!track.urls[formatName])
|
||||||
|
track.urls[formatName] = generateCryptedStreamURL(track.id, track.MD5, track.mediaVersion, formatNumber)
|
||||||
request = got.get(
|
request = got.get(
|
||||||
generateCryptedStreamURL(track.id, track.MD5, track.mediaVersion, formatNumber),
|
track.urls[formatName],
|
||||||
{ headers: {'User-Agent': USER_AGENT_HEADER}, timeout: 30000 }
|
{ headers: {'User-Agent': USER_AGENT_HEADER}, timeout: 30000 }
|
||||||
).on("response", (response)=>{
|
).on("response", (response)=>{
|
||||||
track.filesizes[`FILESIZE_${formatName}`] = response.headers["content-length"]
|
track.filesizes[`FILESIZE_${formatName}`] = response.headers["content-length"]
|
||||||
|
@ -409,7 +422,9 @@ class Downloader {
|
||||||
|
|
||||||
// Download the track
|
// Download the track
|
||||||
if (!trackAlreadyDownloaded || this.settings.overwriteFile == OverwriteOption.OVERWRITE){
|
if (!trackAlreadyDownloaded || this.settings.overwriteFile == OverwriteOption.OVERWRITE){
|
||||||
track.downloadURL = generateCryptedStreamURL(track.id, track.MD5, track.mediaVersion, track.bitrate)
|
if (!track.urls[formatsName[track.bitrate]])
|
||||||
|
track.urls[formatsName[track.bitrate]] = generateCryptedStreamURL(track.id, track.MD5, track.mediaVersion, track.bitrate)
|
||||||
|
track.downloadURL = track.urls[formatsName[track.bitrate]]
|
||||||
let stream = fs.createWriteStream(writepath)
|
let stream = fs.createWriteStream(writepath)
|
||||||
try {
|
try {
|
||||||
await streamTrack(stream, track, 0, this.downloadObject, this.listener)
|
await streamTrack(stream, track, 0, this.downloadObject, this.listener)
|
||||||
|
@ -478,6 +493,7 @@ class Downloader {
|
||||||
this.warn(itemData, e.errid, 'fallback')
|
this.warn(itemData, e.errid, 'fallback')
|
||||||
let newTrack = await this.dz.gw.get_track_with_fallback(track.fallbackID)
|
let newTrack = await this.dz.gw.get_track_with_fallback(track.fallbackID)
|
||||||
track.parseEssentialData(newTrack)
|
track.parseEssentialData(newTrack)
|
||||||
|
await track.retriveTrackURLs(this.dz)
|
||||||
await track.retriveFilesizes(this.dz)
|
await track.retriveFilesizes(this.dz)
|
||||||
return await this.downloadWrapper(extraData, track)
|
return await this.downloadWrapper(extraData, track)
|
||||||
}
|
}
|
||||||
|
@ -487,6 +503,7 @@ class Downloader {
|
||||||
if (searchedID != "0"){
|
if (searchedID != "0"){
|
||||||
let newTrack = await this.dz.gw.get_track_with_fallback(searchedID)
|
let newTrack = await this.dz.gw.get_track_with_fallback(searchedID)
|
||||||
track.parseEssentialData(newTrack)
|
track.parseEssentialData(newTrack)
|
||||||
|
await track.retriveTrackURLs(this.dz)
|
||||||
await track.retriveFilesizes(this.dz)
|
await track.retriveFilesizes(this.dz)
|
||||||
track.searched = true
|
track.searched = true
|
||||||
if (this.listener) this.listener.send('queueUpdate', {
|
if (this.listener) this.listener.send('queueUpdate', {
|
||||||
|
|
|
@ -22,6 +22,7 @@ class Track {
|
||||||
this.title = "",
|
this.title = "",
|
||||||
this.MD5 = ""
|
this.MD5 = ""
|
||||||
this.mediaVersion = ""
|
this.mediaVersion = ""
|
||||||
|
this.trackToken = ""
|
||||||
this.duration = 0
|
this.duration = 0
|
||||||
this.fallbackID = "0"
|
this.fallbackID = "0"
|
||||||
this.filesizes = {}
|
this.filesizes = {}
|
||||||
|
@ -48,18 +49,20 @@ class Track {
|
||||||
this.artistsString = ""
|
this.artistsString = ""
|
||||||
this.mainArtistsString = ""
|
this.mainArtistsString = ""
|
||||||
this.featArtistsString = ""
|
this.featArtistsString = ""
|
||||||
|
this.urls = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
parseEssentialData(trackAPI_gw, trackAPI){
|
parseEssentialData(trackAPI_gw, trackAPI){
|
||||||
this.id = String(trackAPI_gw.SNG_ID)
|
this.id = String(trackAPI_gw.SNG_ID)
|
||||||
this.duration = trackAPI_gw.DURATION
|
this.duration = trackAPI_gw.DURATION
|
||||||
|
this.trackToken = trackAPI_gw.TRACK_TOKEN
|
||||||
this.MD5 = trackAPI_gw.MD5_ORIGIN
|
this.MD5 = trackAPI_gw.MD5_ORIGIN
|
||||||
if (!this.MD5){
|
if (!this.MD5){
|
||||||
if (trackAPI && trackAPI.md5_origin){
|
if (trackAPI && trackAPI.md5_origin){
|
||||||
this.MD5 = trackAPI.md5_origin
|
this.MD5 = trackAPI.md5_origin
|
||||||
}else{
|
}/*else{
|
||||||
throw new MD5NotFound
|
throw new MD5NotFound
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
this.mediaVersion = trackAPI_gw.MEDIA_VERSION
|
this.mediaVersion = trackAPI_gw.MEDIA_VERSION
|
||||||
this.fallbackID = "0"
|
this.fallbackID = "0"
|
||||||
|
@ -113,6 +116,7 @@ class Track {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.parseEssentialData(trackAPI_gw, trackAPI)
|
this.parseEssentialData(trackAPI_gw, trackAPI)
|
||||||
|
this.retriveTrackURLs(dz)
|
||||||
|
|
||||||
if (this.localTrack){
|
if (this.localTrack){
|
||||||
this.parseLocalTrackData(trackAPI_gw)
|
this.parseLocalTrackData(trackAPI_gw)
|
||||||
|
@ -255,6 +259,14 @@ class Track {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async retriveTrackURLs(dz){
|
||||||
|
let urls = await dz.get_tracks_urls(this.trackToken)
|
||||||
|
this.urls = {}
|
||||||
|
urls[0].media.forEach(url => {
|
||||||
|
this.urls[url.format] = url.sources[0].url
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
removeDuplicateArtists(){
|
removeDuplicateArtists(){
|
||||||
[this.artist, this.artists] = removeDuplicateArtists(this.artist, this.artists)
|
[this.artist, this.artists] = removeDuplicateArtists(this.artist, this.artists)
|
||||||
}
|
}
|
||||||
|
@ -393,5 +405,8 @@ class AlbumDoesntExists extends TrackError {
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
Track,
|
Track,
|
||||||
|
TrackError,
|
||||||
|
MD5NotFound,
|
||||||
|
NoDataToParse,
|
||||||
AlbumDoesntExists
|
AlbumDoesntExists
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue