Skip to content

Commit

Permalink
support hi-res
Browse files Browse the repository at this point in the history
  • Loading branch information
Cinvin committed Jun 19, 2022
1 parent f7733d2 commit 02d6660
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 40 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ncm-cloud",
"version": "1.0.0",
"version": "1.0.1",
"main": "dist/main/index.cjs",
"author": "Cinvin",
"license": "MIT",
Expand Down
9 changes: 7 additions & 2 deletions packages/renderer/src/api/cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,18 @@ export function cloudDisk(params:{ limit: number, offset: number, [timestamp: st
/**
* 获取云盘歌曲详情(需要登录)
*/
export function cloudDiskTrackDetail(id: number) {
export function cloudDiskTrackDetail(id: number[]) {
let idstr=''
for (let iditem of id){
idstr+=iditem.toString()+','
}
idstr= idstr.substring(0,idstr.length - 1)
return request({
url: '/user/cloud/detail',
method: 'get',
params: {
timestamp: new Date().getTime(),
id,
id: idstr
},
});
}
Expand Down
19 changes: 13 additions & 6 deletions packages/renderer/src/api/migu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,24 @@ export function songItemformat(song: any) {
artists: song.singer || song.singers,
contentId: song.contentId,
bestQualityformatType: '',
bestQualityUrl: ''
bestQualityUrl: '',
bestQualitySize: '',
bestQualityFileType: '',
};
let resources = song.newRateFormats.map((detail: any) => ({
formatType: detail.formatType,
url: encodeURI(detail.url || detail.androidUrl),
size: Number(detail.androidSize || detail.size),
fileType: detail.androidFileType || detail.fileType,
}))
if (resources.length > 0) {
resources.sort((a: { formatType: string }, b: { formatType: string }) => {
return formatTypePriority(a.formatType) - formatTypePriority(b.formatType)
resources.sort((a: { size:number }, b: { size:number }) => {
// return formatTypePriority(a.formatType) - formatTypePriority(b.formatType)
return b.size - a.size
})
let tageturl = resources[0].url
if (tageturl.startsWith('$')) {
item.bestQualityformatType = resources[0].formatType;

let toneFlag = item.bestQualityformatType
item.bestQualityUrl = `https://app.pd.nf.migu.cn/MIGUM3.0/v1.0/content/sub/listenSong.do?channel=mx&copyrightId=${song.copyrightId}&contentId=${song.contentId}&toneFlag=${toneFlag}&resourceType=${song.resourceType}&userId=15548614588710179085069&netType=00`;
}
Expand All @@ -149,13 +154,15 @@ export function songItemformat(song: any) {
urlObj.protocol = 'http';
urlObj.hostname = 'freetyst.nf.migu.cn';
item.bestQualityUrl = urlObj.href;
item.bestQualityformatType = resources[0].formatType;
}
item.bestQualityformatType = resources[0].formatType;
item.bestQualitySize = resources[0].size;
item.bestQualityFileType = resources[0].fileType;
}
return item
};
function formatTypePriority(formatType: string) {
return ['SQ', 'HQ', 'PQ', 'LQ', 'ZQ'].indexOf(formatType)
return ['ZQ', 'SQ', 'HQ', 'PQ', 'LQ'].indexOf(formatType)
}
function dealSongName(songName: string) {
if (songName.endsWith('曲)') || songName.endsWith('原声带)') || songName.endsWith('背景音乐)')) {
Expand Down
37 changes: 26 additions & 11 deletions packages/renderer/src/components/MiguUpload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Search } from '@element-plus/icons-vue'
import { getSearch } from '../api/search'
import { searchSinger, searchAlbum, searchSong, songItemformat } from '../api/migu'
import { generateSingerTasks, generateAlbumTasks } from '../utils/migu2ncm'
import { uploadSong, cloudDiskTrackMatch } from '../api/cloud'
import { uploadSong, cloudDiskTrackMatch, cloudDiskTrackDelete } from '../api/cloud'
import { useMessageStore } from '../stores/message'
import { useTaskStatusStore } from '../stores/taskStatus'
import { storeToRefs } from 'pinia'
Expand Down Expand Up @@ -87,7 +87,7 @@ let limitOption = reactive({
FLAC: false,
})
let taskListData: { ncmSongId: any; migucontentId: any; miguURL: string; miguformatType: string; songName: any; albumName: any; artists: any; isInCloud: boolean; isNoCopyRight: boolean; isVIP: boolean; status: string; sort: number; progress: number; }[]
let taskListData: { ncmSongId: any; migucontentId: any; miguURL: string; miguformatType: string; miguFileType: string; songName: any; albumName: any; artists: any; isInCloud: boolean; isNoCopyRight: boolean; isVIP: boolean; status: string; sort: number; progress: number; }[]
taskListData = []
let taskList = reactive({
data: taskListData,
Expand Down Expand Up @@ -283,10 +283,11 @@ function handleStart() {
migucontentId: miguSongTaget.songItem.contentId,
miguURL: miguSongTaget.songItem.bestQualityUrl,
miguformatType: miguSongTaget.songItem.bestQualityformatType,
miguFileType: miguSongTaget.songItem.bestQualityFileType,
songName: miguSongTaget.name,
albumName: miguSongTaget.songItem.album.name,
artists: miguSongTaget.songItem.artists.map((a: { name: any }) => { return a.name }).toString(),
isInCloud: false,
isInCloud: true,
isNoCopyRight: false,
isVIP: false,
status: '未开始',
Expand Down Expand Up @@ -330,7 +331,7 @@ async function handleTasks() {
function handleReTryTask(taskItem: any) {
let taskIndex = taskList.data.indexOf(taskItem)
if (taskIndex<0) return
if (taskIndex < 0) return
statusDesc.value = '下载上传ing'
working.value = true
handleTask(taskIndex).finally(() => {
Expand All @@ -343,6 +344,7 @@ function handleTask(taskIndex: number, poolIndex = 0) {
let task = taskList.data[taskIndex]
task.status = '下载中'
task.sort = 2
return axios.get(task.miguURL,
{
responseType: "blob",
Expand All @@ -361,14 +363,17 @@ function handleTask(taskIndex: number, poolIndex = 0) {
task.sort = 4
return poolIndex
}
let content = res.data
let fileName = task.miguformatType == 'SQ' ? `${task.songName}.flac` : `${task.songName}.mp3`
console.log('before fileObj')
let fileObj = new File([content], fileName,{type:content.type})
let fileName = `${task.songName}.${task.miguFileType}`
let fileObj = new File([content], fileName, { type: content.type })
console.log(fileObj)
task.status = '上传中'
task.sort = 1
await uploadSong(fileObj).then((res: any) => {
await uploadSong(fileObj).then(async (res: any) => {
console.log(res)
if (res.code && res.code !== 200 && res.message) {
MessageStore.send(res.message, 'warning')
Expand All @@ -377,10 +382,20 @@ function handleTask(taskIndex: number, poolIndex = 0) {
}
else {
task.status = '已上传'
cloudDiskTrackMatch({ sid: res.privateCloud.songId, asid: task.ncmSongId }).then(() => {
if (res.privateCloud.songId != task.ncmSongId) {
if (task.isInCloud) {
await cloudDiskTrackDelete(task.ncmSongId)
task.isInCloud = false
}
cloudDiskTrackMatch({ sid: res.privateCloud.songId, asid: task.ncmSongId }).then(() => {
task.status = '已完成'
task.sort = 5
})
}
else{
task.status = '已完成'
task.sort = 5
})
task.sort = 5
}
}
// return poolIndex
})
Expand Down
4 changes: 2 additions & 2 deletions packages/renderer/src/components/MyCloud.vue
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ function onClickDelete(songItem: any) {
<div class="song-info">
<img v-if="scope.row.simpleSong.al" :src="scope.row.simpleSong.al.picUrl + '?param=50y50'" class="song-img"
lazy />
<img v-else src="http://p4.music.126.net/UeTuwE7pvjBpypWLudqukA==/3132508627578625.jpg?param=50y50">
<img v-else src="http://p4.music.126.net/UeTuwE7pvjBpypWLudqukA==/3132508627578625.jpg?param=50y50" lazy />
<div class="song-info-cont">
<div class="ellipsis-text">{{ scope.row.simpleSong.name }}</div>
<div class="ellipsis-text">
Expand All @@ -191,7 +191,7 @@ function onClickDelete(songItem: any) {
<!-- <el-table-column prop="simpleSong.al.name" label="专辑" width="180" show-overflow-tooltip/> -->
<el-table-column label="专辑" width="180">
<template #default="scope">
<template v-if="scope.row.simpleSong.al && scope.row.simpleSong.al.id > 0">{{ scope.row.simpleSong.al.name
<template v-if="scope.row.simpleSong.al && scope.row.simpleSong.al.name.length > 0">{{ scope.row.simpleSong.al.name
}}</template>
<template v-else>{{ scope.row.album }}</template>
</template>
Expand Down
98 changes: 80 additions & 18 deletions packages/renderer/src/utils/migu2ncm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,94 @@
import { getAlbum } from '../api/album';
import { getArtistAllSongs } from '../api/artist'
import { getSingerAlbumsSongs,getAlbumSongs } from '../api/migu'
import { cloudDiskTrackDetail } from '../api/cloud'
export function generateSingerTasks(ncmId: number, miguId: string,
limitOption:{CopyRight: boolean,VIP: boolean,FLAC: boolean}) {
let promisencm = getArtistAllSongs(ncmId);
let promisemigu = getSingerAlbumsSongs(miguId)
return Promise.all([promisencm,promisemigu]).then((values)=>{
return Promise.all([promisencm,promisemigu]).then(async (values)=>{
let ncmSongs=values[0]
let miguSongs=values[1]

// console.log(ncmSongs)
// console.log(miguSongs)
//step.1 匹配 去重(如 英雄:英雄和周杰伦的床边故事:英雄 是同一文件(同一contentId))
let matchList=[]
let inCloudList=[]
let inCloudIdList=[]
let contentIdList=[]
for (let ncmSong of ncmSongs){
let find=miguSongs.find((song)=>{
// console.log(song.artists.split('|').sort().toString(),ncmSong.ar.map((artist)=>(artist.name)).sort().toString())
return song.name == ncmSong.name
&& song.album == ncmSong.al.name
&& song.artists.split('|').sort().toString()==ncmSong.ar.map((artist: { name: any; })=>(artist.name)).sort().toString()
})
if (ncmSong.al.name=='Mojito'){
console.log(ncmSong)
console.log(find)
}
if (find){
let findmatch=matchList.find((match)=>{
return match.migucontentId==find?.contentId
let findmatch=contentIdList.find((match)=>{
return match==find?.contentId
})
if (findmatch){
continue
}
else{
contentIdList.push(find.contentId)
}
let matchItem={
ncmSongId:ncmSong.id,
migucontentId:find.contentId,
miguURL:find.bestQualityUrl,
miguformatType:find.bestQualityformatType,
miguFileType:find.bestQualityFileType,
miguSize:find.bestQualitySize,
songName:ncmSong.name,
albumName:ncmSong.al.name,
artists:find.artists,
isInCloud:ncmSong.privilege.cs,
isInCloud:ncmSong.privilege.cs==true,
isNoCopyRight:ncmSong.privilege.st==-200,
isVIP:ncmSong.fee==1 || ncmSong.fee==4,
status:'未开始',
sort:3,
progress:0,
}
matchList.push(matchItem)
if (matchItem.isInCloud){
inCloudList.push(matchItem)
inCloudIdList.push(Number(matchItem.ncmSongId))
}
else{
matchList.push(matchItem)
}
}
}

if (inCloudList.length>0){
let cloudDetailList=await cloudDiskTrackDetail(inCloudIdList)
// console.log(cloudDetailList)
for (let item of cloudDetailList.data){
let taskItem=inCloudList.find((match)=>{
return match.ncmSongId==item.simpleSong.id})
// console.log(item)
// console.log(taskItem)
if (taskItem && taskItem.miguSize>item.fileSize){
matchList.push(taskItem)
}
}
}

// console.log(matchList)
//step.2 过滤
let taskList=[]
for (let item of matchList){
if (item.isInCloud){
continue
}
// if (item.isInCloud){
// continue
// }

if ((limitOption.CopyRight&&item.isNoCopyRight)||
(limitOption.VIP&&item.isVIP)||
(limitOption.FLAC&&item.miguformatType=='SQ')){
(limitOption.FLAC&&item.miguFileType!='mp3')){
taskList.push(item)
}
}
Expand All @@ -65,11 +101,14 @@ export function generateAlbumTasks(ncmId: number, miguId: string,miguresourceTyp
limitOption:{CopyRight: boolean,VIP: boolean,FLAC: boolean}) {
let promisencm = getAlbum(ncmId);
let promisemigu = getAlbumSongs(miguId,miguresourceType)
return Promise.all([promisencm,promisemigu]).then((values:any)=>{
return Promise.all([promisencm,promisemigu]).then(async (values:any)=>{
let ncmSongs=values[0].songs
let miguSongs=values[1]

let matchList=[]
let inCloudList=[]
let inCloudIdList=[]
let contentIdList=[]
for (let ncmSong of ncmSongs){
//已在云盘 跳过
// if(ncmSong.privilege.cs){
Expand All @@ -80,17 +119,22 @@ export function generateAlbumTasks(ncmId: number, miguId: string,miguresourceTyp
&& song.artists.split('|').sort().toString()==ncmSong.ar.map((artist: { name: any; })=>(artist.name)).sort().toString()
})
if (find){
let findmatch=matchList.find((match)=>{
return match.migucontentId==find?.contentId
let findmatch=contentIdList.find((match)=>{
return match==find?.contentId
})
if (findmatch){
continue
}
else{
contentIdList.push(find.contentId)
}
let matchItem={
ncmSongId:ncmSong.id,
migucontentId:find.contentId,
miguURL:find.bestQualityUrl,
miguformatType:find.bestQualityformatType,
miguFileType:find.bestQualityFileType,
miguSize:find.bestQualitySize,
songName:ncmSong.name,
albumName:ncmSong.al.name,
artists:find.artists,
Expand All @@ -101,19 +145,37 @@ export function generateAlbumTasks(ncmId: number, miguId: string,miguresourceTyp
sort:3,
progress:0,
}
matchList.push(matchItem)
if (matchItem.isInCloud){
inCloudList.push(matchItem)
inCloudIdList.push(matchItem.ncmSongId)
}
else{
matchList.push(matchItem)
}
}
}

if (inCloudList.length>0){
let cloudDetailList=await cloudDiskTrackDetail(inCloudIdList)
for (let item of cloudDetailList.data){
let taskItem=inCloudList.find((match)=>{
return match.ncmSongId==item.simpleSong.id})
if (taskItem && taskItem.miguSize>item.fileSize){
matchList.push(taskItem)
}
}
}

// console.log(matchList)
//step.2 过滤
let taskList=[]
for (let item of matchList){
if (item.isInCloud){
continue
}
// if (item.isInCloud){
// continue
// }
if ((limitOption.CopyRight&&item.isNoCopyRight)||
(limitOption.VIP&&item.isVIP)||
(limitOption.FLAC&&item.miguformatType=='SQ')){
(limitOption.FLAC&&item.miguFileType!='mp3')){
taskList.push(item)
}
}
Expand Down

0 comments on commit 02d6660

Please sign in to comment.