Skip to content

Add subtitle description support#62

Open
nicklan wants to merge 2 commits intoenen92:masterfrom
nicklan:subtitle-support
Open

Add subtitle description support#62
nicklan wants to merge 2 commits intoenen92:masterfrom
nicklan:subtitle-support

Conversation

@nicklan
Copy link

@nicklan nicklan commented Feb 19, 2025

The resources tar actually includes a plist file that includes descriptions about each video.

Within that file there can be a single description for the whole video, or multiple descriptions. They are keyed by the number of seconds into the video that the description is applicable. The keys are referenced from the entries.json in the pointsOfInterest element.

This PR does the following main things:

When downloading/parsing the video info and building the playlist:

  • Extracts the plist file from the tar archive (Localizable.nocache.strings) for the configured language (falls back to English)
  • Parses the file and extracts the descriptions
  • Builds a pois list based on the pointsOfInterest element in entries.json and indexing into the above file
  • Creates a playlist that uses a new class that stores the url and the related descriptions

When playing videos, if descriptions are enabled

  • Turn the pois element into a .srt temp subtitle file
  • Tell the player to use that file for subtitles and enable subtitles

@graysky2
Copy link
Contributor

This looks really nice! I assume the answer is yes but just want to confirm that this works for you?

@nicklan
Copy link
Author

nicklan commented Feb 19, 2025

This looks really nice! I assume the answer is yes but just want to confirm that this works for you?

Thanks! And yep, it works nicely for me:
image

@graysky2
Copy link
Contributor

graysky2 commented Feb 19, 2025

So I am using offline mode (pre-downloaded the videos). The screensaver is refusing to start with this in kodi.log:

2025-02-19 17:17:01.318 T:2387    error <general>: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                                    - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                                   Error Type: <class 'FileNotFoundError'>
                                                   Error Contents: [Errno 2] No such file or directory: '/usr/share/kodi/addons/screensaver.atv4/resources/TVIdleScreenStrings.bundle/en.lproj/Localizable.nocache.strings'
                                                   Traceback (most recent call last):
                                                     File "/usr/share/kodi/addons/screensaver.atv4/entrypointscript.py", line 13, in <module>
                                                       atv.run(len(sys.argv) > 1)
                                                       ~~~~~~~^^^^^^^^^^^^^^^^^^^
                                                     File "/usr/share/kodi/addons/screensaver.atv4/resources/lib/atv.py", line 189, in run
                                                       screensaver = Screensaver(
                                                           'screensaver-atv4.xml',
                                                       ...<2 lines>...
                                                           '',
                                                       )
                                                     File "/usr/share/kodi/addons/screensaver.atv4/resources/lib/atv.py", line 35, in __init__
                                                       self.video_playlist = AtvPlaylist().compute_playlist_array()
                                                                             ~~~~~~~~~~~^^
                                                     File "/usr/share/kodi/addons/screensaver.atv4/resources/lib/playlist.py", line 104, in __init__
                                                       with open(plist_path, "rb") as f:
                                                            ~~~~^^^^^^^^^^^^^^^^^^
                                                   FileNotFoundError: [Errno 2] No such file or directory: '/usr/share/kodi/addons/screensaver.atv4/resources/TVIdleScreenStrings.bundle/en.lproj/Localizable.nocache.strings'
                                                   -->End of Python script error report<--

Missing some stuff it seems

@nicklan
Copy link
Author

nicklan commented Feb 19, 2025

Ahh okay, I haven't tested offline mode. I guess if you stay offline it can't re-get the file and extract the plist file so it can build stuff. I can add a check so it just doesn't create the subtitle info if it can't find the file with the descriptions.

@graysky2
Copy link
Contributor

graysky2 commented Feb 19, 2025

Can you easily adapt it to fetch the data it seems when in offline mode? If too much, can I manually wget what it needs?

@nicklan
Copy link
Author

nicklan commented Feb 19, 2025

Can you easily adapt it to fetch the data it seems when in offline mode?

I need to check what is available in this case. Does the resources.tar still exist in that case? Is it okay to re-download it if set to offline?

You can wget https://sylvan.apple.com/Aerials/resources-15.tar and then extract TVIdleScreenStrings.bundle/en.lproj/Localizable.nocache.strings from it and put it in /usr/share/kodi/addons/screensaver.atv4/resources/TVIdleScreenStrings.bundle/en.lproj/Localizable.nocache.strings

@graysky2
Copy link
Contributor

Man I downloaded these ages ago. If you have a fast connect, go ahead and try offline mode. It's probably more efficient for you to replicate it on your side.

@graysky2
Copy link
Contributor

You can wget https://sylvan.apple.com/Aerials/resources-15.tar and then extract TVIdleScreenStrings.bundle/en.lproj/Localizable.nocache.strings from it and put it in /usr/share/kodi/addons/screensaver.atv4/resources/TVIdleScreenStrings.bundle/en.lproj/Localizable.nocache.strings

I did this but still got errors:

2025-02-19 17:28:24.548 T:3164    error <general>: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                                                    - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                                   Error Type: <class 'KeyError'>
                                                   Error Contents: 'shotID'
                                                   Traceback (most recent call last):
                                                     File "/usr/share/kodi/addons/screensaver.atv4/entrypointscript.py", line 13, in <module>
                                                       atv.run(len(sys.argv) > 1)
                                                       ~~~~~~~^^^^^^^^^^^^^^^^^^^
                                                     File "/usr/share/kodi/addons/screensaver.atv4/resources/lib/atv.py", line 189, in run
                                                       screensaver = Screensaver(
                                                           'screensaver-atv4.xml',
                                                       ...<2 lines>...
                                                           '',
                                                       )
                                                     File "/usr/share/kodi/addons/screensaver.atv4/resources/lib/atv.py", line 35, in __init__
                                                       self.video_playlist = AtvPlaylist().compute_playlist_array()
                                                                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
                                                     File "/usr/share/kodi/addons/screensaver.atv4/resources/lib/playlist.py", line 167, in compute_playlist_array
                                                       shotId = block["shotID"]
                                                                ~~~~~^^^^^^^^^^
                                                   KeyError: 'shotID'
                                                   -->End of Python script error report<--

@nicklan
Copy link
Author

nicklan commented Feb 19, 2025

I understand the problem, it's more a question of the "right" solution. I.e. if you're in offline mode, the addon probably shouldn't go re-download a bunch of stuff.

I do realize that entries.json gets checked into the repo here. I could also just add the needed (english) descriptions as part of the PR, so it would fall back to that in offline mode. Again more a question of if we want to add a 45k file to the repo.

@graysky2
Copy link
Contributor

Maybe add a check for the needed files for users with an offline set of videos already and grab it if not present? Also, can you see my error one post above. After manually placing that directory, it is still erroring out.

@nicklan
Copy link
Author

nicklan commented Feb 19, 2025

I did this but still got errors:

Hrmm, somehow your entries.json must not have the shotId key? I looked at the entries.json in the repo and every element there does have that key. I can check and not error, but if you don't have that I suspect you might also not have the pointsOfInterest key, so none of this will work :)

Perhaps your entries.json is way out of date?

@nicklan
Copy link
Author

nicklan commented Feb 19, 2025

I did enable offline mode and download a couple of videos, and it's all working, but obviously I have the up to date files at this point

@nicklan
Copy link
Author

nicklan commented Feb 19, 2025

If you could post an entry or two from your /usr/share/kodi/addons/screensaver.atv4/resources/entries.json file it might help me understand what other formats I need to handle

@graysky2
Copy link
Contributor

Sure here is the entire file: https://gist.github.com/graysky2/68838af1a34bab64c9c094ae310f10fd

Can you post yours? I am happy to just overwrite it.

@nicklan
Copy link
Author

nicklan commented Feb 19, 2025

Ahh yeah, you have entries like:

       {
            "accessibilityLabel": "California to Vegas",
            "categories": [
                "55B7C95D-CEAF-4FD8-ADEF-F5BC657D8F6D"
            ],
            "clipNumber": "6",
            "official": "kubedzero_manually_added",
            "url-1080-HDR": "https://sylvan.apple.com/Aerials/2x/Videos/comp_GMT306_139NC_139J_3066_CALI_TO_VEGAS_v07_HDR_PS_FINAL_22062018_HDR_2K_HEVC.mov",
            "url-1080-SDR": "https://sylvan.apple.com/Aerials/2x/Videos/comp_GMT306_139NC_139J_3066_CALI_TO_VEGAS_v07_SDR_FINAL_22062018_SDR_2K_HEVC.mov",
            "url-4K-HDR": "https://sylvan.apple.com/Aerials/2x/Videos/comp_GMT306_139NC_139J_3066_CALI_TO_VEGAS_v07_HDR_PS_FINAL_22062018_HDR_4K_HEVC.mov",
            "url-4K-SDR": "https://sylvan.apple.com/Aerials/2x/Videos/comp_GMT306_139NC_139J_3066_CALI_TO_VEGAS_v07_SDR_FINAL_22062018_SDR_4K_HEVC.mov"
        },

which don't have shotId. I suspect (hope) with the code I just pushed you hopefully won't get errors and should get subtitles for those clips that do have pointsOfInterest. That said you can also just overwrite it with: https://github.com/enen92/screensaver.atv4/blob/master/resources/entries.json

But I'm not 100% sure if it will match the videos you already have downloaded

@graysky2
Copy link
Contributor

Should I just delete the downloaded videos and re-download them?

@nicklan
Copy link
Author

nicklan commented Feb 19, 2025

I mean you could get all the latest videos easily yeah by just going into online mode and downloading new videos :)

@graysky2
Copy link
Contributor

OK so as I test I will re-download everything after applying your new commit. That should grab the tarball I manually downloaded too, yes?

@nicklan
Copy link
Author

nicklan commented Feb 19, 2025

OK so as I test I will re-download everything after applying your new commit. That should grab the tarball I manually downloaded too, yes?

Yeah, in online mode it always downloads that tar and extracts the latest (at least afaict, I only just started looking at this code today ;) )

@graysky2
Copy link
Contributor

graysky2 commented Feb 20, 2025

I can't get it working even in offline mode. Videos just play but no subtitles even though they are enabled. The installation was just applying the PR and copying the entire dirtree to /usr/share/kodi/addons/screensaver.atv4/

Is that all?

When I start the addon with offline disabled:

2025-02-19 19:22:56.367 T:5477  warning <general>: No descriptions for language {}, defaulting to English
2025-02-19 19:22:56.367 T:5477  warning <general>: Could not find description file, cannot enable subtitles
2025-02-19 19:22:56.700 T:5341     info <general>: Loading skin file: /usr/share/kodi/addons/screensaver.atv4/resources/skins/default/1080i/screensaver-atv4.xml, load type: LOAD_ON_GUI_INIT
2025-02-19 19:22:56.743 T:5341     info <general>: VideoPlayer::OpenFile: /opt/ATV/I003_C011_SDR_4K_HEVC.mov
2025-02-19 19:22:56.743 T:5479     info <general>: Creating InputStream
2025-02-19 19:22:56.754 T:5479     info <general>: Creating Demuxer
2025-02-19 19:22:56.756 T:5479     info <general>: Opening stream: 0 source: 256
2025-02-19 19:22:56.756 T:5479     info <general>: Creating video codec with codec id: 173
2025-02-19 19:22:56.756 T:5479     info <general>: CDVDVideoCodecFFmpeg::Open() Using codec: HEVC (High Efficiency Video Coding)
2025-02-19 19:22:56.756 T:5479     info <general>: Creating video thread
2025-02-19 19:22:56.756 T:5481     info <general>: running thread: video_thread
2025-02-19 19:22:56.763 T:5489     info <general>: COutput::OnStartup: Output Thread created
2025-02-19 19:22:56.823 T:5479     info <general>: Opening stream: 0 source: 1024
2025-02-19 19:22:56.824 T:5479    error <general>: OpenStream - Unable to create subtitle parser
2025-02-19 19:22:56.870 T:5341     info <general>: GLES: Selecting single pass rendering
2025-02-19 19:22:56.870 T:5341     info <general>: GLES: Selecting YUV 2 RGB shader
2025-02-19 19:22:56.875 T:5479  warning <general>: CDVDMessageQueue(audio)::Put MSGQ_NOT_INITIALIZED
2025-02-19 19:22:56.986 T:5481     info <general>: CDVDVideoCodecFFmpeg::CDropControl: calculated diff time: 33366

@graysky2
Copy link
Contributor

graysky2 commented Feb 20, 2025

Yeah, in online mode it always downloads that tar and extracts the latest (at least afaict, I only just started looking at this code today ;) )

Where exactly should it download that tarball? I am running the latest version of this PR in offline mode and cannot find anything in /var/lib/kodi/ (the homedir of the kodi user).

That said you can also just overwrite it with: https://github.com/enen92/screensaver.atv4/blob/master/resources/entries.json

That is the file I am using.

Ahh yeah, you have entries like: which don't have shotId

It does not have any entries for that ... does your copy? If so, how?

On Arch Linux, this code is provided by kodi-addon-screensaver-apple-aerial which I maintain. Basically, the PKGBUILD just downloads this code, applies this PR, and copies the contents of this repo to /usr/share/kodi/addons/screensaver.atv4/

@nicklan
Copy link
Author

nicklan commented Feb 21, 2025

Hrmm. I can probably look at this again next week. Just to check, if you can could you just fully uninstall your current version including the user data and then install, does it work?

I suspect somehow the "old" data is hanging around and not getting updated with the new needed stuff.

I have an arch machine so I'll test out the AUR package as soon as I have a minute. Very cool that you want to package this :)

BTW, is this repo "abandoned"? Seems like stuff doesn't really get merged.

@graysky2
Copy link
Contributor

Just going by the last commit, @enen92 might not care to continue the project. You can carry the torch with your fork. I will try clearing all user data, but yes, using pacman guarantees none of the old file are present.

@graysky2
Copy link
Contributor

So I did have a settings.xml in /var/lib/kodi/.kodi/userdata/addon_data/screensaver.atv4/ but removing it had no effect, still no subtitles.

@graysky2
Copy link
Contributor

graysky2 commented Mar 1, 2025

@nicklan - did you get a chance to check this out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants