1.3 KiB
1.3 KiB
Audio File Display Name Fix - Complete
Problem Solved
User wanted audio files to show proper "Artist - Title.mp3" names when sent to Telegram, but without changing the saved filename on disk.
Solution Implemented
- Reverted file storage: Files are saved with original format
${videoId}_${title}.mp3 - Custom display filename: Added logic to generate custom filename only for Telegram display
- Modified sendAudioFileInternal(): Now accepts both URLs and file paths, generates custom filename for display
Key Changes in src/bot.ts
- Function now detects if input is URL or file path
- Extracts local file path from URL when needed
- Generates custom display filename:
${performer} - ${title}.mp3 - Uses file options parameter to set custom filename in Telegram
- Maintains backward compatibility with both URL and file path inputs
Technical Details
- Uses node-telegram-bot-api file options:
{ filename: customFilename, contentType: 'audio/mpeg' } - Sanitizes performer and title for safe filename (removes special chars, limits length)
- Fallback: sends as document if audio fails
- Error handling: sends text message with link if all methods fail
Result
- Files stored on disk:
123456_song_title.mp3(unchanged) - Files displayed in Telegram:
Artist Name - Song Title.mp3 - No more "🎵 ..." caption text