kivyblocks/kivyblocks/hack_ffpyplayer.py

45 lines
1.2 KiB
Python
Raw Normal View History

2022-02-11 13:20:52 +08:00
2022-04-06 14:00:57 +08:00
from functools import partial
2022-04-23 19:57:11 +08:00
from ffpyplayer.player import MediaPlayer as OldMediaPlayer
2022-02-11 14:23:28 +08:00
from threading import Thread
2022-02-11 13:20:52 +08:00
from kivy.core.video.video_ffpyplayer import VideoFFPy
2022-04-23 19:57:11 +08:00
from kivy.core.video import video_ffpyplayer
external_ff_opts = {}
external_lib_opts = {}
def set_external_ff_opts(dic):
external_ff_opts = dic
def set_external_lib_opts(dic):
external_lib_opts = dic
def MediaPlayer(filename, *args, ff_opts={}, lib_opts={}, **kw):
ff_opts.update(external_ff_opts)
lib_opts.update(external_lib_opts)
if filename.startswith('http://') or \
filename.startswith('https://'):
2022-04-29 12:17:10 +08:00
headers_str = get_spec_headers(filename)
if headers_str is not None:
lib_opts['headers'] = headers_str
2022-04-23 19:57:11 +08:00
return OldMediaPlayer(filename, *args, ff_opts=ff_opts,
lib_opts=lib_opts, **kw)
def hack_mediaplayer():
video_ffpyplayer.MediaPlayer = MediaPlayer
2022-02-11 13:20:52 +08:00
2022-02-11 14:23:28 +08:00
headers_pattern = {
}
2022-02-11 13:20:52 +08:00
2022-02-11 14:23:28 +08:00
def set_headers_pattern(pattern, headers_str):
headers_pattern[pattern] = headers_str
def get_spec_headers(filename):
for p in headers_pattern.keys():
2022-02-11 13:20:52 +08:00
if p in filename:
2022-04-29 12:17:10 +08:00
headers = headers_pattern[p]
headers_str = ';'.join([f'{k}={v}' for k,v in headers.items()])
return "$'%s'" % headers_str
2022-02-11 13:20:52 +08:00
return None