aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/youtube-dl.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-02-12 11:47:23 +0100
committerChocobozzz <me@florianbigard.com>2019-02-12 11:47:23 +0100
commitc74c9be934fa1584edf6f4f7a41f00c4d3f2a8b3 (patch)
tree42370ebba95a968b45e59bbc81ae40947b541174 /server/helpers/youtube-dl.ts
parent84929846e743f4b5f3971b386ea2c447db8c416f (diff)
downloadPeerTube-c74c9be934fa1584edf6f4f7a41f00c4d3f2a8b3.tar.gz
PeerTube-c74c9be934fa1584edf6f4f7a41f00c4d3f2a8b3.tar.zst
PeerTube-c74c9be934fa1584edf6f4f7a41f00c4d3f2a8b3.zip
Refractor published date on video import
Diffstat (limited to 'server/helpers/youtube-dl.ts')
-rw-r--r--server/helpers/youtube-dl.ts29
1 files changed, 23 insertions, 6 deletions
diff --git a/server/helpers/youtube-dl.ts b/server/helpers/youtube-dl.ts
index a5ab92df0..782dd2e2e 100644
--- a/server/helpers/youtube-dl.ts
+++ b/server/helpers/youtube-dl.ts
@@ -16,7 +16,7 @@ export type YoutubeDLInfo = {
16 nsfw?: boolean 16 nsfw?: boolean
17 tags?: string[] 17 tags?: string[]
18 thumbnailUrl?: string 18 thumbnailUrl?: string
19 originallyPublishedAt?: string 19 originallyPublishedAt?: Date
20} 20}
21 21
22const processOptions = { 22const processOptions = {
@@ -143,13 +143,33 @@ async function safeGetYoutubeDL () {
143 return youtubeDL 143 return youtubeDL
144} 144}
145 145
146function buildOriginallyPublishedAt (obj: any) {
147 let originallyPublishedAt: Date = null
148
149 const uploadDateMatcher = /^(\d{4})(\d{2})(\d{2})$/.exec(obj.upload_date)
150 if (uploadDateMatcher) {
151 originallyPublishedAt = new Date()
152 originallyPublishedAt.setHours(0, 0, 0, 0)
153
154 const year = parseInt(uploadDateMatcher[1], 10)
155 // Month starts from 0
156 const month = parseInt(uploadDateMatcher[2], 10) - 1
157 const day = parseInt(uploadDateMatcher[3], 10)
158
159 originallyPublishedAt.setFullYear(year, month, day)
160 }
161
162 return originallyPublishedAt
163}
164
146// --------------------------------------------------------------------------- 165// ---------------------------------------------------------------------------
147 166
148export { 167export {
149 updateYoutubeDLBinary, 168 updateYoutubeDLBinary,
150 downloadYoutubeDLVideo, 169 downloadYoutubeDLVideo,
151 getYoutubeDLInfo, 170 getYoutubeDLInfo,
152 safeGetYoutubeDL 171 safeGetYoutubeDL,
172 buildOriginallyPublishedAt
153} 173}
154 174
155// --------------------------------------------------------------------------- 175// ---------------------------------------------------------------------------
@@ -174,9 +194,6 @@ function normalizeObject (obj: any) {
174} 194}
175 195
176function buildVideoInfo (obj: any) { 196function buildVideoInfo (obj: any) {
177
178 const date = obj.upload_date.slice(0,4) + ',' + obj.upload_date.slice(4,6) + ',' + obj.upload_date.slice(6,8)
179
180 return { 197 return {
181 name: titleTruncation(obj.title), 198 name: titleTruncation(obj.title),
182 description: descriptionTruncation(obj.description), 199 description: descriptionTruncation(obj.description),
@@ -185,7 +202,7 @@ function buildVideoInfo (obj: any) {
185 nsfw: isNSFW(obj), 202 nsfw: isNSFW(obj),
186 tags: getTags(obj.tags), 203 tags: getTags(obj.tags),
187 thumbnailUrl: obj.thumbnail || undefined, 204 thumbnailUrl: obj.thumbnail || undefined,
188 originallyPublishedAt: new Date(date).toISOString() 205 originallyPublishedAt: buildOriginallyPublishedAt(obj)
189 } 206 }
190} 207}
191 208