aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/sync-channel.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/sync-channel.ts')
-rw-r--r--server/lib/sync-channel.ts88
1 files changed, 47 insertions, 41 deletions
diff --git a/server/lib/sync-channel.ts b/server/lib/sync-channel.ts
index f91599c14..10167ee38 100644
--- a/server/lib/sync-channel.ts
+++ b/server/lib/sync-channel.ts
@@ -1,7 +1,7 @@
1import { logger } from '@server/helpers/logger' 1import { logger } from '@server/helpers/logger'
2import { YoutubeDLWrapper } from '@server/helpers/youtube-dl' 2import { YoutubeDLWrapper } from '@server/helpers/youtube-dl'
3import { CONFIG } from '@server/initializers/config' 3import { CONFIG } from '@server/initializers/config'
4import { buildYoutubeDLImport } from '@server/lib/video-import' 4import { buildYoutubeDLImport } from '@server/lib/video-pre-import'
5import { UserModel } from '@server/models/user/user' 5import { UserModel } from '@server/models/user/user'
6import { VideoImportModel } from '@server/models/video/video-import' 6import { VideoImportModel } from '@server/models/video/video-import'
7import { MChannel, MChannelAccountDefault, MChannelSync } from '@server/types/models' 7import { MChannel, MChannelAccountDefault, MChannelSync } from '@server/types/models'
@@ -12,8 +12,8 @@ import { ServerConfigManager } from './server-config-manager'
12export async function synchronizeChannel (options: { 12export async function synchronizeChannel (options: {
13 channel: MChannelAccountDefault 13 channel: MChannelAccountDefault
14 externalChannelUrl: string 14 externalChannelUrl: string
15 videosCountLimit: number
15 channelSync?: MChannelSync 16 channelSync?: MChannelSync
16 videosCountLimit?: number
17 onlyAfter?: Date 17 onlyAfter?: Date
18}) { 18}) {
19 const { channel, externalChannelUrl, videosCountLimit, onlyAfter, channelSync } = options 19 const { channel, externalChannelUrl, videosCountLimit, onlyAfter, channelSync } = options
@@ -24,56 +24,62 @@ export async function synchronizeChannel (options: {
24 await channelSync.save() 24 await channelSync.save()
25 } 25 }
26 26
27 const user = await UserModel.loadByChannelActorId(channel.actorId) 27 try {
28 const youtubeDL = new YoutubeDLWrapper( 28 const user = await UserModel.loadByChannelActorId(channel.actorId)
29 externalChannelUrl, 29 const youtubeDL = new YoutubeDLWrapper(
30 ServerConfigManager.Instance.getEnabledResolutions('vod'), 30 externalChannelUrl,
31 CONFIG.TRANSCODING.ALWAYS_TRANSCODE_ORIGINAL_RESOLUTION 31 ServerConfigManager.Instance.getEnabledResolutions('vod'),
32 ) 32 CONFIG.TRANSCODING.ALWAYS_TRANSCODE_ORIGINAL_RESOLUTION
33 )
33 34
34 const targetUrls = await youtubeDL.getInfoForListImport({ latestVideosCount: videosCountLimit }) 35 const targetUrls = await youtubeDL.getInfoForListImport({ latestVideosCount: videosCountLimit })
35 36
36 logger.info( 37 logger.info(
37 'Fetched %d candidate URLs for sync channel %s.', 38 'Fetched %d candidate URLs for sync channel %s.',
38 targetUrls.length, channel.Actor.preferredUsername, { targetUrls } 39 targetUrls.length, channel.Actor.preferredUsername, { targetUrls }
39 ) 40 )
40 41
41 if (targetUrls.length === 0) { 42 if (targetUrls.length === 0) {
42 if (channelSync) { 43 if (channelSync) {
43 channelSync.state = VideoChannelSyncState.SYNCED 44 channelSync.state = VideoChannelSyncState.SYNCED
44 await channelSync.save() 45 await channelSync.save()
46 }
47
48 return
45 } 49 }
46 50
47 return 51 const children: CreateJobArgument[] = []
48 }
49 52
50 const children: CreateJobArgument[] = [] 53 for (const targetUrl of targetUrls) {
54 if (await skipImport(channel, targetUrl, onlyAfter)) continue
51 55
52 for (const targetUrl of targetUrls) { 56 const { job } = await buildYoutubeDLImport({
53 if (await skipImport(channel, targetUrl, onlyAfter)) continue 57 user,
58 channel,
59 targetUrl,
60 channelSync,
61 importDataOverride: {
62 privacy: VideoPrivacy.PUBLIC
63 }
64 })
54 65
55 const { job } = await buildYoutubeDLImport({ 66 children.push(job)
56 user, 67 }
57 channel,
58 targetUrl,
59 channelSync,
60 importDataOverride: {
61 privacy: VideoPrivacy.PUBLIC
62 }
63 })
64
65 children.push(job)
66 }
67 68
68 // Will update the channel sync status 69 // Will update the channel sync status
69 const parent: CreateJobArgument = { 70 const parent: CreateJobArgument = {
70 type: 'after-video-channel-import', 71 type: 'after-video-channel-import',
71 payload: { 72 payload: {
72 channelSyncId: channelSync?.id 73 channelSyncId: channelSync?.id
74 }
73 } 75 }
74 }
75 76
76 await JobQueue.Instance.createJobWithChildren(parent, children) 77 await JobQueue.Instance.createJobWithChildren(parent, children)
78 } catch (err) {
79 logger.error(`Failed to import channel ${channel.name}`, { err })
80 channelSync.state = VideoChannelSyncState.FAILED
81 await channelSync.save()
82 }
77} 83}
78 84
79// --------------------------------------------------------------------------- 85// ---------------------------------------------------------------------------