Skip to content

Commit

Permalink
chore: Release 0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
endrl committed Nov 3, 2023
1 parent f14a9ab commit 8b2e82f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jellyfin-segment-editor",
"version": "0.2.0",
"version": "0.3.0",
"description": "Manage Intro, Outro and other Segments",
"productName": "Jellyfin Segment Editor",
"author": "endrl <119058008+endrl@users.noreply.github.com>",
Expand Down
53 changes: 26 additions & 27 deletions src/composables/videoApi.ts
Original file line number Diff line number Diff line change
@@ -1,61 +1,60 @@
import { useApiStore } from 'stores/api'
import { ItemDto } from 'src/interfaces';
import { CREATOR_UUID } from './constants';

export function useVideoApi() {
const { buildUrl, postJson } = useApiStore()

/**
* Get a media stream url by id
* Endpoint: Videos/itemId/master.m3u8 is HLS. HLS supports audio: aac, mp3 ac3, eac3. video container: fMP4, mp2ts
* Doc: https://datatracker.ietf.org/doc/html/draft-pantos-http-live-streaming-20#section-3.1 -3.4
* @param itemId itemId of media
* @param forceVideoReason force transcode of video
* @param forceAudioReason force transcode of audio
* @param container ts, mp4, ...
*/
function getVideoStream(itemId: ItemDto['Id'], forceVideoReason?:string, forceAudioReason?: string, container?: string) {
/**
* Get a media stream url by id
* Endpoint: Videos/itemId/master.m3u8 is HLS. HLS supports audio: aac, mp3 ac3, eac3. video container: fMP4, mp2ts
* Doc: https://datatracker.ietf.org/doc/html/draft-pantos-http-live-streaming-20#section-3.1 -3.4
* @param itemId itemId of media
* @param forceVideoReason force transcode of video
* @param forceAudioReason force transcode of audio
* @param container ts, mp4, ...
*/
function getVideoStream(itemId: ItemDto['Id'], forceVideoReason?: string, forceAudioReason?: string, container?: string) {
const query: Map<string, any> = new Map();
const transcodeReasons: string[] = [];
query.set('MediaSourceId',itemId)
query.set('MediaSourceId', itemId)

// if there is no transcode, enable direct stream
if (!forceAudioReason && !forceVideoReason){
query.set('static',true)
if (!forceAudioReason && !forceVideoReason) {
query.set('static', true)
}
if(forceAudioReason){
if (forceAudioReason) {
transcodeReasons.push(`Audio not supported (${forceAudioReason})`)
query.set('AudioCodec','aac')
query.set('TranscodingMaxAudioChannels',2)
query.set('AudioCodec', 'aac')
query.set('TranscodingMaxAudioChannels', 2)
}
if(forceVideoReason){
if (forceVideoReason) {
transcodeReasons.push(`Video not supported (${forceVideoReason}`)
query.set('VideoCodec','h264')
query.set('VideoCodec', 'h264')
}
if(transcodeReasons.length){
query.set('transcodeReasons',transcodeReasons.join(','))
if (transcodeReasons.length) {
query.set('transcodeReasons', transcodeReasons.join(','))
}
if (container){
query.set('segmentContainer',container)
if (container) {
query.set('segmentContainer', container)
}
// skip session, we can't stop it without userId...
// query.set('PlaySessionId',CREATOR_UUID)

const baseUrl = `Videos/${itemId}/master.m3u8`;
return buildUrl(baseUrl,query)
return buildUrl(baseUrl, query)
}

/**
* Report end of playback. Requires userId from httpContext server side...
* @param itemId
*/
function reportPlayingStop(itemId: ItemDto['Id']){
function reportPlayingStop(itemId: ItemDto['Id']) {
const payload = {
ItemId: itemId,
MediaSourceId: itemId,
PlaySessionId: CREATOR_UUID
PlaySessionId: 'xxx'
}
postJson('Sessions/Playing/Stopped',payload)
postJson('Sessions/Playing/Stopped', payload)
}

return { getVideoStream, reportPlayingStop }
Expand Down

0 comments on commit 8b2e82f

Please sign in to comment.