+function buildOriginallyPublishedAt (obj: any) {
+ let originallyPublishedAt: Date = null
+
+ const uploadDateMatcher = /^(\d{4})(\d{2})(\d{2})$/.exec(obj.upload_date)
+ if (uploadDateMatcher) {
+ originallyPublishedAt = new Date()
+ originallyPublishedAt.setHours(0, 0, 0, 0)
+
+ const year = parseInt(uploadDateMatcher[1], 10)
+ // Month starts from 0
+ const month = parseInt(uploadDateMatcher[2], 10) - 1
+ const day = parseInt(uploadDateMatcher[3], 10)
+
+ originallyPublishedAt.setFullYear(year, month, day)
+ }
+
+ return originallyPublishedAt
+}
+
+// ---------------------------------------------------------------------------
+
+export {
+ updateYoutubeDLBinary,
+ getYoutubeDLVideoFormat,
+ downloadYoutubeDLVideo,
+ getYoutubeDLSubs,
+ getYoutubeDLInfo,
+ safeGetYoutubeDL,
+ buildOriginallyPublishedAt
+}
+
+// ---------------------------------------------------------------------------
+
+async function guessVideoPathWithExtension (tmpPath: string, sourceExt: string) {
+ if (!isVideoFileExtnameValid(sourceExt)) {
+ throw new Error('Invalid video extension ' + sourceExt)
+ }
+
+ const extensions = [ sourceExt, '.mp4', '.mkv', '.webm' ]
+
+ for (const extension of extensions) {
+ const path = tmpPath + extension
+
+ if (await pathExists(path)) return path
+ }
+
+ throw new Error('Cannot guess path of ' + tmpPath)
+}
+