-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
90 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,31 @@ | ||
import got from 'got' | ||
import { createWriteStream } from 'fs' | ||
|
||
export default async (lrcPath: string, lyricDownloadUrl: string) => { | ||
function convertToStandardTime(timeStr: string) { | ||
const timeInSec = parseFloat(timeStr) | ||
const hours = Math.floor(timeInSec / 3600) | ||
const minutes = Math.floor((timeInSec - hours * 3600) / 60) | ||
const seconds = Math.floor(timeInSec - hours * 3600 - minutes * 60) | ||
const milliseconds = Math.round((timeInSec - Math.floor(timeInSec)) * 100) | ||
|
||
const minutesStr = minutes.toString().padStart(2, '0') | ||
const secondsStr = seconds.toString().padStart(2, '0') | ||
const millisecondsStr = milliseconds.toString().padStart(2, '0') | ||
|
||
return `${minutesStr}:${secondsStr}.${millisecondsStr}` | ||
} | ||
|
||
export default async (lrcPath: string | null, lyricDownloadUrl: string) => { | ||
const { | ||
data: { lrclist }, | ||
} = await got(lyricDownloadUrl).json() | ||
let lyric = '' | ||
for (const lrc of lrclist) { | ||
lyric += `[${lrc.time}] ${lrc.lineLyric}\n` | ||
lyric += `[${convertToStandardTime(lrc.time)}]${lrc.lineLyric}\n` | ||
} | ||
if (lrcPath) { | ||
const lrcFileWriteStream = createWriteStream(lrcPath) | ||
lrcFileWriteStream.write(lyric) | ||
} | ||
const lrcFileWriteStream = createWriteStream(lrcPath) | ||
lrcFileWriteStream.write(lyric) | ||
if (!lrcPath) return lyric | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,20 @@ | ||
import got from 'got' | ||
import { createWriteStream } from 'fs' | ||
|
||
export default async (lrcPath: string, lyricDownloadUrl: string) => { | ||
export default async (lrcPath: string | null, lyricDownloadUrl: string) => { | ||
let lrc, lrcFileWriteStream | ||
const { | ||
lrc: { lyric }, | ||
} = await got(lyricDownloadUrl).json() | ||
const lrcFileWriteStream = createWriteStream(lrcPath) | ||
if (lrcPath) { | ||
lrcFileWriteStream = createWriteStream(lrcPath) | ||
} | ||
if (lyric) { | ||
lrcFileWriteStream.write(lyric) | ||
lrcFileWriteStream?.write(lyric) | ||
lrc = lyric | ||
} else { | ||
lrcFileWriteStream.write(`[00:00.00]${lrcPath.split('.')[0]}`) | ||
lrc = `[00:00.00]${lrcPath?.split('.')[0]}` | ||
lrcFileWriteStream?.write(lrc) | ||
} | ||
if (!lrcPath) return lrc | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8c8de4d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
musicn – ./
musicn-zonemeen.vercel.app
musicn-git-main-zonemeen.vercel.app
musicn-one.vercel.app