+function associate (models) {
+ this.belongsTo(models.Author, {
+ foreignKey: {
+ name: 'authorId',
+ allowNull: false
+ },
+ onDelete: 'cascade'
+ })
+
+ this.belongsToMany(models.Tag, {
+ foreignKey: 'videoId',
+ through: models.VideoTag,
+ onDelete: 'cascade'
+ })
+}
+
+function generateMagnetUri () {
+ let baseUrlHttp, baseUrlWs
+
+ if (this.isOwned()) {
+ baseUrlHttp = constants.CONFIG.WEBSERVER.URL
+ baseUrlWs = constants.CONFIG.WEBSERVER.WS + '://' + constants.CONFIG.WEBSERVER.HOSTNAME + ':' + constants.CONFIG.WEBSERVER.PORT
+ } else {
+ baseUrlHttp = constants.REMOTE_SCHEME.HTTP + '://' + this.Author.Pod.host
+ baseUrlWs = constants.REMOTE_SCHEME.WS + '://' + this.Author.Pod.host
+ }
+
+ const xs = baseUrlHttp + constants.STATIC_PATHS.TORRENTS + this.getTorrentName()
+ const announce = baseUrlWs + '/tracker/socket'
+ const urlList = [ baseUrlHttp + constants.STATIC_PATHS.WEBSEED + this.getVideoFilename() ]
+
+ const magnetHash = {
+ xs,
+ announce,
+ urlList,
+ infoHash: this.infoHash,
+ name: this.name
+ }
+
+ return magnetUtil.encode(magnetHash)
+}
+
+function getVideoFilename () {
+ if (this.isOwned()) return this.id + this.extname
+
+ return this.remoteId + this.extname
+}
+
+function getThumbnailName () {
+ // We always have a copy of the thumbnail
+ return this.id + '.jpg'
+}
+
+function getPreviewName () {
+ const extension = '.jpg'
+
+ if (this.isOwned()) return this.id + extension
+
+ return this.remoteId + extension
+}
+
+function getTorrentName () {
+ const extension = '.torrent'
+
+ if (this.isOwned()) return this.id + extension
+
+ return this.remoteId + extension
+}
+