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

Replace deprecated ugettext_lazy import with gettext_lazy #7

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion sage_stream/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def get(self, request, *args, **kwargs):
video_path = request.GET.get(path_key)
range_header = request.META.get('HTTP_RANGE', '').strip()
range_re = re.compile(range_re_pattern, re.I)
video_path = video_path.replace(media_url, media_dir)
if not (media_url == '/' or media_dir == ''):
video_path = video_path.replace(media_url, media_dir)
video_path = os.path.join(django_settings.BASE_DIR, video_path)

# log
Expand Down
2 changes: 1 addition & 1 deletion sage_stream/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.conf import settings
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

class WatchLog(models.Model):
"""Stream watch log"""
Expand Down
5 changes: 2 additions & 3 deletions sage_stream/utils/file_services.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import os


def file_iterator(file_name, chunk_size=8192, offset=0, length=None):
def file_iterator(file_name, request_index, chunk_size=8192, offset=0, length=None):
"""iterate file chunk by chunk in generator mode"""
with open(file_name, "rb") as f:
f.seek(offset, os.SEEK_SET)
remaining = length
while True:
bytes_length = chunk_size if remaining is None else min(remaining, chunk_size)
data = f.read(bytes_length)
if not data:
if not (data and request_index.is_current()):
break
if remaining:
remaining -= len(data)
Expand Down
3 changes: 2 additions & 1 deletion sage_stream/utils/stream_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def get_content_range_header(first_byte, last_byte, size):
return 'bytes %s-%s/%s' % (first_byte, last_byte, size)


def get_streaming_response(path, range_header, range_re, max_load_volume):
def get_streaming_response(path, range_header, range_re, max_load_volume, request_index):
"""
get range_header and match bytes position in the file
generate StreamingHttpResponse
Expand All @@ -46,6 +46,7 @@ def get_streaming_response(path, range_header, range_re, max_load_volume):
resp = StreamingHttpResponse(
file_iterator(
path,
request_index,
offset=first_byte,
length=length
),
Expand Down