ニジカ投稿局 https://tv.nizika.tv
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

paths.ts 2.8 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import { join } from 'path'
  2. import { CONFIG } from '@server/initializers/config.js'
  3. import { DIRECTORIES, VIDEO_LIVE } from '@server/initializers/constants.js'
  4. import {
  5. isStreamingPlaylist,
  6. MStreamingPlaylistVideo,
  7. MUserExport,
  8. MUserImport,
  9. MVideo,
  10. MVideoFile,
  11. MVideoUUID
  12. } from '@server/types/models/index.js'
  13. import { removeFragmentedMP4Ext } from '@peertube/peertube-core-utils'
  14. import { buildUUID } from '@peertube/peertube-node-utils'
  15. import { isVideoInPrivateDirectory } from './video-privacy.js'
  16. // ################## Video file name ##################
  17. export function generateWebVideoFilename (resolution: number, extname: string) {
  18. return buildUUID() + '-' + resolution + extname
  19. }
  20. export function generateHLSVideoFilename (resolution: number) {
  21. return `${buildUUID()}-${resolution}-fragmented.mp4`
  22. }
  23. // ################## Streaming playlist ##################
  24. export function getLiveDirectory (video: MVideo) {
  25. return getHLSDirectory(video)
  26. }
  27. export function getLiveReplayBaseDirectory (video: MVideo) {
  28. return join(getLiveDirectory(video), VIDEO_LIVE.REPLAY_DIRECTORY)
  29. }
  30. export function getHLSDirectory (video: MVideo) {
  31. if (isVideoInPrivateDirectory(video.privacy)) {
  32. return join(DIRECTORIES.HLS_STREAMING_PLAYLIST.PRIVATE, video.uuid)
  33. }
  34. return join(DIRECTORIES.HLS_STREAMING_PLAYLIST.PUBLIC, video.uuid)
  35. }
  36. export function getHLSRedundancyDirectory (video: MVideoUUID) {
  37. return join(DIRECTORIES.HLS_REDUNDANCY, video.uuid)
  38. }
  39. export function getHlsResolutionPlaylistFilename (videoFilename: string) {
  40. // Video file name already contain resolution
  41. return removeFragmentedMP4Ext(videoFilename) + '.m3u8'
  42. }
  43. export function generateHLSMasterPlaylistFilename (isLive = false) {
  44. if (isLive) return 'master.m3u8'
  45. return buildUUID() + '-master.m3u8'
  46. }
  47. export function generateHlsSha256SegmentsFilename (isLive = false) {
  48. if (isLive) return 'segments-sha256.json'
  49. return buildUUID() + '-segments-sha256.json'
  50. }
  51. // ################## Torrents ##################
  52. export function generateTorrentFileName (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, resolution: number) {
  53. const extension = '.torrent'
  54. const uuid = buildUUID()
  55. if (isStreamingPlaylist(videoOrPlaylist)) {
  56. return `${uuid}-${resolution}-${videoOrPlaylist.getStringType()}${extension}`
  57. }
  58. return uuid + '-' + resolution + extension
  59. }
  60. export function getFSTorrentFilePath (videoFile: MVideoFile) {
  61. return join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename)
  62. }
  63. // ---------------------------------------------------------------------------
  64. export function getFSUserExportFilePath (userExport: MUserExport) {
  65. return join(CONFIG.STORAGE.TMP_PERSISTENT_DIR, userExport.filename)
  66. }
  67. export function getFSUserImportFilePath (userImport: MUserImport) {
  68. return join(CONFIG.STORAGE.TMP_PERSISTENT_DIR, userImport.filename)
  69. }