Skip to content

Commit

Permalink
Add caption selector and audio track selector to download prompt
Browse files Browse the repository at this point in the history
- TODO: fix captions not loading in iv

#348
  • Loading branch information
MarmadileManteater committed May 9, 2024
1 parent 42d58ec commit d691d12
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ input {

.ft-input-component {
inline-size: 100%;
margin-block-start: 1em;
}

.wrapper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ export default defineComponent({
},
data: function () {
return {
selected: -1
selected: -1,
captionSelected: -1,
audioTrackSelected: -1
}
},
computed: {
Expand All @@ -46,8 +48,10 @@ export default defineComponent({
const quality = this.defaultQuality
const sources = this.audioVideoSources
for (let i = 0; i < sources.length; i++) {
if (quality === parseInt(sources[i].qualityLabel.split('p')[0])) {
return i
if (sources[i].video) {
if (quality === parseInt(sources[i].qualityLabel.split('p')[0])) {
return i
}
}
}
return -1
Expand Down Expand Up @@ -79,6 +83,14 @@ export default defineComponent({
return parseInt(b.qualityLabel.split('p')[0]) - parseInt(a.qualityLabel.split('p')[0])
}
if (!a.video && !b.video) {
// bubble up original audio tracks
// TODO: organise audio by language
if (a.audio?.is_original && !b.audio?.is_original) {
return -1
}
if (b.audio?.is_original && !a.audio?.is_original) {
return 1
}
return b.audio?.bitrate - a.audio?.bitrate
}
// #endregion
Expand All @@ -94,7 +106,7 @@ export default defineComponent({
sourceNames: function () {
return this.audioVideoSources.map(
(source) => {
return `${source.video?.qualityLabel || source.video?.quality_label || `${source.audio?.bitrate} kbps`} - ${source.video ? this.$t('Download Prompt.Video') : this.$t('Download Prompt.Audio')}`
return `${source.video?.qualityLabel || source.video?.quality_label || `${source.audio?.language ? `${source.audio?.language} ` : ''}${source.audio?.bitrate} kbps`} - ${source.video ? this.$t('Download Prompt.Video') : this.$t('Download Prompt.Audio')}`
})
},
/**
Expand All @@ -104,6 +116,39 @@ export default defineComponent({
sourceIds: function () {
return [...Array(this.audioVideoSources.length).keys()]
},
captions: function () {
return this.sourcesForDownload.filter((source) => source.audio === undefined)
},
captionNames: function () {
return ['', ...this.captions.map(caption => caption.label)]
},
captionIds: function() {
return [-1, ...Array(this.captions.length).keys()]
},
hasMultipleAudioTracks: function () {
if (!this.audioVideoSources[this.formatSelected]?.video) {
return false
}
return this.audioVideoSources[this.formatSelected].languageTracks.length > 0
},
audioTracks: function () {
if (!this.hasMultipleAudioTracks) {
return []
}
return this.audioVideoSources[this.formatSelected].languageTracks
},
audioTrackNames: function () {
if (!this.hasMultipleAudioTracks) {
return []
}
return [`${this.audioVideoSources[this.formatSelected].audio.language} - ${this.audioVideoSources[this.formatSelected].audio.bitrate} kbps`, ...this.audioTracks.map(track => `${track.language} - ${track.bitrate} kbps`)]
},
audioTrackIds: function () {
if (!this.hasMultipleAudioTracks) {
return []
}
return [-1, ...Array(this.audioVideoSources[this.formatSelected].languageTracks.length).keys()]
},
/**
* the placeholder title for the file
* @returns {string}
Expand All @@ -121,6 +166,12 @@ export default defineComponent({
},
updateFormatSelected(selected) {
this.formatSelected = parseInt(selected)
},
updateCaptionSelected(selected) {
this.captionSelected = parseInt(selected)
},
updateAudioTrackSelected(selected) {
this.audioTrackSelected = parseInt(selected)
}
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@
:icon="['fas', 'download']"
@change="updateFormatSelected"
/>
<ft-select
:placeholder="$t('Download Prompt.Captions')"
:value="captionSelected"
:select-names="captionNames"
:select-values="captionIds"
:icon="['fas', 'closed-captioning']"
@change="updateCaptionSelected"
/>
<ft-select
v-if="hasMultipleAudioTracks"
:placeholder="$t('Download Prompt.Audio Language')"
:value="audioTrackSelected"
:select-names="audioTrackNames"
:select-values="audioTrackIds"
:icon="['fas', 'globe']"
@change="updateAudioTrackSelected"
/>
<ft-input
:label="'File name'"
:show-label="true"
Expand Down
19 changes: 13 additions & 6 deletions src/renderer/helpers/android.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ export async function downloadVideoAndAudio(directoryHandle, videoFormat, audioF
return outputFile
}

function getTypeAndContainer(format) {
function getFormatInfo(format) {
if ('mime_type' in format) {
const [type, container] = format.mime_type.split(';')[0].split('/')

Expand Down Expand Up @@ -455,7 +455,7 @@ export function getDownloadFormats(formats) {
const videoFormats = []
// #region Seperate audio and video formats
for (const format of formats) {
const { type, container } = getTypeAndContainer(format)
const { type, container } = getFormatInfo(format)
if (type === 'audio') {
audioFormats.push(format)
pairings.push({
Expand All @@ -472,18 +472,25 @@ export function getDownloadFormats(formats) {
// #endregion
const usedLabels = []
for (const video of videoFormats) {
const { container } = getTypeAndContainer(video)
const { container } = getFormatInfo(video)
/** @type {AudioVideo} */
const pairing = {
video,
container,
qualityLabel: video?.quality_label || video?.qualityLabel
qualityLabel: video?.quality_label || video?.qualityLabel,
languageTracks: []
}
for (const audio of audioFormats) {
const { __container } = audio
if (__container === pairing.container) {
if (!pairing.audio && __container === pairing.container && (audio.is_original || audio.audioChannels)) {
pairing.audio = audio
break
if (audio.audioChannels) {
// if iv
break
}
}
if (__container === pairing.container && !audio.is_original) {
pairing.languageTracks.push(audio)
}
}
if (usedLabels.indexOf(pairing.qualityLabel) === -1) {
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
faChevronRight,
faCircleUser,
faClone,
faClosedCaptioning,
faComment,
faCommentDots,
faCopy,
Expand Down Expand Up @@ -119,6 +120,7 @@ library.add(
faChevronRight,
faCircleUser,
faClone,
faClosedCaptioning,
faComment,
faCommentDots,
faCopy,
Expand Down
2 changes: 2 additions & 0 deletions static/locales-android/en-US.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ Download Prompt:
Formats: Formats
Audio: Audio
Video: Video
Captions: Captions
Audio Language: Audio Language

0 comments on commit d691d12

Please sign in to comment.