Support for browser webplayer and subtitles in new webplugin
This commit is contained in:
parent
e55735f409
commit
70bba5fc96
5 changed files with 31 additions and 11 deletions
|
@ -105,10 +105,10 @@ Vue.component('media', {
|
||||||
|
|
||||||
play: async function(item) {
|
play: async function(item) {
|
||||||
if (!this.selectedDevice.accepts[item.type]) {
|
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)
|
if (item.title)
|
||||||
status.title = item.title;
|
status.title = item.title;
|
||||||
|
@ -167,14 +167,24 @@ Vue.component('media', {
|
||||||
},
|
},
|
||||||
|
|
||||||
startStreaming: async function(item) {
|
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', {
|
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', {
|
this.bus.$emit('streaming-started', {
|
||||||
url: ret.url,
|
url: ret.url,
|
||||||
resource: resource,
|
resource: item.url,
|
||||||
});
|
});
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -38,7 +38,14 @@ MediaPlayers.browser = Vue.extend({
|
||||||
return {};
|
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() {
|
stop: async function() {
|
||||||
|
|
|
@ -53,10 +53,10 @@ MediaPlayers.local = Vue.extend({
|
||||||
return await request(this.pluginPrefix.concat('.status'));
|
return await request(this.pluginPrefix.concat('.status'));
|
||||||
},
|
},
|
||||||
|
|
||||||
play: async function(resource, subtitles=undefined) {
|
play: async function(item, subtitles=undefined) {
|
||||||
return await request(
|
return await request(
|
||||||
this.pluginPrefix.concat('.play'),
|
this.pluginPrefix.concat('.play'),
|
||||||
{resource: resource, subtitles: subtitles}
|
{resource: item.url, subtitles: subtitles}
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -358,7 +358,7 @@ class MediaPlugin(Plugin):
|
||||||
return filename.lower().split('.')[-1] in cls.audio_extensions
|
return filename.lower().split('.')[-1] in cls.audio_extensions
|
||||||
|
|
||||||
@action
|
@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.
|
Starts streaming local media over the specified HTTP port.
|
||||||
The stream will be available to HTTP clients on
|
The stream will be available to HTTP clients on
|
||||||
|
@ -367,6 +367,9 @@ class MediaPlugin(Plugin):
|
||||||
:param media: Media to stream
|
:param media: Media to stream
|
||||||
:type media: str
|
: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
|
:param download: Set to True if you prefer to download the file from
|
||||||
the streaming link instead of streaming it
|
the streaming link instead of streaming it
|
||||||
:type download: bool
|
:type download: bool
|
||||||
|
@ -391,7 +394,7 @@ class MediaPlugin(Plugin):
|
||||||
self.logger.info('Starting streaming {}'.format(media))
|
self.logger.info('Starting streaming {}'.format(media))
|
||||||
response = requests.put('{url}/media{download}'.format(
|
response = requests.put('{url}/media{download}'.format(
|
||||||
url=http.local_base_url, download='?download' if download else ''),
|
url=http.local_base_url, download='?download' if download else ''),
|
||||||
json={'source': media})
|
json={'source': media, 'subtitles': subtitles})
|
||||||
|
|
||||||
if not response.ok:
|
if not response.ok:
|
||||||
self.logger.warning('Unable to start streaming: {}'.
|
self.logger.warning('Unable to start streaming: {}'.
|
||||||
|
|
|
@ -215,7 +215,7 @@ class LocalMediaSearcher(MediaSearcher):
|
||||||
filter(MediaToken.token.in_(query_tokens)). \
|
filter(MediaToken.token.in_(query_tokens)). \
|
||||||
group_by(MediaFile.path). \
|
group_by(MediaFile.path). \
|
||||||
having(func.count(MediaFileToken.token_id) >= len(query_tokens)):
|
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] = {
|
results[file_record.path] = {
|
||||||
'url': 'file://' + file_record.path,
|
'url': 'file://' + file_record.path,
|
||||||
'title': os.path.basename(file_record.path),
|
'title': os.path.basename(file_record.path),
|
||||||
|
|
Loading…
Reference in a new issue