+function areDifferences (videos1: Video[], videos2: Video[]) {
+ // Remove some keys we don't want to compare
+ videos1.concat(videos2).forEach(video => {
+ delete video.id
+ delete video.isLocal
+ delete video.thumbnailPath
+ delete video.updatedAt
+ delete video.views
+ })
+
+ if (videos1.length !== videos2.length) {
+ return `Videos length are different (${videos1.length}/${videos2.length}).`
+ }
+
+ for (const video1 of videos1) {
+ const video2 = videos2.find(video => video.uuid === video1.uuid)
+
+ if (!video2) return 'Video ' + video1.uuid + ' is missing.'
+
+ for (const videoKey of Object.keys(video1)) {
+ const attribute1 = video1[videoKey]
+ const attribute2 = video2[videoKey]
+
+ if (videoKey === 'tags') {
+ if (attribute1.length !== attribute2.length) {
+ return 'Tags are different.'
+ }
+
+ attribute1.forEach(tag1 => {
+ if (attribute2.indexOf(tag1) === -1) {
+ return 'Tag ' + tag1 + ' is missing.'
+ }
+ })
+ } else if (videoKey === 'files') {
+ if (attribute1.length !== attribute2.length) {
+ return 'Video files are different.'
+ }
+
+ attribute1.forEach((videoFile1: VideoFile) => {
+ const videoFile2: VideoFile = attribute2.find(videoFile => videoFile.magnetUri === videoFile1.magnetUri)
+ if (!videoFile2) {
+ return `Video ${video1.uuid} has missing video file ${videoFile1.magnetUri}.`
+ }
+
+ if (videoFile1.size !== videoFile2.size || videoFile1.resolutionLabel !== videoFile2.resolutionLabel) {
+ return `Video ${video1.uuid} has different video file ${videoFile1.magnetUri}.`
+ }
+ })
+ } else {
+ if (attribute1 !== attribute2) {
+ return `Video ${video1.uuid} has different value for attribute ${videoKey}.`
+ }
+ }
+ }
+ }
+
+ return undefined
+}
+