Add ability to download a video from direct link or torrent file

This commit is contained in:
Chocobozzz
2017-10-19 14:58:28 +02:00
parent bda65bdc9f
commit a96aed1518
13 changed files with 123 additions and 86 deletions

View File

@@ -0,0 +1,30 @@
<div bsModal #modal="bs-modal" class="modal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content modal-lg">
<div class="modal-header">
<button type="button" class="close" aria-label="Close" (click)="hide()">
<span aria-hidden="true">&times;</span>
</button>
<h4 class="modal-title">Download</h4>
</div>
<div class="modal-body">
<div *ngFor="let file of video.files" class="resolution-block">
<label>{{ file.resolutionLabel }}</label>
<a class="btn btn-default " target="_blank" [href]="file.torrentUrl">
<span class="glyphicon glyphicon-download"></span>
Torrent file
</a>
<a class="btn btn-default" target="_blank" [href]="file.fileUrl">
<span class="glyphicon glyphicon-download"></span>
Download
</a>
<!-- Don't display magnet URI for now, this is not compatible with most torrent clients -->
<!--<input #magnetUriInput (click)="magnetUriInput.select()" type="text" class="form-control input-sm readonly" readonly [value]="file.magnetUri" />-->
</div>
</div>
</div>
</div>
</div>

View File

@@ -5,10 +5,11 @@ import { ModalDirective } from 'ngx-bootstrap/modal'
import { Video } from '../shared'
@Component({
selector: 'my-video-magnet',
templateUrl: './video-magnet.component.html'
selector: 'my-video-download',
templateUrl: './video-download.component.html',
styles: [ '.resolution-block { margin-top: 20px; }' ]
})
export class VideoMagnetComponent {
export class VideoDownloadComponent {
@Input() video: Video = null
@ViewChild('modal') modal: ModalDirective

View File

@@ -1,20 +0,0 @@
<div bsModal #modal="bs-modal" class="modal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content modal-lg">
<div class="modal-header">
<button type="button" class="close" aria-label="Close" (click)="hide()">
<span aria-hidden="true">&times;</span>
</button>
<h4 class="modal-title">Magnet Uri</h4>
</div>
<div class="modal-body">
<div *ngFor="let file of video.files">
<label>{{ file.resolutionLabel }}</label>
<input #magnetUriInput (click)="magnetUriInput.select()" type="text" class="form-control input-sm readonly" readonly [value]="file.magnetUri" />
</div>
</div>
</div>
</div>
</div>

View File

@@ -71,8 +71,8 @@
</li>
<li role="menuitem">
<a class="dropdown-item" title="Get magnet URI" href="#" (click)="showMagnetUriModal($event)">
<span class="glyphicon glyphicon-magnet"></span> Magnet
<a class="dropdown-item" title="Download the video" href="#" (click)="showDownloadModal($event)">
<span class="glyphicon glyphicon-download-alt"></span> Download
</a>
</li>
@@ -179,6 +179,6 @@
<ng-template [ngIf]="video !== null">
<my-video-share #videoShareModal [video]="video"></my-video-share>
<my-video-magnet #videoMagnetModal [video]="video"></my-video-magnet>
<my-video-download #videoDownloadModal [video]="video"></my-video-download>
<my-video-report #videoReportModal [video]="video"></my-video-report>
</ng-template>

View File

@@ -10,7 +10,7 @@ import { MetaService } from '@ngx-meta/core'
import { NotificationsService } from 'angular2-notifications'
import { AuthService, ConfirmService } from '../../core'
import { VideoMagnetComponent } from './video-magnet.component'
import { VideoDownloadComponent } from './video-download.component'
import { VideoShareComponent } from './video-share.component'
import { VideoReportComponent } from './video-report.component'
import { Video, VideoService } from '../shared'
@@ -23,7 +23,7 @@ import { UserVideoRateType, VideoRateType } from '../../../../../shared'
styleUrls: [ './video-watch.component.scss' ]
})
export class VideoWatchComponent implements OnInit, OnDestroy {
@ViewChild('videoMagnetModal') videoMagnetModal: VideoMagnetComponent
@ViewChild('videoDownloadModal') videoDownloadModal: VideoDownloadComponent
@ViewChild('videoShareModal') videoShareModal: VideoShareComponent
@ViewChild('videoReportModal') videoReportModal: VideoReportComponent
@@ -160,9 +160,9 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
this.videoShareModal.show()
}
showMagnetUriModal (event: Event) {
showDownloadModal (event: Event) {
event.preventDefault()
this.videoMagnetModal.show()
this.videoDownloadModal.show()
}
isUserLoggedIn () {

View File

@@ -7,7 +7,7 @@ import { SharedModule } from '../../shared'
import { VideoWatchComponent } from './video-watch.component'
import { VideoReportComponent } from './video-report.component'
import { VideoShareComponent } from './video-share.component'
import { VideoMagnetComponent } from './video-magnet.component'
import { VideoDownloadComponent } from './video-download.component'
@NgModule({
imports: [
@@ -18,7 +18,7 @@ import { VideoMagnetComponent } from './video-magnet.component'
declarations: [
VideoWatchComponent,
VideoMagnetComponent,
VideoDownloadComponent,
VideoShareComponent,
VideoReportComponent
],

View File

@@ -158,7 +158,12 @@ const peertubePlugin = function (options: PeertubePluginOptions) {
})
player.torrent.on('error', err => handleError(err))
player.torrent.on('warning', err => handleError(err))
player.torrent.on('warning', err => {
// We don't support HTTP tracker but we don't care -> we use the web socket tracker
if (err.message.indexOf('Unsupported tracker protocol: http://') !== -1) return
return handleError(err)
})
player.trigger('videoFileUpdate')