diff options
Diffstat (limited to 'server/lib/sync-channel.ts')
-rw-r--r-- | server/lib/sync-channel.ts | 90 |
1 files changed, 48 insertions, 42 deletions
diff --git a/server/lib/sync-channel.ts b/server/lib/sync-channel.ts index f91599c14..35af91429 100644 --- a/server/lib/sync-channel.ts +++ b/server/lib/sync-channel.ts | |||
@@ -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 | const targetUrls = await youtubeDL.getInfoForListImport({ latestVideosCount: videosCountLimit }) | ||
35 | |||
36 | logger.info( | ||
37 | 'Fetched %d candidate URLs for sync channel %s.', | ||
38 | targetUrls.length, channel.Actor.preferredUsername, { targetUrls } | ||
39 | ) | ||
40 | |||
41 | if (targetUrls.length === 0) { | ||
42 | if (channelSync) { | ||
43 | channelSync.state = VideoChannelSyncState.SYNCED | ||
44 | await channelSync.save() | ||
45 | } | ||
46 | |||
47 | return | ||
48 | } | ||
49 | 34 | ||
50 | const children: CreateJobArgument[] = [] | 35 | const targetUrls = await youtubeDL.getInfoForListImport({ latestVideosCount: videosCountLimit }) |
51 | 36 | ||
52 | for (const targetUrl of targetUrls) { | 37 | logger.info( |
53 | if (await skipImport(channel, targetUrl, onlyAfter)) continue | 38 | 'Fetched %d candidate URLs for sync channel %s.', |
39 | targetUrls.length, channel.Actor.preferredUsername, { targetUrls } | ||
40 | ) | ||
54 | 41 | ||
55 | const { job } = await buildYoutubeDLImport({ | 42 | if (targetUrls.length === 0) { |
56 | user, | 43 | if (channelSync) { |
57 | channel, | 44 | channelSync.state = VideoChannelSyncState.SYNCED |
58 | targetUrl, | 45 | await channelSync.save() |
59 | channelSync, | ||
60 | importDataOverride: { | ||
61 | privacy: VideoPrivacy.PUBLIC | ||
62 | } | 46 | } |
63 | }) | ||
64 | 47 | ||
65 | children.push(job) | 48 | return |
66 | } | 49 | } |
50 | |||
51 | const children: CreateJobArgument[] = [] | ||
52 | |||
53 | for (const targetUrl of targetUrls) { | ||
54 | if (await skipImport(channel, targetUrl, onlyAfter)) continue | ||
67 | 55 | ||
68 | // Will update the channel sync status | 56 | const { job } = await buildYoutubeDLImport({ |
69 | const parent: CreateJobArgument = { | 57 | user, |
70 | type: 'after-video-channel-import', | 58 | channel, |
71 | payload: { | 59 | targetUrl, |
72 | channelSyncId: channelSync?.id | 60 | channelSync, |
61 | importDataOverride: { | ||
62 | privacy: VideoPrivacy.PUBLIC | ||
63 | } | ||
64 | }) | ||
65 | |||
66 | children.push(job) | ||
73 | } | 67 | } |
74 | } | ||
75 | 68 | ||
76 | await JobQueue.Instance.createJobWithChildren(parent, children) | 69 | // Will update the channel sync status |
70 | const parent: CreateJobArgument = { | ||
71 | type: 'after-video-channel-import', | ||
72 | payload: { | ||
73 | channelSyncId: channelSync?.id | ||
74 | } | ||
75 | } | ||
76 | |||
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 | // --------------------------------------------------------------------------- |