Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for movie captions #907

Closed
wants to merge 1 commit into from
Closed

Add support for movie captions #907

wants to merge 1 commit into from

Conversation

douzebis
Copy link

Generate HTML5 subtitle tracks dynamically based on the contents of the
where the movie is located.

For example a "movie.en.vtt" file in the same folder as the "movie.mkv"
will be used as a track for English subtitles.

@douzebis
Copy link
Author

This is a feature enhancement corresponding to issue
#239

Generate HTML5 subtitle tracks dynamically based on the contents of the
where the movie is located.

For example a "movie.en.vtt" file in the same folder as the "movie.mkv"
will be used as a track for English subtitles.

Signed-off-by: Frederic Ruget <fred@atlant.is>
@szaimen szaimen requested a review from skjnldsv May 22, 2021 21:38
@szaimen szaimen added 3. to review Waiting for reviews enhancement New feature or request labels May 22, 2021
@douzebis
Copy link
Author

Hi! I've seen the failure in test Node / node12.x.
Do I need to commit the changes in files js/viewer-main.js and js/viewer-main.js.map? (Apparently automatically generated?)

@beardhatcode
Copy link
Contributor

@douzebis, yes the files in js need to be pushed (it's indeed odd)

Copy link
Contributor

@beardhatcode beardhatcode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution 😄. This looks good to me (but I don't decide if this gets in), I added some comments to make the code cleaner.

I am wondering about how this works when publicly sharing files. So, if you share a folder, will these captions work?

const lang = langs[i]
let language = languages[lang]
if (language.length === 0) language = lang
tracks += '<track src="'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to create these elements with vue (v-for) and not by creating a string here. A bit like this

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @beardhatcode!
I'll have a look at the 'v-for' syntax and try and use it.
I'll be updating my code and re-submitting.

Also, I may add the possibility to use '.movie.en.vtt' for the language tracks -- with a leading dot.
So as not to clutter the contents of the viewer folder with language tracks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, that could work but in that case you could have two vtt files per language be sure to give precedence to the visible file (without a dot). However, I would first try to just get it working and leave this addition for another PR.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

@@ -21,13 +21,14 @@
*/
import { getDavPath } from '../utils/fileUtils'

export default function(fileInfo, mime, component) {
export default function(fileInfo, mime, component, caplangs) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, I'm not sure that caplangs should go here in file.js it is video specific. This change should not reach into this file. Maybe it is a util or a mixin?

@@ -415,6 +418,19 @@ export default {
// retrieve folder list
const fileList = await folderRequest(dirPath)

// retrieve caption languages
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be moved to the Video component as it is only used for videos

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually i was unable to code the retrieval of the caption files within Videos.vue, because I could not implement it unless I was using an 'async' function and this did not work well with the Videos.vue template -- I got "promises" instead of the the actual list of files.

Please don't hesitate to suggest code snippets... I need guidance :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Promises" are values JavaScript returns when it does not have the data yet. So when you are getting a file listing, you need to send some requests, if all of the javascript stoped at that moment, that would kill the user experience. Instead, JavaScript returns a promise: "I don'd have this data now, but I promise I will have it". You can also say to JS, ah, OK once you have that data call this function with it as argument (then). So what you could do (I think) is:

Add a [created] hook to the Video component. In there you do what you did before to get the data (yourCodeThatFindsTheRightThingAndReturnsAPromice) and then use then to specify what should happen once we have that data. So in the snippet below response will hold the data you want, and

  created() {
      yourCodeThatFindsTheRightThingAndReturnsAPromice().
      .then(response => {
          /* do stuff with the respose to get the right things*/
          this.captions = ...  // ← set a fild to be used in the template on top
      });
  }

I don't really have that much time to explain it well, but it is really worth the effort to learn about promises and async/await see this useful tutorial by Mozilla

Comment on lines +319 to +320
let language = languages[lang]
if (language.length === 0) language = lang
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let language = languages[lang]
if (language.length === 0) language = lang
let language = languages[lang] || lang

Comment on lines +317 to +318
for (let i = 0; i < langs.length; ++i) {
const lang = langs[i]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (let i = 0; i < langs.length; ++i) {
const lang = langs[i]
for (let lang of langs) {

But it might be even better to use v-for instead.

@douzebis douzebis marked this pull request as draft May 23, 2021 10:37
@douzebis
Copy link
Author

OK.
I did it again from scratch and filed a new pull request:
#910

(I did not want to clutter the history of the viewer with back and forth modifications.)

Now there is a single modified file: src/components/Videos.vue

@beardhatcode
Copy link
Contributor

@douzebis, that ok we could have just rewritten the history to clean it up. I'll close this PR then in favour of #910.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants