020415efb9
fixing HTML5 media support.
https://stackoverflow.com/questions/37044064/html-audio-cant-set-currenttime
https://stackoverflow.com/questions/21956683/enable-access-control-on-simple-http-server
https://stackoverflow.com/questions/5052635/what-is-relation-between-content-length-and-byte-ranges-in-http-1-1
https://stackoverflow.com/questions/16725907/google-app-engine-serving-mp3-for-audio-element-needs-content-range-header
I was trying to use HTML5 audio tag to display audios like:
```html
<audio id="elem_audio" src="myfile.mp3" controls></audio>
```
![image](https://user-images.githubusercontent.com/5332158/79063321-565b5500-7c77-11ea-9f8d-6e1df6f07892.png)
But the progress bar seek was not working. After researching, I found the problem was the HTML server not properly responding to the HTML5 header requests. The HTML server should respond to quite complicated things as 206 partial, properly handle keep-alive, provide media ranges and other HTTP headers: https://stackoverflow.com/questions/37044064/html-audio-cant-set-currenttime
To implement all these on the Simple HTTP server would be quite complicated. Then, instead, I imported the `flask` web server, which is quite simple and straight forward to use. Now, the back-end is using a secure complaint HTTP back-end:
1. https://palletsprojects.com/p/flask/
> Flask is a lightweight WSGI web application framework. It is designed to make getting started quick and easy, with the ability to scale up to complex applications. It began as a simple wrapper around Werkzeug and Jinja and has become one of the most popular Python web application frameworks.
>
> Flask offers suggestions, but doesn't enforce any dependencies or project layout. It is up to the developer to choose the tools and libraries they want to use. There are many extensions provided by the community that make adding new functionality easy.
1. https://docs.pylonsproject.org/projects/waitress/en/latest/
> Waitress is meant to be a production-quality pure-Python WSGI server with very acceptable performance. It has no dependencies except ones which live in the Python standard library. It runs on CPython on Unix and Windows under Python 2.7+ and Python 3.5+. It is also known to run on PyPy 1.6.0 on UNIX. It supports HTTP/1.0 and HTTP/1.1.
Right now, anki does not support fields passing file names directly to HTML audio tags, but this can be easily done with (https://github.com/ankitects/anki/pull 540 - Added arguments to the sound tag) plus the commit 826a97df61
, the HTML5 audio tag can be used like this:
```html
// Audio = [sound:myfile.mp3|onlyfilename]
<audio id="elem_audio" src="{{Audio}}" controls controlsList="nodownload"></audio>
```
![image](https://user-images.githubusercontent.com/5332158/79063736-c539ad80-7c79-11ea-8420-40b72185f4e7.png)
# Conflicts:
# qt/aqt/mediasrv.py
57 lines
1.5 KiB
Python
57 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
import os
|
|
|
|
import setuptools
|
|
|
|
|
|
def package_files(directory):
|
|
entries = []
|
|
for (path, directories, filenames) in os.walk(directory):
|
|
entries.append((path, [os.path.join(path, f) for f in filenames]))
|
|
return entries
|
|
|
|
|
|
# just the Python files for type hints?
|
|
pyonly = os.getenv("PYFILESONLY")
|
|
|
|
if pyonly:
|
|
extra_files = []
|
|
else:
|
|
extra_files = package_files("aqt_data")
|
|
|
|
install_requires = [
|
|
"beautifulsoup4",
|
|
"requests",
|
|
"send2trash",
|
|
"markdown",
|
|
"jsonschema",
|
|
# "pyaudio", # https://anki.tenderapp.com/discussions/add-ons/44009-problems-with-code-completion
|
|
# "pyqtwebengine", # https://github.com/ankitects/anki/pull/530 - Set to checks.yml install and import anki wheels
|
|
"flask",
|
|
"flask_cors",
|
|
"waitress",
|
|
"pyqt5>=5.9",
|
|
'psutil; sys.platform == "win32"',
|
|
'pywin32; sys.platform == "win32"',
|
|
"anki==2.1.28", # automatically updated 1
|
|
]
|
|
|
|
|
|
setuptools.setup(
|
|
name="aqt",
|
|
version="2.1.28", # automatically updated 2
|
|
author="Ankitects Pty Ltd",
|
|
description="Anki's Qt GUI code",
|
|
long_description="Anki's QT GUI code",
|
|
long_description_content_type="text/markdown",
|
|
url="https://apps.ankiweb.net",
|
|
packages=setuptools.find_packages(".", exclude=["tests"]),
|
|
data_files=extra_files,
|
|
license="License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)",
|
|
classifiers=[],
|
|
python_requires=">=3.7",
|
|
package_data={"aqt": ["py.typed"]},
|
|
install_requires=install_requires,
|
|
)
|