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 <https://django-sage-streaming.readthedocs.io/>`__ documentation
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|SageTeam| |PyPI release| |Supported Python versions| |Supported Django
versions| |Documentation| |Test|
- `Project Detail <#project-detail>`__
- `installation <#installation>`__
- `Get Started <#getting-started>`__
- `Admin <#admin>`__
- `Settings <#settings>`__
- `Front-End implementation <#frontend>`__
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
.. code:: shell
$ pip install django-sage-streaming
Then add ``sage_stream`` to INSTALLED\_APPS in settings.py
.. code:: python
INSTALLED_APPS = [
...
'sage_stream',
...
]
Also make sure you have ``rest_framework`` in INSTALLED\_APPS
.. code:: python
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
.. code:: python
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 <#settings>`__
2. create custom views: you can use stream functions in your application
.. code:: python
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
.. code:: python
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=(+)-()' |
+------------------------------------------+---------------------------------------------------------------------------+
Frontend
--------
Frontend implementation is so easy
you just need to add stream url as ``src`` in ``video`` tag
.. code:: html
<video width="480" controls>
<source src="http://localhost:8000/api/stream/?path=<path_to_video>" type="video/mp4">
</video>
Team
----
+-----------------------------------------------------------------+---------------------------------------------------------+
| |sepehr| | |mehran| |
+=================================================================+=========================================================+
| `Sepehr Akbarazadeh <https://github.com/sepehr-akbarzadeh>`__ | `Mehran Rahmanzadeh <https://github.com/mrhnz>`__ |
+-----------------------------------------------------------------+---------------------------------------------------------+
.. |SageTeam| image:: https://github.com/sageteam-org/django-sage-painless/blob/develop/docs/images/tag_sage.png?raw=true
:alt: SageTeam
.. |PyPI release| image:: https://github.com/sageteam-org/django-sage-painless/blob/develop/docs/images/tag_pypi_0.0.8.png?raw=true
:alt: django-sage-painless
.. |Supported Python versions| image:: https://github.com/sageteam-org/django-sage-painless/blob/develop/docs/images/tag_python-02.png?raw=true
:alt: django-sage-painless
.. |Supported Django versions| image:: https://github.com/sageteam-org/django-sage-painless/blob/develop/docs/images/tag_django.png?raw=true
:alt: django-sage-painless
.. |Documentation| image:: https://github.com/sageteam-org/django-sage-painless/blob/develop/docs/images/tag_docs.png?raw=true
:alt: django-sage-painless
.. |Test| image:: https://github.com/sageteam-org/django-sage-painless/blob/develop/docs/images/tag_test.png?raw=true
:alt: django-sage-painless
.. |sepehr| image:: https://github.com/sageteam-org/django-sage-painless/blob/develop/docs/images/sepehr.jpeg?raw=true
:height: 230px
:width: 230px
:alt: Sepehr Akbarzadeh
.. |mehran| image:: https://github.com/sageteam-org/django-sage-painless/blob/develop/docs/images/mehran.png?raw=true
:height: 340px
:width: 225px
:alt: Mehran Rahmanzadeh
Raw data
{
"_id": null,
"home_page": "https://github.com/J3dd4/fork-django-streaming",
"name": "fork-django-streaming",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.5",
"maintainer_email": "",
"keywords": "django,python,streaming,video streaming",
"author": "Jed",
"author_email": "adijed3@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/0e/87/50ab27bd4a2fa8b99871617e45e92f4b65dfe45893adef156ab1be1d6a08/fork-django-streaming-0.2.0.tar.gz",
"platform": null,
"description": "Django Sage Streaming\r\n=====================\r\n\r\ndjango-sage-streaming is a package based on Django Web Framework & Django Rest Framework for video streaming.\r\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n\r\nThe Latest version of `django-sage-streaming <https://django-sage-streaming.readthedocs.io/>`__ documentation\r\n'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''\r\n\r\n|SageTeam| |PyPI release| |Supported Python versions| |Supported Django\r\nversions| |Documentation| |Test|\r\n\r\n- `Project Detail <#project-detail>`__\r\n- `installation <#installation>`__\r\n- `Get Started <#getting-started>`__\r\n- `Admin <#admin>`__\r\n- `Settings <#settings>`__\r\n- `Front-End implementation <#frontend>`__\r\n\r\nProject Detail\r\n--------------\r\n\r\nYou can find all technologies we used in our project into these files:\r\n\\* Version: 1.0.0 \\* Frameworks: - Django 3.2.5 \\* Libraries: - Django\r\nrest framework 3.12.4 \\* Language: Python 3.9.4\r\n\r\nInstallation\r\n------------\r\n\r\nFirst install package\r\n\r\n.. code:: shell\r\n\r\n $ pip install django-sage-streaming\r\n\r\nThen add ``sage_stream`` to INSTALLED\\_APPS in settings.py\r\n\r\n.. code:: python\r\n\r\n INSTALLED_APPS = [\r\n ...\r\n 'sage_stream',\r\n ...\r\n ]\r\n\r\nAlso make sure you have ``rest_framework`` in INSTALLED\\_APPS\r\n\r\n.. code:: python\r\n\r\n INSTALLED_APPS = [\r\n ...\r\n 'rest_framework',\r\n ...\r\n ]\r\n\r\nGetting Started\r\n---------------\r\n\r\n``django-sage-streaming`` provides two ways that you can stream videos\r\nover HTTP: 1. built-in API View: for using built-in view add\r\n``sage_stream.api.urls`` to urls.py\r\n\r\n.. code:: python\r\n\r\n from django.urls import path, include\r\n urlpatterns = [\r\n ...\r\n path('api/', include('sage_stream.api.urls')),\r\n ...\r\n ]\r\n\r\nNow you can access the stream api here:\r\n``localhost:8000/api/stream?path=<you_video_path>``\r\n\r\n`The settings of built-in view is available here <#settings>`__\r\n\r\n2. create custom views: you can use stream functions in your application\r\n\r\n.. code:: python\r\n\r\n from sage_stream.utils.stream_services import get_streaming_response\r\n\r\n response = get_streaming_response(\r\n path=video_path, # path to video\r\n range_header=range_header, # range header extracted from request\r\n range_re=range_re, # range header regex pattern (default is available in sage_stream.settings.STREAM_RANGE_HEADER_REGEX_PATTERN)\r\n max_load_volume=max_load_volume, # the maximum volume of the response body\r\n )\r\n\r\nOther functions you can use\r\n\r\n.. code:: python\r\n\r\n from sage_stream.utils.file_services import file_iterator # iterates in given file chunk by chunk in generator mode\r\n from sage_stream.utils.log_services import log_watch_request # creates WatchLog instance with given data\r\n\r\n # usage examples\r\n\r\n # log\r\n log_watch_request(video_path, request.user.is_authenticated, ip, request.user)\r\n\r\n # file iterator\r\n resp = StreamingHttpResponse(\r\n file_iterator(\r\n path,\r\n offset=first_byte,\r\n length=length\r\n ),\r\n status=206,\r\n content_type=content_type\r\n )\r\n\r\nAdmin\r\n-----\r\n\r\n``django-sage-streaming`` also has logging system for watching requests\r\n\r\nIt is available in admin panel when you add ``sage_stream`` to\r\nINSTALLED\\_APPS\r\n\r\nSettings\r\n--------\r\n\r\nHere are the parameters that you can set from setting:\r\n\r\n+------------------------------------------+---------------------------------------------------------------------------+\r\n| Parameter | Description |\r\n+==========================================+===========================================================================+\r\n| STREAM\\_DEFAULT\\_PERMISSION\\_CLASSES | permission\\_classes that used in built-in APIView. default: (AllowAny,) |\r\n+------------------------------------------+---------------------------------------------------------------------------+\r\n| STREAM\\_DEFAULT\\_VIDEO\\_PATH\\_URL\\_VAR | url path variable key. default: path |\r\n+------------------------------------------+---------------------------------------------------------------------------+\r\n| STREAM\\_MAX\\_LOAD\\_VOLUME | maximum load video in each chunk(by MB). default: 8 |\r\n+------------------------------------------+---------------------------------------------------------------------------+\r\n| STREAM\\_WATCH\\_LOG\\_ENABLED | is log watch requests enabled. default: True |\r\n+------------------------------------------+---------------------------------------------------------------------------+\r\n| STREAM\\_RANGE\\_HEADER\\_REGEX\\_PATTERN | range header regex pattern. default: r'bytes=(+)-()' |\r\n+------------------------------------------+---------------------------------------------------------------------------+\r\n\r\nFrontend\r\n--------\r\n\r\nFrontend implementation is so easy\r\n\r\nyou just need to add stream url as ``src`` in ``video`` tag\r\n\r\n.. code:: html\r\n\r\n <video width=\"480\" controls>\r\n <source src=\"http://localhost:8000/api/stream/?path=<path_to_video>\" type=\"video/mp4\">\r\n </video>\r\n\r\n\r\nTeam\r\n----\r\n\r\n+-----------------------------------------------------------------+---------------------------------------------------------+\r\n| |sepehr| | |mehran| |\r\n+=================================================================+=========================================================+\r\n| `Sepehr Akbarazadeh <https://github.com/sepehr-akbarzadeh>`__ | `Mehran Rahmanzadeh <https://github.com/mrhnz>`__ |\r\n+-----------------------------------------------------------------+---------------------------------------------------------+\r\n\r\n.. |SageTeam| image:: https://github.com/sageteam-org/django-sage-painless/blob/develop/docs/images/tag_sage.png?raw=true\r\n :alt: SageTeam\r\n.. |PyPI release| image:: https://github.com/sageteam-org/django-sage-painless/blob/develop/docs/images/tag_pypi_0.0.8.png?raw=true\r\n :alt: django-sage-painless\r\n.. |Supported Python versions| image:: https://github.com/sageteam-org/django-sage-painless/blob/develop/docs/images/tag_python-02.png?raw=true\r\n :alt: django-sage-painless\r\n.. |Supported Django versions| image:: https://github.com/sageteam-org/django-sage-painless/blob/develop/docs/images/tag_django.png?raw=true\r\n :alt: django-sage-painless\r\n.. |Documentation| image:: https://github.com/sageteam-org/django-sage-painless/blob/develop/docs/images/tag_docs.png?raw=true\r\n :alt: django-sage-painless\r\n.. |Test| image:: https://github.com/sageteam-org/django-sage-painless/blob/develop/docs/images/tag_test.png?raw=true\r\n :alt: django-sage-painless\r\n.. |sepehr| image:: https://github.com/sageteam-org/django-sage-painless/blob/develop/docs/images/sepehr.jpeg?raw=true\r\n :height: 230px\r\n :width: 230px\r\n :alt: Sepehr Akbarzadeh\r\n.. |mehran| image:: https://github.com/sageteam-org/django-sage-painless/blob/develop/docs/images/mehran.png?raw=true\r\n :height: 340px\r\n :width: 225px\r\n :alt: Mehran Rahmanzadeh\r\n",
"bugtrack_url": null,
"license": "GNU",
"summary": "video streaming based on Django",
"version": "0.2.0",
"project_urls": {
"Download": "https://github.com/sageteam-org/django-sage-streaming/archive/refs/tags/0.1.0.tar.gz",
"Homepage": "https://github.com/J3dd4/fork-django-streaming"
},
"split_keywords": [
"django",
"python",
"streaming",
"video streaming"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9fb04e3973d2f7b444ed8fcacecb7b86ffb46163bc3b8ab97df8134385188fbd",
"md5": "5ac7d767d8946023c6b7992e9737d12a",
"sha256": "01ec2986c90ea748c67d51623a24790761e5cdff280faf559ec380e0da616fef"
},
"downloads": -1,
"filename": "fork_django_streaming-0.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "5ac7d767d8946023c6b7992e9737d12a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.5",
"size": 21926,
"upload_time": "2023-08-12T06:58:35",
"upload_time_iso_8601": "2023-08-12T06:58:35.211566Z",
"url": "https://files.pythonhosted.org/packages/9f/b0/4e3973d2f7b444ed8fcacecb7b86ffb46163bc3b8ab97df8134385188fbd/fork_django_streaming-0.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "0e8750ab27bd4a2fa8b99871617e45e92f4b65dfe45893adef156ab1be1d6a08",
"md5": "2efcbd16512c628423f326c4b90ca2cd",
"sha256": "f657d8f467eaa7b2d0d9f09cd1d7324d99fdfe6e15758786befbb70bc8dbefcd"
},
"downloads": -1,
"filename": "fork-django-streaming-0.2.0.tar.gz",
"has_sig": false,
"md5_digest": "2efcbd16512c628423f326c4b90ca2cd",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.5",
"size": 19772,
"upload_time": "2023-08-12T06:58:37",
"upload_time_iso_8601": "2023-08-12T06:58:37.177659Z",
"url": "https://files.pythonhosted.org/packages/0e/87/50ab27bd4a2fa8b99871617e45e92f4b65dfe45893adef156ab1be1d6a08/fork-django-streaming-0.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-08-12 06:58:37",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "J3dd4",
"github_project": "fork-django-streaming",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "fork-django-streaming"
}