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 simple user-agent control for playlist on safari #12

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions app/recordings/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class RecordingPlayListView(View):
content_type = "application/vnd.apple.mpegurl"
http_method_names = ['get', 'options']

def is_user_agent_safari(self, request):
return "safari" in request.headers.get("User-Agent", "").lower()

def get(self, request, *args, **kwargs):
recording = get_object_or_404(
Recording,
Expand All @@ -32,8 +35,10 @@ def get(self, request, *args, **kwargs):
m3u8 += "#EXT-X-MEDIA-SEQUENCE:0\n"
m3u8 += "#EXT-X-PLAYLIST-TYPE:VOD\n"
# todo: EXT-X-DISCONTINUITY seems to not be working on Safari. Leaving it out
# renders the stream unusable on Firefox/Chrome. Leave this out for now
m3u8 += "#EXT-X-DISCONTINUITY\n"
# renders the stream unusable on Firefox/Chrome.
# Therefore remove EXT-X-DISCONTINUITY if the user's browser is Safari.
if not self.is_user_agent_safari(request):
m3u8 += "#EXT-X-DISCONTINUITY\n"
for chunk in sorted(recording.chunks, key=lambda c: c['position']):
m3u8 += "\n"
# this sets the offset for the current chunk. This, however
Expand Down