Skip to content

Commit

Permalink
see changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
shiyiya committed Apr 13, 2024
1 parent 1aaf873 commit 337f27f
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 31 deletions.
53 changes: 30 additions & 23 deletions packages/docs/public/oplayer.html
Original file line number Diff line number Diff line change
Expand Up @@ -211,33 +211,38 @@

<script src="https://cdn.jsdelivr.net/npm/@oplayer/[email protected]/dist/index.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@oplayer/[email protected]/dist/index.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@oplayer/[email protected].23/dist/index.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@oplayer/[email protected].24/dist/index.min.js"></script>

<script src="https://cdn.jsdelivr.net/npm/@oplayer/[email protected].3/dist/airplay.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@oplayer/[email protected].5/dist/chromecast.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@oplayer/[email protected].6/dist/airplay.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@oplayer/[email protected].6/dist/chromecast.min.js"></script>

<script>
var playlistScriptCdn = 'https://cdn.jsdelivr.net/npm/@oplayer/plugins@latest/dist/playlist.min.js'
var playlistScriptCdn =
'https://cdn.jsdelivr.net/npm/@oplayer/[email protected]/dist/playlist.min.js'
var danmakuScriptCdn = 'https://cdn.jsdelivr.net/npm/@oplayer/danmaku@latest/dist/index.min.js'

var query = document.location.search.substring(1)
var src, poster, subtitle, danmaku, title, watermark
var playlist = [],
deps = [],
isM3u = false

if (query.endsWith('==')) {
src = atob(query.substring(0, query.length - 2))
} else if (query.startsWith('http')) {
src = safeDecodeURIComponent(query.substring(0, query.length - 1))
m3u = false,
p = 0

var _query = decodeURIComponent(query || '')
if (_query.startsWith('http')) {
// ?https://xx.com= 有时候会自动带上 “=”
src = _query.endsWith('=') ? _query.substring(0, _query.length - 1) : query
} else if (_query.endsWith('=')) {
src = atob(_query)
} else {
var search = new URLSearchParams(document.location.search)
src = safeDecodeURIComponent(search.get('src'))
playlist = JSON.parse(safeDecodeURIComponent(search.get('playlist')) || '[]')
poster = safeDecodeURIComponent(search.get('poster'))
title = safeDecodeURIComponent(search.get('title')) || '❤OPlayer'
danmaku = safeDecodeURIComponent(search.get('danmaku'))
isM3u = Boolean(search.get('m3u'))
m3u = safeDecodeURIComponent(search.get('m3u'))
p = search.get('p') || 0

subtitle = search.get('subtitle')
? {
Expand Down Expand Up @@ -267,9 +272,9 @@
: undefined
}

if (/m3u(#|\?|$)/i.test(src) || isM3u) {
playlist = [{ title: '-', src, poster }]
isM3u = true
if (/m3u(#|\?|$)/i.test(src) || m3u) {
playlist = [{ title: '-', src: typeof m3u == 'string' ? m3u : src, poster }]
m3u = true
src = undefined
deps.push(['https://cdn.jsdelivr.net/npm/[email protected]/dist/m3u8-parser.min.js'])
}
Expand Down Expand Up @@ -328,7 +333,7 @@
library: 'https://cdn.jsdelivr.net/npm/[email protected]/dist/hls.min.js'
}),
ODash({ library: 'https://cdn.dashjs.org/latest/dash.all.min.js' }),
OMpegts(),
OMpegts({ library: 'https://cdn.jsdelivr.net/npm/mpegts.js/dist/mpegts.min.js' }),
new OAirplay(),
new OChromecast()
])
Expand All @@ -342,22 +347,24 @@
OPlaylist.m3u8Parser = m3u8Parser
player.applyPlugin(
new OPlaylist({
initialIndex: 0,
initialIndex: p,
autoHide: false,
sources: playlist,
m3uList: isM3u
m3uList: m3u
? {
sourceFormat(info) {
try {
const chunk = info.title.substring(3).split(' ')
const titleWith = chunk.find((it) => it.includes('title')).split('=')[1]
const posterWith = chunk.find((it) => it.includes('logo'))?.split('=')[1]
const chunk = info.title.substring(3).split('" ')
const titleWith = /group-title="(.+",.+)/.exec(info.title)
const posterWith = /tvg-logo="(.+)"/.exec(info.title)
return {
src: info.uri,
title: titleWith.substring(1, titleWith.length),
poster: posterWith?.substring(1, posterWith.length)
format: 'm3u8',
title: titleWith ? titleWith[1] : /group-title="(.+)"/.exec(info.title)[1],
poster: posterWith && posterWith[1]
}
} catch (error) {
return { src: info.uri, title: info.title }
return { src: info.uri, title: info.title, format: 'm3u8' }
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/mpegts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oplayer/mpegts",
"version": "1.2.23",
"version": "1.2.24",
"description": "mpegts.js plugin for oplayer",
"type": "module",
"main": "./dist/index.es.js",
Expand Down
13 changes: 9 additions & 4 deletions packages/mpegts/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Player, PlayerPlugin, Source, PartialRequired } from '@oplayer/core'
import { type Player, type PlayerPlugin, type Source, type PartialRequired, loadSDK } from '@oplayer/core'
import type Mpegts from 'mpegts.js'

const PLUGIN_NAME = 'oplayer-plugin-mpegts'
Expand All @@ -14,6 +14,7 @@ export type Active = (
export type MpegtsPluginOptions = {
config?: Partial<Mpegts.Config>
matcher?: Matcher
library?: string
}

const REG = /flv|ts|m2ts(#|\?|$)/i
Expand Down Expand Up @@ -52,12 +53,16 @@ class MpegtsPlugin implements PlayerPlugin {
}

async load({ $video, options }: Player, source: Source) {
const { matcher } = this.options
const { matcher, library } = this.options

if (!matcher($video, source)) return false

//@ts-ignore
MpegtsPlugin.library ??= (await import('mpegts.js/dist/mpegts.js')).default
if (!MpegtsPlugin.library) {
MpegtsPlugin.library =
(globalThis as any).mpegts ||
//@ts-expect-error
(library ? await loadSDK(library, 'mpegts') : (await import('mpegts.js/dist/mpegts.js')).default)
}

if (!MpegtsPlugin.library.isSupported()) return false

Expand Down
2 changes: 2 additions & 0 deletions packages/plugins/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## UnRelease

- playlist: fix error scroll position

## 1.0.12-beta.3

- vtt thumbnails: `prefix` options
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oplayer/plugins",
"version": "1.0.12-beta.5",
"version": "1.0.12-beta.6",
"author": "shiyiya",
"description": "oplayer's plugin",
"homepage": "https://github.com/shiyiya/oplayer",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/src/playlist.css
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
}

.playlist-list::-webkit-scrollbar {
width: 3px;
width: 0.3em;
}

.playlist-list::-webkit-scrollbar-thumb {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/src/playlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export default class PlaylistPlugin implements PlayerPlugin {
const list = this.$root.querySelector('.playlist-list')!
const active = this.$root.querySelector<HTMLDivElement>('.playlist-source__active')
if (active && list.scrollHeight > 0 && this.currentIndex) {
list.scrollTo(0, active.offsetHeight * this.currentIndex)
list.scrollTo(0, active.offsetTop - active.offsetHeight)
}
}
})
Expand Down

0 comments on commit 337f27f

Please sign in to comment.