nativeshell.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. const viewdata = JSON.parse(window.atob("@@data@@"));
  2. console.log(viewdata);
  3. const features = [
  4. "filedownload",
  5. "displaylanguage",
  6. "htmlaudioautoplay",
  7. "htmlvideoautoplay",
  8. "externallinks",
  9. //"clientsettings",
  10. "multiserver",
  11. "remotecontrol",
  12. ];
  13. const plugins = [
  14. 'mpvVideoPlayer',
  15. 'mpvAudioPlayer',
  16. ];
  17. function loadScript(src) {
  18. return new Promise((resolve, reject) => {
  19. const s = document.createElement('script');
  20. s.src = src;
  21. s.onload = resolve;
  22. s.onerror = reject;
  23. document.head.appendChild(s);
  24. });
  25. }
  26. // Add plugin loaders
  27. for (const plugin of plugins) {
  28. window[plugin] = async () => {
  29. await loadScript(`${viewdata.scriptPath}${plugin}.js`);
  30. return window["_" + plugin];
  31. };
  32. }
  33. window.NativeShell = {
  34. openUrl(url, target) {
  35. window.api.system.openExternalUrl(url);
  36. },
  37. downloadFile(downloadInfo) {
  38. window.api.system.openExternalUrl(downloadInfo.url);
  39. },
  40. //openClientSettings() {
  41. // window.NativeInterface.openClientSettings();
  42. //},
  43. getPlugins() {
  44. return plugins;
  45. }
  46. };
  47. function getDeviceProfile() {
  48. return {
  49. 'Name': 'Jellyfin Media Player',
  50. 'MusicStreamingTranscodingBitrate': 1280000,
  51. 'TimelineOffsetSeconds': 5,
  52. 'TranscodingProfiles': [
  53. {'Type': 'Audio'},
  54. {
  55. 'Container': 'ts',
  56. 'Type': 'Video',
  57. 'Protocol': 'hls',
  58. 'AudioCodec': 'aac,mp3,ac3,opus,flac,vorbis',
  59. 'VideoCodec': 'h264,h265,hevc,mpeg4,mpeg2video',
  60. 'MaxAudioChannels': '6'
  61. },
  62. {'Container': 'jpeg', 'Type': 'Photo'}
  63. ],
  64. 'DirectPlayProfiles': [{'Type': 'Video'}, {'Type': 'Audio'}, {'Type': 'Photo'}],
  65. 'ResponseProfiles': [],
  66. 'ContainerProfiles': [],
  67. 'CodecProfiles': [],
  68. 'SubtitleProfiles': [
  69. {'Format': 'srt', 'Method': 'External'},
  70. {'Format': 'srt', 'Method': 'Embed'},
  71. {'Format': 'ass', 'Method': 'External'},
  72. {'Format': 'ass', 'Method': 'Embed'},
  73. {'Format': 'sub', 'Method': 'Embed'},
  74. {'Format': 'sub', 'Method': 'External'},
  75. {'Format': 'ssa', 'Method': 'Embed'},
  76. {'Format': 'ssa', 'Method': 'External'},
  77. {'Format': 'smi', 'Method': 'Embed'},
  78. {'Format': 'smi', 'Method': 'External'},
  79. {'Format': 'pgssub', 'Method': 'Embed'},
  80. {'Format': 'dvdsub', 'Method': 'Embed'},
  81. {'Format': 'pgs', 'Method': 'Embed'}
  82. ]
  83. };
  84. }
  85. async function createApi() {
  86. await loadScript('qrc:///qtwebchannel/qwebchannel.js');
  87. const channel = await new Promise((resolve) => {
  88. /*global QWebChannel */
  89. new QWebChannel(window.qt.webChannelTransport, resolve);
  90. });
  91. return channel.objects;
  92. }
  93. window.NativeShell.AppHost = {
  94. async init() {
  95. window.api = await createApi();
  96. },
  97. getDefaultLayout() {
  98. return "desktop";
  99. },
  100. supports(command) {
  101. return features.includes(command.toLowerCase());
  102. },
  103. getDeviceProfile,
  104. getSyncProfile: getDeviceProfile,
  105. appName() {
  106. return "Jellyfin Media Player";
  107. },
  108. appVersion() {
  109. return navigator.userAgent.split(" ")[1];
  110. },
  111. deviceName() {
  112. return viewdata.deviceName;
  113. }
  114. };