Support for browser webplayer and subtitles in new webplugin

This commit is contained in:
Fabio Manganiello 2019-06-26 11:05:16 +02:00
parent e55735f409
commit 70bba5fc96
5 changed files with 31 additions and 11 deletions

View file

@ -105,10 +105,10 @@ Vue.component('media', {
play: async function(item) {
if (!this.selectedDevice.accepts[item.type]) {
item = await this.startStreaming(item.url);
item = await this.startStreaming(item);
}
let status = await this.selectedDevice.play(item.url, item.subtitles);
let status = await this.selectedDevice.play(item, item.subtitles);
if (item.title)
status.title = item.title;
@ -167,14 +167,24 @@ Vue.component('media', {
},
startStreaming: async function(item) {
const resource = item instanceof Object ? item.url : item;
if (typeof item === 'string')
item = {url: item};
const ret = await request('media.start_streaming', {
media: resource,
media: item.url,
subtitles: item.subtitles,
});
const hostRegex = /^(https?:\/\/[^:/]+(:[0-9]+)?\/?)/;
const baseURL = window.location.href.match(hostRegex)[1];
ret.url = ret.url.replace(hostRegex, baseURL);
if (ret.subtitles_url)
ret.subtitles_url = ret.subtitles_url.replace(hostRegex, baseURL);
this.bus.$emit('streaming-started', {
url: ret.url,
resource: resource,
resource: item.url,
});
return ret;

View file

@ -38,7 +38,14 @@ MediaPlayers.browser = Vue.extend({
return {};
},
play: async function(item) {
play: async function(item, subtitles) {
let url = item.url;
if (item.source && item.source.startsWith('file://'))
url += '?webplayer'
let playerWindow = window.open(url, '_blank');
console.log(playerWindow);
return {};
},
stop: async function() {

View file

@ -53,10 +53,10 @@ MediaPlayers.local = Vue.extend({
return await request(this.pluginPrefix.concat('.status'));
},
play: async function(resource, subtitles=undefined) {
play: async function(item, subtitles=undefined) {
return await request(
this.pluginPrefix.concat('.play'),
{resource: resource, subtitles: subtitles}
{resource: item.url, subtitles: subtitles}
);
},

View file

@ -358,7 +358,7 @@ class MediaPlugin(Plugin):
return filename.lower().split('.')[-1] in cls.audio_extensions
@action
def start_streaming(self, media, download=False):
def start_streaming(self, media, subtitles=None, download=False):
"""
Starts streaming local media over the specified HTTP port.
The stream will be available to HTTP clients on
@ -367,6 +367,9 @@ class MediaPlugin(Plugin):
:param media: Media to stream
:type media: str
:param subtitles: Path or URL to the subtitles track to be used
:type subtitles: str
:param download: Set to True if you prefer to download the file from
the streaming link instead of streaming it
:type download: bool
@ -391,7 +394,7 @@ class MediaPlugin(Plugin):
self.logger.info('Starting streaming {}'.format(media))
response = requests.put('{url}/media{download}'.format(
url=http.local_base_url, download='?download' if download else ''),
json={'source': media})
json={'source': media, 'subtitles': subtitles})
if not response.ok:
self.logger.warning('Unable to start streaming: {}'.

View file

@ -215,7 +215,7 @@ class LocalMediaSearcher(MediaSearcher):
filter(MediaToken.token.in_(query_tokens)). \
group_by(MediaFile.path). \
having(func.count(MediaFileToken.token_id) >= len(query_tokens)):
if (os.path.isfile(file_record.path)):
if os.path.isfile(file_record.path):
results[file_record.path] = {
'url': 'file://' + file_record.path,
'title': os.path.basename(file_record.path),