(issue: Issue)
| 186 | } |
| 187 | |
| 188 | async function addStream(issue: Issue) { |
| 189 | const log = createThread(issue, 'streams/add') |
| 190 | log.start() |
| 191 | |
| 192 | const data = issue.data |
| 193 | if (data.missing('stream_id')) { |
| 194 | log.error('The request is missing the "Stream ID"') |
| 195 | skippedIssues.add(issue) |
| 196 | return |
| 197 | } |
| 198 | |
| 199 | const streamUrl = data.getString('stream_url') |
| 200 | if (!streamUrl) { |
| 201 | log.error('The request is missing the "Stream URL"') |
| 202 | skippedIssues.add(issue) |
| 203 | return |
| 204 | } |
| 205 | |
| 206 | if (streams.includes((_stream: Stream) => _stream.url === streamUrl)) { |
| 207 | log.error(`The stream with the URL "${streamUrl}" is already included in the playlists`) |
| 208 | skippedIssues.add(issue) |
| 209 | return |
| 210 | } |
| 211 | |
| 212 | const streamId = data.getString('stream_id') || '' |
| 213 | const [channelId, feedId] = streamId.split('@') |
| 214 | |
| 215 | const channel: sdk.Models.Channel | undefined = apiData.channelsKeyById.get(channelId) |
| 216 | if (!channel) { |
| 217 | log.error(`There is no channel with the ID "${channelId}" in the database`) |
| 218 | skippedIssues.add(issue) |
| 219 | return |
| 220 | } |
| 221 | |
| 222 | const blocklistRecords: sdk.Models.BlocklistRecord[] | undefined = |
| 223 | apiData.blocklistRecordsGroupedByChannel.get(channelId) |
| 224 | if (blocklistRecords) { |
| 225 | blocklistRecords.forEach((record: sdk.Models.BlocklistRecord) => { |
| 226 | if (record.reason === 'dmca') { |
| 227 | log.error( |
| 228 | `The channel has been added to our blocklist due to the claims of the copyright holder: ${record.ref}` |
| 229 | ) |
| 230 | } else if (record.reason === 'nsfw') { |
| 231 | log.error(`The channel has been added to our blocklist due to NSFW content: ${record.ref}`) |
| 232 | } |
| 233 | }) |
| 234 | skippedIssues.add(issue) |
| 235 | return |
| 236 | } |
| 237 | |
| 238 | cacheData() |
| 239 | |
| 240 | const httpUserAgent = data.getString('http_user_agent') || null |
| 241 | const httpReferrer = data.getString('http_referrer') || null |
| 242 | |
| 243 | let quality = data.getString('quality') || null |
| 244 | if (!quality) { |
| 245 | const streamInfo = await getStreamInfo(streamUrl, { httpUserAgent, httpReferrer }) |
no test coverage detected