2025-12-03 21:56:50 +00:00
|
|
|
import { apiClient } from '@/services/api/client';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Service HLS pour gérer les URLs et informations de streaming HLS
|
|
|
|
|
* T0335: Create HLS Streaming Frontend Service
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Génère l'URL du master playlist pour un track
|
|
|
|
|
* @param trackId - ID du track
|
|
|
|
|
* @returns URL du master playlist
|
|
|
|
|
*/
|
2025-12-22 21:56:37 +00:00
|
|
|
export function getHLSMasterPlaylistURL(trackId: string): string {
|
2025-12-03 21:56:50 +00:00
|
|
|
const baseURL = apiClient.defaults.baseURL || '';
|
|
|
|
|
// Enlever le /api/v1 de la fin si présent, car on va ajouter /api/tracks
|
|
|
|
|
const cleanBaseURL = baseURL.replace(/\/api\/v1$/, '');
|
|
|
|
|
return `${cleanBaseURL}/api/v1/tracks/${trackId}/hls/master.m3u8`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Génère l'URL d'une quality playlist pour un track et bitrate
|
|
|
|
|
* @param trackId - ID du track
|
|
|
|
|
* @param bitrate - Bitrate (ex: "128k", "192k", "320k")
|
|
|
|
|
* @returns URL de la quality playlist
|
|
|
|
|
*/
|
2025-12-13 02:34:34 +00:00
|
|
|
export function getHLSQualityPlaylistURL(
|
2025-12-22 21:56:37 +00:00
|
|
|
trackId: string,
|
2025-12-13 02:34:34 +00:00
|
|
|
bitrate: string,
|
|
|
|
|
): string {
|
2025-12-03 21:56:50 +00:00
|
|
|
const baseURL = apiClient.defaults.baseURL || '';
|
|
|
|
|
const cleanBaseURL = baseURL.replace(/\/api\/v1$/, '');
|
|
|
|
|
return `${cleanBaseURL}/api/v1/tracks/${trackId}/hls/${bitrate}/playlist.m3u8`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Génère l'URL d'un segment pour un track, bitrate et nom de segment
|
|
|
|
|
* @param trackId - ID du track
|
|
|
|
|
* @param bitrate - Bitrate (ex: "128k", "192k", "320k")
|
|
|
|
|
* @param segment - Nom du segment (ex: "segment_000.ts")
|
|
|
|
|
* @returns URL du segment
|
|
|
|
|
*/
|
2025-12-13 02:34:34 +00:00
|
|
|
export function getHLSSegmentURL(
|
2025-12-22 21:56:37 +00:00
|
|
|
trackId: string,
|
2025-12-13 02:34:34 +00:00
|
|
|
bitrate: string,
|
|
|
|
|
segment: string,
|
|
|
|
|
): string {
|
2025-12-03 21:56:50 +00:00
|
|
|
const baseURL = apiClient.defaults.baseURL || '';
|
|
|
|
|
const cleanBaseURL = baseURL.replace(/\/api\/v1$/, '');
|
|
|
|
|
return `${cleanBaseURL}/api/v1/tracks/${trackId}/hls/${bitrate}/${segment}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Interface pour les informations d'un stream HLS
|
|
|
|
|
*/
|
|
|
|
|
export interface HLSStreamInfo {
|
2025-12-22 21:56:37 +00:00
|
|
|
trackId: string;
|
2025-12-03 21:56:50 +00:00
|
|
|
bitrates: number[];
|
|
|
|
|
playlistUrl: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Interface pour le statut d'un stream HLS (T0339, T0340)
|
|
|
|
|
*/
|
|
|
|
|
export interface HLSStreamStatus {
|
|
|
|
|
status: 'pending' | 'processing' | 'ready' | 'failed';
|
|
|
|
|
bitrates: number[];
|
|
|
|
|
segments_count: number;
|
|
|
|
|
playlist_url: string;
|
2025-12-22 21:56:37 +00:00
|
|
|
track_id: string;
|
2025-12-03 21:56:50 +00:00
|
|
|
created_at?: string;
|
|
|
|
|
updated_at?: string;
|
|
|
|
|
queue_job_id?: number;
|
|
|
|
|
retry_count?: number;
|
|
|
|
|
started_at?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Récupère les informations d'un stream HLS pour un track
|
|
|
|
|
* @param trackId - ID du track
|
|
|
|
|
* @returns Informations du stream HLS
|
|
|
|
|
*/
|
2025-12-13 02:34:34 +00:00
|
|
|
export async function getHLSStreamInfo(
|
2025-12-22 21:56:37 +00:00
|
|
|
trackId: string,
|
2025-12-13 02:34:34 +00:00
|
|
|
): Promise<HLSStreamInfo> {
|
2025-12-03 21:56:50 +00:00
|
|
|
const response = await apiClient.get(`/tracks/${trackId}/hls/info`);
|
|
|
|
|
return response.data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Récupère le statut d'un stream HLS pour un track (T0339, T0340)
|
|
|
|
|
* @param trackId - ID du track
|
|
|
|
|
* @returns Statut du stream HLS
|
|
|
|
|
*/
|
2025-12-13 02:34:34 +00:00
|
|
|
export async function getHLSStreamStatus(
|
2025-12-22 21:56:37 +00:00
|
|
|
trackId: string,
|
2025-12-13 02:34:34 +00:00
|
|
|
): Promise<HLSStreamStatus> {
|
2025-12-03 21:56:50 +00:00
|
|
|
const response = await apiClient.get(`/tracks/${trackId}/hls/status`);
|
|
|
|
|
return response.data;
|
|
|
|
|
}
|