Git Product home page Git Product logo

tahercoolguy / django-sage-streaming Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sageteam-org/django-sage-streaming

0.0 0.0 0.0 48 KB

django-sage-streaming is a package based on Django Web Framework & Django Rest Framework for video streaming. We made this package in Django so that everyone can easily stream videos.

Home Page: https://github.com/sageteam-org/django-sage-streaming

License: GNU General Public License v3.0

Python 100.00%

django-sage-streaming's Introduction

Django Sage Streaming

django-sage-streaming is a package based on Django Web Framework & Django Rest Framework for video streaming.

The Latest version of django-sage-streaming documentation

SageTeam

PyPI release Supported Python versions Supported Django versions Documentation

Project Detail

You can find all technologies we used in our project into these files:

  • Version: 1.0.0
  • Frameworks:
    • Django 3.2.5
  • Libraries:
    • Django rest framework 3.12.4
  • Language: Python 3.9.4

Installation

First install package

$ pip install django-sage-streaming

Then add sage_stream to INSTALLED_APPS in settings.py

INSTALLED_APPS = [
  ...
  'sage_stream',
  ...
]

Also make sure you have rest_framework in INSTALLED_APPS

INSTALLED_APPS = [
  ...
  'rest_framework',
  ...
]

Getting Started

django-sage-streaming provides two ways that you can stream videos over HTTP:

  1. built-in API View: for using built-in view add sage_stream.api.urls to urls.py
from django.urls import path, include
urlpatterns = [
  ...
  path('api/', include('sage_stream.api.urls')),
  ...
]

Now you can access the stream api here: localhost:8000/api/stream?path=<you_video_path>

The settings of built-in view is available here

  1. create custom views: you can use stream functions in your application
from sage_stream.utils.stream_services import get_streaming_response

response = get_streaming_response(
    path=video_path, # path to video
    range_header=range_header, # range header extracted from request
    range_re=range_re, # range header regex pattern (default is available in sage_stream.settings.STREAM_RANGE_HEADER_REGEX_PATTERN)
    max_load_volume=max_load_volume,  # the maximum volume of the response body
)

Other functions you can use

from sage_stream.utils.file_services import file_iterator  # iterates in given file chunk by chunk in generator mode
from sage_stream.utils.log_services import log_watch_request  # creates WatchLog instance with given data

# usage examples

# log
log_watch_request(video_path, request.user.is_authenticated, ip, request.user)

# file iterator
resp = StreamingHttpResponse(
    file_iterator(
        path,
        offset=first_byte,
        length=length
    ),
    status=206,
    content_type=content_type
)

Admin

django-sage-streaming also has logging system for watching requests

It is available in admin panel when you add sage_stream to INSTALLED_APPS

Settings

Here are the parameters that you can set from setting:

Parameter Description
STREAM_DEFAULT_PERMISSION_CLASSES permission_classes that used in built-in APIView. default: (AllowAny,)
STREAM_DEFAULT_VIDEO_PATH_URL_VAR url path variable key. default: path
STREAM_MAX_LOAD_VOLUME maximum load video in each chunk(by MB). default: 8
STREAM_WATCH_LOG_ENABLED is log watch requests enabled. default: True
STREAM_RANGE_HEADER_REGEX_PATTERN range header regex pattern. default: r'bytes\s*=\s*(\d+)\s*-\s*(\d*)'

Frontend

Frontend implementation is so easy

you just need to add stream url as src in video tag

<video width="480" controls>
    <source src="http://localhost:8000/api/stream/?path=<path_to_video>" type="video/mp4">
</video>

Team

Sepehr Akbarzadeh Mehran Rahmanzadeh
Sepehr Akbarazadeh Mehran Rahmanzadeh

django-sage-streaming's People

Contributors

mehran-rahmanzadeh avatar tahercoolguy avatar sageteam-org avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.