(query: string, savePath: string)
| 148 | const searchUrl = `https://itunes.apple.com/search?term=${encodeURIComponent(query)}&entity=song&limit=1`; |
| 149 | const { data } = await axios.get(searchUrl); |
| 150 | if (data.results && data.results.length > 0) { |
| 151 | let imageUrl = data.results[0].artworkUrl100; |
| 152 | if (imageUrl) { |
| 153 | imageUrl = imageUrl.replace('100x100bb.jpg', '600x600bb.jpg'); |
| 154 | const response = await axios.get(imageUrl, { responseType: 'stream' }); |
| 155 | const writer = fs.createWriteStream(savePath); |
| 156 | response.data.pipe(writer); |
| 157 | return new Promise((resolve, reject) => { |
| 158 | writer.on('finish', () => resolve(true)); |
| 159 | writer.on('error', () => reject(false)); |
| 160 | }); |
| 161 | } |
| 162 | } |
| 163 | } catch (error) { |
| 164 | console.error("Cover search failed:", error); |
| 165 | } |
| 166 | return false; |
| 167 | } |
| 168 | |
| 169 | // --- Main Converter Class --- |
| 170 | class VideoConverter { |
| 171 | public readonly tempDir: string; |
| 172 | |
| 173 | constructor() { |
| 174 | this.tempDir = path.join(process.cwd(), "temp", "convert"); |
no test coverage detected