Fix #639 providing magnet URI in player and download modal
authorRigel Kent <sendmemail@rigelk.eu>
Fri, 22 Jun 2018 14:29:01 +0000 (16:29 +0200)
committerChocobozzz <me@florianbigard.com>
Sun, 24 Jun 2018 15:42:05 +0000 (17:42 +0200)
client/src/app/videos/+video-watch/modal/video-download.component.html
client/src/app/videos/+video-watch/modal/video-download.component.ts
client/src/assets/player/peertube-player.ts

index d30a49345dc9ae2a4b3aed56efc487683bcedc3d..316bd635cb2055d8c179db6933265bd995b600ee 100644 (file)
             <input type="radio" name="download" id="download-direct" [(ngModel)]="downloadType" value="direct">
             <label i18n for="download-direct">Direct download</label>
           </div>
+
+          <div class="peertube-radio-container">
+            <input type="radio" name="download" id="download-magnet" [(ngModel)]="downloadType" value="magnet">
+            <label i18n for="download-magnet">Torrent (magnet)</label>
+          </div>
         </div>
 
         <div class="form-group inputs">
index 12f31b011a093fbbd6e0916b1b3eb12263edfb9c..2de706e47a707bd0b253f22aa4ca28b60e088fac 100644 (file)
@@ -12,7 +12,7 @@ export class VideoDownloadComponent implements OnInit {
 
   @ViewChild('modal') modal: ModalDirective
 
-  downloadType: 'direct' | 'torrent' = 'torrent'
+  downloadType: 'direct' | 'torrent' | 'magnet' = 'torrent'
   resolutionId: number | string = -1
 
   constructor () {
@@ -41,7 +41,19 @@ export class VideoDownloadComponent implements OnInit {
       return
     }
 
-    const link = this.downloadType === 'direct' ? file.fileDownloadUrl : file.torrentDownloadUrl
+    const link = (() => {
+      switch (this.downloadType) {
+        case 'direct': {
+          return file.fileDownloadUrl
+        }
+        case 'torrent': {
+          return file.torrentDownloadUrl
+        }
+        case 'magnet': {
+          return file.magnetUri
+        }
+      }
+    })()
     window.location.assign(link)
   }
 }
index 6b8bba21199de1c518a2e2653bf4f812c0c5ccd6..7c9a43ed97b8425ec1374530ae1ccf00982a891e 100644 (file)
@@ -143,6 +143,13 @@ function addContextMenu (player: any, videoEmbedUrl: string) {
         listener: () => {
           copyToClipboard(buildVideoEmbed(videoEmbedUrl))
         }
+      },
+      {
+        label: player.localize('Copy magnet URI'),
+        listener: function () {
+          const player = this
+          copyToClipboard(player.peertube().getCurrentVideoFile().magnetUri)
+        }
       }
     ]
   })