(jobData = {}, isNextJob = false)
| 162 | } |
| 163 | |
| 164 | async doChannelDownloads(jobData = {}, isNextJob = false) { |
| 165 | const overrideSettings = this.getOverrideSettings(jobData); |
| 166 | const overrideResolution = overrideSettings.resolution || null; |
| 167 | const channelDownloadGrouper = require('./channelDownloadGrouper'); |
| 168 | |
| 169 | try { |
| 170 | const groups = await channelDownloadGrouper.generateDownloadGroups(overrideResolution); |
| 171 | |
| 172 | if (!groups || groups.length === 0) { |
| 173 | // No enabled channels or failed to resolve groups - fall back to single job behavior |
| 174 | return await this.doSingleChannelDownloadJob(jobData, isNextJob); |
| 175 | } |
| 176 | |
| 177 | const effectiveGlobalQuality = |
| 178 | overrideResolution || configModule.config.preferredResolution || '1080'; |
| 179 | |
| 180 | // We need grouping when: |
| 181 | // - Multiple distinct groups exist (different quality or subfolders or filters) |
| 182 | // - Any group has a custom subfolder |
| 183 | // - Any group has a quality that differs from the effective global quality |
| 184 | // - Any group has download filters (duration or title regex) |
| 185 | const needsGrouping = |
| 186 | groups.length > 1 || |
| 187 | groups.some((g) => g.subFolder !== null) || |
| 188 | groups.some((g) => g.quality !== effectiveGlobalQuality) || |
| 189 | groups.some((g) => g.filterConfig && g.filterConfig.hasGroupingCriteria && g.filterConfig.hasGroupingCriteria()); |
| 190 | |
| 191 | if (needsGrouping) { |
| 192 | logger.info({ groupCount: groups.length }, 'Using grouped downloads with resolved settings'); |
| 193 | return await this.doGroupedChannelDownloads(jobData, groups, isNextJob); |
| 194 | } |
| 195 | |
| 196 | // Single group with uniform settings – reuse the existing single-job flow but |
| 197 | // ensure we pass along the resolved quality so overrides are respected. |
| 198 | const singleGroup = groups[0]; |
| 199 | const jobDataWithQuality = { |
| 200 | ...jobData, |
| 201 | effectiveQuality: singleGroup?.quality || effectiveGlobalQuality, |
| 202 | }; |
| 203 | this.setJobDataValue(jobDataWithQuality, 'effectiveQuality', jobDataWithQuality.effectiveQuality); |
| 204 | |
| 205 | return await this.doSingleChannelDownloadJob(jobDataWithQuality, isNextJob); |
| 206 | } catch (err) { |
| 207 | console.error('Error generating channel download groups, falling back to single job:', err); |
| 208 | return await this.doSingleChannelDownloadJob(jobData, isNextJob); |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * Trigger channel downloads, then enqueue auto-download for every enabled |
no test coverage detected