]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix HLS transcoding
authorChocobozzz <me@florianbigard.com>
Thu, 1 Aug 2019 12:19:18 +0000 (14:19 +0200)
committerChocobozzz <me@florianbigard.com>
Thu, 1 Aug 2019 12:19:18 +0000 (14:19 +0200)
server/lib/activitypub/process/process-dislike.ts
server/lib/activitypub/process/process-like.ts
server/lib/activitypub/process/process-undo.ts
server/lib/video-transcoding.ts
server/models/video/video.ts

index ed8afd3d2608a0fdb0f74719b985fae3ba92b558..c46180617414f426b8c798a7bb8c49fa4ce3c38d 100644 (file)
@@ -43,6 +43,10 @@ async function processDislike (activity: ActivityCreate | ActivityDislike, byAct
 
     await video.increment('dislikes', { transaction: t })
 
+    if (existingRate && existingRate.type === 'like') {
+      await video.decrement('likes', { transaction: t })
+    }
+
     if (video.isOwned()) {
       // Don't resend the activity to the sender
       const exceptions = [ byActor ]
index 8b97aae556bd985e9b2747f8d953bf239ba83564..5b2ab4b6614a4e25b0666586672f689706b10a48 100644 (file)
@@ -43,6 +43,10 @@ async function processLikeVideo (byActor: ActorModel, activity: ActivityLike) {
 
     await video.increment('likes', { transaction: t })
 
+    if (existingRate && existingRate.type === 'dislike') {
+      await video.decrement('dislikes', { transaction: t })
+    }
+
     if (video.isOwned()) {
       // Don't resend the activity to the sender
       const exceptions = [ byActor ]
index 2d48848fe7ec95daff18d787bb770dc8c0196012..692c51904305aed542fc6c6b0d9fbcadbb1b2650 100644 (file)
@@ -59,9 +59,8 @@ async function processUndoLike (byActor: ActorModel, activity: ActivityUndo) {
   return sequelizeTypescript.transaction(async t => {
     if (!byActor.Account) throw new Error('Unknown account ' + byActor.url)
 
-    let rate = await AccountVideoRateModel.loadByUrl(likeActivity.id, t)
-    if (!rate) rate = await AccountVideoRateModel.load(byActor.Account.id, video.id, t)
-    if (!rate) throw new Error(`Unknown rate by account ${byActor.Account.id} for video ${video.id}.`)
+    const rate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byActor.Account.id, video.id, likeActivity.id, t)
+    if (!rate || rate.type !== 'like') throw new Error(`Unknown like by account ${byActor.Account.id} for video ${video.id}.`)
 
     await rate.destroy({ transaction: t })
     await video.decrement('likes', { transaction: t })
@@ -85,9 +84,8 @@ async function processUndoDislike (byActor: ActorModel, activity: ActivityUndo)
   return sequelizeTypescript.transaction(async t => {
     if (!byActor.Account) throw new Error('Unknown account ' + byActor.url)
 
-    let rate = await AccountVideoRateModel.loadByUrl(dislike.id, t)
-    if (!rate) rate = await AccountVideoRateModel.load(byActor.Account.id, video.id, t)
-    if (!rate) throw new Error(`Unknown rate by account ${byActor.Account.id} for video ${video.id}.`)
+    const rate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byActor.Account.id, video.id, dislike.id, t)
+    if (!rate || rate.type !== 'dislike') throw new Error(`Unknown dislike by account ${byActor.Account.id} for video ${video.id}.`)
 
     await rate.destroy({ transaction: t })
     await video.decrement('dislikes', { transaction: t })
index 8d786e0ef5ea5ba16e7f79e96557072dbc4af98b..ba6b29163c880c4ec3fb8bbfe2b2bf74abed89c4 100644 (file)
@@ -121,7 +121,7 @@ async function generateHlsPlaylist (video: VideoModel, resolution: VideoResoluti
   const baseHlsDirectory = join(HLS_STREAMING_PLAYLIST_DIRECTORY, video.uuid)
   await ensureDir(join(HLS_STREAMING_PLAYLIST_DIRECTORY, video.uuid))
 
-  const videoInputPath = join(CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename(video.getOriginalFile()))
+  const videoInputPath = join(CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename(video.getFile(resolution)))
   const outputPath = join(baseHlsDirectory, VideoStreamingPlaylistModel.getHlsPlaylistFilename(resolution))
 
   const transcodeOptions = {
index 05d625fc18a54e8ab7a560ec656fa6f027bfd286..ae29cf2868c4a87e9e6ac4df6bf5133c26dc7d46 100644 (file)
@@ -36,7 +36,7 @@ import {
   Table,
   UpdatedAt
 } from 'sequelize-typescript'
-import { UserRight, VideoPrivacy, VideoState } from '../../../shared'
+import { UserRight, VideoPrivacy, VideoResolution, VideoState } from '../../../shared'
 import { VideoTorrentObject } from '../../../shared/models/activitypub/objects'
 import { Video, VideoDetails, VideoFile } from '../../../shared/models/videos'
 import { VideoFilter } from '../../../shared/models/videos/video-query.type'
@@ -1753,6 +1753,12 @@ export class VideoModel extends Model<VideoModel> {
     return maxBy(this.VideoFiles, file => file.resolution)
   }
 
+  getFile (resolution: VideoResolution) {
+    if (Array.isArray(this.VideoFiles) === false) return undefined
+
+    return this.VideoFiles.find(f => f.resolution === resolution)
+  }
+
   async addAndSaveThumbnail (thumbnail: ThumbnailModel, transaction: Transaction) {
     thumbnail.videoId = this.id