MCPcopy Create free account
hub / github.com/DialmasterOrg/Youtarr / backfillChannelPosters

Method backfillChannelPosters

server/modules/channelModule.js:976–1018  ·  view source on GitHub ↗

* Backfill poster.jpg files for existing channel folders. * Copies channelthumb to each channel's folder as poster.jpg if it doesn't exist. * @param {Array} channels - Array of channel database records * @returns {Promise }

(channels)

Source from the content-addressed store, hash-verified

974 * @returns {Promise<void>}
975 */
976 async backfillChannelPosters(channels) {
977 try {
978 const config = configModule.getConfig() || {};
979 const shouldWriteChannelPosters = config.writeChannelPosters !== false;
980
981 if (!shouldWriteChannelPosters) {
982 return;
983 }
984
985 const outputDir = configModule.directoryPath;
986 const imageDir = configModule.getImagePath();
987
988 if (!outputDir || !fs.existsSync(outputDir)) {
989 return;
990 }
991
992 for (const channel of channels) {
993 if (!channel.channel_id) continue;
994
995 // Use folder_name (sanitized by yt-dlp) if available, fall back to uploader
996 const channelFolderName = channel.folder_name || channel.uploader;
997 if (!channelFolderName) continue;
998
999 const channelFolderPath = path.join(outputDir, channelFolderName);
1000 const channelPosterPath = path.join(channelFolderPath, 'poster.jpg');
1001
1002 // Check if channel folder exists and poster.jpg doesn't exist
1003 if (fs.existsSync(channelFolderPath) && !fs.existsSync(channelPosterPath)) {
1004 const channelThumbPath = path.join(imageDir, `channelthumb-${channel.channel_id}.jpg`);
1005
1006 if (fs.existsSync(channelThumbPath)) {
1007 try {
1008 fs.copySync(channelThumbPath, channelPosterPath);
1009 } catch (copyErr) {
1010 logger.error({ err: copyErr, channelFolderName }, 'Error backfilling poster for channel');
1011 }
1012 }
1013 }
1014 }
1015 } catch (err) {
1016 logger.error({ err }, 'Error during channel poster backfill');
1017 }
1018 }
1019
1020 /**
1021 * Read all enabled channels from the database.

Callers 4

readChannelsMethod · 0.95
getChannelsPaginatedMethod · 0.95
runCompletionSideEffectsFunction · 0.80

Calls 2

getConfigMethod · 0.80
getImagePathMethod · 0.80

Tested by

no test coverage detected