sphinx-contrib / youtube

A Sphinx extension to embed videos from YouTube
BSD 3-Clause "New" or "Revised" License
52 stars 38 forks source link

Support twitch #68

Open mscheltienne opened 7 months ago

mscheltienne commented 7 months ago

It should be possible to support twitch as well? If you can give me a couple of hints/guidance, I can open a PR to add the functionality.

dham commented 7 months ago

Thanks for the offer. These are the things you need to do to add a new platform:

  1. Add a module to youtube/sphinxcontrib/youtube following the pattern of youtube.py, vimeo.py and peertube.py. This will contain subclasses of utils.video and utils.Video which set whichever parameters are different for your platform from the default.
  2. Register the new classes in __init__.py.
  3. Add basic tests following the pattern for the other platforms.
  4. Add documentation to README.md and the RST files in the docs folder. Again, follow the pattern for other platforms.
mscheltienne commented 7 months ago

Twitch requires the parent domain.. I am actually unable to include a .. raw:: directives which works locally through file:///. Example directive which works:

        .. raw:: html

            <div style="text-align: center;">
                <iframe
                    src="https://player.twitch.tv/?video=1950152310&parent=mscheltienne.github.io&parent=well-play-teen.org&autoplay=false"
                    allowfullscreen
                    frameborder="0"
                    height="378"
                    scrolling="no"
                    width="620">
                </iframe>
            </div>

I don't see an easy way to get the parent as part of this extension.. any idea?

dham commented 7 months ago

I think you do the following.

  1. When you subclass Video, overwrite option_spec with one that adds a parent option.
  2. Write a wrapper for utils.visit_video_node_html which adds the right string based on parent into url_parameters. If you look at youtube.py then you can see such a wrapper.
mscheltienne commented 7 months ago

But we don't have a way to retrieve the domain (to complete the parent) dynamically. I guess the only option is a configuration key, e.g. 'twitch_parent'.

dham commented 7 months ago

At the point that sphinx runs, it has no way of knowing where the resulting html will be hosted. I think that you're right that it needs to go in conf.py, because it's global.