Prefer a subtitle/audio track for series

This commit is contained in:
samcm 2017-08-10 01:45:40 +10:00
parent cedad518b1
commit 832450755b
3 changed files with 138 additions and 14 deletions

View File

@ -196,8 +196,8 @@
// Below are options chosen for each copy
chosenMediaIndex: 0, // The index of the item we want to play
chosenQuality: JSON.parse(window['localStorage'].getItem('PTPLAYERQUALITY')) || 'Original', // The quality profile
chosenSubtitleIndex: 0, // Subtitle track index
chosenAudioTrackIndex: 0, // Audio track index
chosenSubtitleIndex: null, // Subtitle track index
chosenAudioTrackIndex: null, // Audio track index
sources: [],
// Player status
@ -230,12 +230,26 @@
this.$store.commit('setSettingPTPLAYERQUALITY',this.chosenQuality)
},
chosenMediaIndex: function () {
this.chosenSubtitleIndex = 0
this.chosenAudioTrackIndex = 0
this.changedPlaying(false)
},
chosenAudioTrackIndex: function () {
//console.log('Audio track change')
if (!this.chosenAudioTrackIndex){
return
}
console.log('Audio track change')
if (this.playingMetadata && this.playingMetadata.type == 'episode') {
// We should save this preference for this series in our localStorage
let seriesKey = this.playingMetadata.grandparentKey
let languageCode = this.playingMetadata.Media[this.chosenMediaIndex].Part[0].Stream[this.chosenAudioTrackIndex].languageCode
console.log('Our prefered audio track for ' + seriesKey + ' is now ' + languageCode)
this.savePrefence('audio',seriesKey,languageCode)
}
var that = this
let audioStreamID = this.playingMetadata.Media[this.chosenMediaIndex].Part[0].Stream[this.chosenAudioTrackIndex].id
let baseparams = this.getSourceByLabel(this.chosenQuality).params
@ -270,7 +284,20 @@
})
},
chosenSubtitleIndex: function () {
chosenSubtitleIndex: function () {
if (!this.chosenSubtitleIndex){
return
}
console.log('Audio track change')
if (this.playingMetadata && this.playingMetadata.type == 'episode') {
// We should save this preference for this series in our localStorage
let seriesKey = this.playingMetadata.grandparentKey
let languageCode = this.playingMetadata.Media[this.chosenMediaIndex].Part[0].Stream[this.chosenSubtitleIndex].languageCode
console.log('Our prefered subtitle track for ' + seriesKey + ' is now ' + languageCode)
this.savePrefence('subs',seriesKey,languageCode)
}
//console.log('Subtitle track change')
var that = this
let subtitleStreamID = 0
@ -350,7 +377,22 @@
text: current.language + ' (' + current.codec + ' ' + current.audioChannelLayout + ')'
})
}
}
return audioTracks
},
audioTracks () {
let audioTracks = []
if (!this.playingMetadata) {
return audioTracks
}
if (this.playingMetadata.Media[this.chosenMediaIndex].Part[0].Stream.length == 1) {
return audioTracks
}
for (let i = 0; i < this.playingMetadata.Media[this.chosenMediaIndex].Part[0].Stream.length; i++) {
let current = this.playingMetadata.Media[this.chosenMediaIndex].Part[0].Stream[i]
if (current.streamType == 2) {
audioTracks.push(current)
}
}
return audioTracks
},
@ -376,7 +418,23 @@
}
}
return subtitleTracks
},
subtitleTracks () {
let subtitleTracks = []
if (!this.playingMetadata) {
return subtitleTracks
}
if (this.playingMetadata.Media[this.chosenMediaIndex].Part[0].Stream.length == 1) {
return subtitleTracks
}
for (let i = 0; i < this.playingMetadata.Media[this.chosenMediaIndex].Part[0].Stream.length; i++) {
let current = this.playingMetadata.Media[this.chosenMediaIndex].Part[0].Stream[i]
if (current.streamType == 3) {
subtitleTracks.push(current)
}
}
return subtitleTracks
},
qualitiesSelect () {
@ -404,9 +462,59 @@
}
return null
},
getInitAudioTrackIndex: function (){
console.log('Fetching audio track')
// Load preferences from file
if (!this.playingMetadata || this.playingMetadata.type != 'episode'){
console.log('Error with playingMetadata or content type when fetching audio track preference')
return 0
}
let prefLanguage = this.getPreference('audio',this.playingMetadata.grandparentKey)
console.log('Our audio preference for this series is ' + prefLanguage)
let tracks = this.playingMetadata.Media[this.chosenMediaIndex].Part[0].Stream
console.log('Tracks: ', tracks)
for (let i = 0; i < tracks.length; i++){
if (prefLanguage == tracks[i].languageCode && tracks[i].streamType == 2){
return i
}
}
console.log('No preference for ' + this.playingMetadata.grandparentKey)
},
getInitSubtitleTrackIndex: function (){
console.log('Fetching subtitle track')
// Load preferences from file
if (!this.playingMetadata || this.playingMetadata.type != 'episode'){
console.log('Error with playingMetadata or content type when fetching subtitle track preference', this.playingMetadata.type, this.playingMetadata)
return 0
}
let tracks = this.playingMetadata.Media[this.chosenMediaIndex].Part[0].Stream
let prefLanguage = this.getPreference('subs',this.playingMetadata.grandparentKey)
console.log('Our subtitle preference for this series is ' + prefLanguage)
for (let i = 0; i < tracks.length; i++){
if (prefLanguage == tracks[i].languageCode && tracks[i].streamType == 3){
return i
}
}
console.log('No preference for ' + this.playingMetadata.grandparentKey)
},
openModal () {
return this.$refs.playersettingsModal.open()
},
savePrefence (type, ratingKey, preference){
let oldSettings = JSON.parse(localStorage.getItem('PTPLAYERPREFS-' + type))
if (!oldSettings){
oldSettings = {}
}
oldSettings[ratingKey] = preference
localStorage.setItem('PTPLAYERPREFS-' + type, JSON.stringify(oldSettings))
},
getPreference (type, ratingKey){
let oldSettings = JSON.parse(localStorage.getItem('PTPLAYERPREFS-' + type))
if (!oldSettings){
return null
}
return oldSettings[ratingKey]
},
generateSources () {
var that = this
let qualityTemplate = function (label, resolution, bitrate, videoQuality) {
@ -478,18 +586,27 @@
function req () {
that.sources = that.generateSources()
request(that.getSourceByLabel(that.chosenQuality).initUrl, function (error, response, body) {
parseXMLString(body, function (err, result) {
var options = {
headers: {
accept: 'application/json'
},
url: that.getSourceByLabel(that.chosenQuality).initUrl
}
request(options, function (error, response, body) {
if (error){
return false
}
that.ready = true
that.transcodeSessionMetadata = body
/*parseXMLString(body, function (err, result) {
if (err) {
that.ready = false
}
that.ready = true
that.transcodeSessionMetadata = result
})
if (!error) {
}
}*/
})
}
@ -500,9 +617,13 @@
}
if (changeItem) {
this.playingMetadata = null
this.chosenServer.getMediaByRatingKey(this.chosenKey, function (result) {
this.chosenServer.getMediaByRatingKey(this.chosenKey, (result) => {
//console.log(result)
that.playingMetadata = result
this.playingMetadata = result
this.chosenAudioTrackIndex = this.getInitAudioTrackIndex()
this.chosenSubtitleIndex = this.getInitSubtitleTrackIndex()
req()
})
} else {
@ -573,7 +694,7 @@
location = 'lan'
}
let params = {
hasMDE: 1,
hasMDE: 0,
path: this.playingMetadata.key,
mediaIndex: this.chosenMediaIndex,
partIndex: 0,

View File

@ -34,6 +34,9 @@
props: ['server', 'metadata', 'initialOffset', 'src', 'initUrl', 'stopUrl', 'params', 'sources'],
created () {
},
beforeDestroy: function(){
this.$store.commit('SET_DECISIONBLOCKED', false)
},
data () {
return {
@ -397,7 +400,6 @@
console.log(player)
},
playerStateChanged (playerCurrentState) {
console.log("Setting volume to " + this.player.volume() || 0)
this.$store.commit('setSettingPTPLAYERVOLUME', this.player.volume() || 0)
this.bufferedTill = Math.round(this.player.buffered().end(0) * 1000)
this.duration = Math.round(this.player.duration() * 1000)

View File

@ -271,6 +271,7 @@ const mutations = {
state.blockAutoPlay = value
},
SET_DECISIONBLOCKED (state, value) {
console.log('Setting decisionBlocked to ' + value)
state.decisionBlocked = value
},
REFRESH_PLEXDEVICES (state) {