-
Notifications
You must be signed in to change notification settings - Fork 49
feat: Implemented HLS stream source as new plugin type. #84
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
Open
sepi
wants to merge
16
commits into
django-cms:master
Choose a base branch
from
sepi:hls-stream-source
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
b83f60b
feat: Implemented HLS stream source as new plugin type.
raffael-mnhn 56d8fe4
Update tox.ini
fsbraun a0bc25f
Update settings.py
fsbraun 77cca1f
hls.js source is now configurable
raffael-mnhn 144bc18
Removed debug log in js for HLS source
raffael-mnhn 2142235
Better field type for hls source url
raffael-mnhn 7766e66
Added brief documentation for HLS source
raffael-mnhn d4d797b
Update test_migrations.py
fsbraun de44dc1
Update lint.yml
fsbraun 580335c
Update test.yml
fsbraun 65e1a88
Sort imports for ruff
raffael-mnhn 369a50b
Complete test requirements
fsbraun c71680e
Merge branch 'hls-stream-source' of github.com:sepi/djangocms-video i…
fsbraun abf5863
Fix: Wrong migration reference
fsbraun 63dd3b5
Fix migration, remove unneeded mptt from `INSTALLED_APPS` in tests, f…
fsbraun 5fc0b66
Update tests
fsbraun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # Generated by Django 5.0.9 on 2024-11-30 13:11 | ||
|
|
||
| import django.db.models.deletion | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('cms', '0035_auto_20230822_2208_squashed_0036_auto_20240311_1028'), | ||
| ('djangocms_video', '0011_alter_videoplayer_cmsplugin_ptr_and_more'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name='HlsStreamSource', | ||
| fields=[ | ||
| ('cmsplugin_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, related_name='%(app_label)s_%(class)s', serialize=False, to='cms.cmsplugin')), | ||
| ('hls_source_url', models.CharField(max_length=1024, verbose_name='HLS Source URL')), | ||
| ], | ||
| bases=('cms.cmsplugin',), | ||
| ), | ||
| ] |
23 changes: 23 additions & 0 deletions
23
djangocms_video/migrations/0013_videoplayer_autoplay_videoplayer_show_controls.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # Generated by Django 5.0.9 on 2024-11-30 14:56 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('djangocms_video', '0012_hlsstreamsource'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name='videoplayer', | ||
| name='autoplay', | ||
| field=models.BooleanField(default=False, help_text='If enabled, the video will automatically play once the page is loaded. This might not work depending on how the user has configured their browser.', verbose_name='Autoplay'), | ||
| ), | ||
| migrations.AddField( | ||
| model_name='videoplayer', | ||
| name='show_controls', | ||
| field=models.BooleanField(default=True, help_text='If enabled, the video will be shown with Play, Pause and Seek elements that allow the user to control playback.', verbose_name='Show controls'), | ||
| ), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
djangocms_video/templates/djangocms_video/default/hls_stream_source.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| {% load i18n cms_tags sekizai_tags %} | ||
|
|
||
| {% if not disabled %} | ||
| {% with instance.hls_source_url as url %} | ||
| <source id="{{ source_id }}" src="{{ url }}" type="application/x-mpegURL" {{ instance.attributes_str }}> | ||
| {% endwith %} | ||
| {% endif %} | ||
|
|
||
| {% addtoblock "js" %} | ||
| <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/hls.min.js "></script> | ||
sepi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
sepi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <script> | ||
| // Find first source ending in a .m3u8 path and return its url | ||
| function getHlsUrl(videoElement) { | ||
| const sources = videoElement.querySelectorAll("source"); | ||
| for (source of sources) { | ||
| if (source.src.endsWith("m3u8")) { | ||
| return source.src; | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| function attachHlsStream(sourceElement) { | ||
| if (Hls.isSupported()) { | ||
| let video = sourceElement.parentElement; | ||
| let hls = new Hls(); | ||
| let hlsUrl = getHlsUrl(video); | ||
| hls.loadSource(hlsUrl); | ||
| hls.attachMedia(video); | ||
| hls.on(Hls.Events.MANIFEST_PARSED, function (event, data) { | ||
| console.log('manifest loaded, found ' + data.levels.length + ' quality level',); | ||
sepi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| video.play(); | ||
| }); | ||
|
|
||
| hls.on(Hls.Events.ERROR, function (event, data) { | ||
| if (data.fatal) { | ||
| switch (data.type) { | ||
| case Hls.ErrorTypes.MEDIA_ERROR: | ||
| console.error('fatal media error encountered, try to recover'); | ||
| hls.recoverMediaError(); | ||
| break; | ||
| case Hls.ErrorTypes.NETWORK_ERROR: | ||
| console.error('fatal network error encountered', data); | ||
| break; | ||
| default: | ||
| hls.destroy(); | ||
| break; | ||
| } | ||
| } | ||
| }); | ||
| } else if (video.canPlayType('application/vnd.apple.mpegurl')) { | ||
| video.src = hlsUrl; | ||
| video.addEventListener('loadedmetadata', () => { | ||
| video.play(); | ||
| }); | ||
| } else { | ||
| console.error('HLS is not supported on this browser.'); | ||
| } | ||
| } | ||
|
|
||
| attachHlsStream(document.getElementById('{{ source_id }}')); | ||
|
|
||
| </script> | ||
| {% endaddtoblock %} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.