Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I am having a problem with ConnectionManager is undefined and ApiClient is undefined. #17

Open
movieperson opened this issue Jun 12, 2023 · 0 comments

Comments

@movieperson
Copy link

Jellyfin 23 Apr download latest Firefox on Windows 10.

Same file errors on the JS file as others have previously reported

let userid = (await ApiClient.getCurrentUser()).Id;
ApiClient.getItem(userid, itemid).then(r => {

ApiClient.getItems(userid, itemid).then(r => openPotplayer(r.Items[0].Id));

Please help..... What am I doing wrong?

Doc included below

##########################################################

I am adapting it to run mpv.
I can launch the powershell script and it opens mpv properly.

registry entry is correct

potplayer.reg

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\potplayer]
@="URL:potplayer protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\potplayer\shell]
[HKEY_CLASSES_ROOT\potplayer\shell\open]
[HKEY_CLASSES_ROOT\potplayer\shell\open\command]
@="powershell -File D:\apps\Jellyfin-mpv-master\potplayer.ps1 %1"

potplayer.ps1

Add-Type -Assembly System.Web
$path=$args[0]
$path=$path -replace "potplayer://" , ""
$path= [System.Web.HttpUtility]::UrlDecode($path)
echo $path
& "D:\Apps\mpv_default\mpv.exe" $path

userscript.js

// ==UserScript==
// @name Jellyfin with Potplayer
// @Version 0.1
// @description play video with Potplayer
// @author Tccoin
// @match http://DLNAWebserver:8096/jellyfin/web/index.html
// ==/UserScript==

(function() {
'use strict';
let openPotplayer = async (itemid) => {
let userid = (await ApiClient.getCurrentUser()).Id;
ApiClient.getItem(userid, itemid).then(r => {
if (r.Path) {
let path = r.Path.replace(/\/g, '/');
path = path.replace('E:', 'Q:');
console.log(path);
window.open('potplayer://' + path)
} else {
ApiClient.getItems(userid, itemid).then(r => openPotplayer(r.Items[0].Id));
}
})
};

let bindEvent = async () => {
let buttons = [];
let retry = 6 + 1;
while (buttons.length == 0 && retry > 0) {
await new Promise(resolve => setTimeout(resolve, 500));
buttons = document.querySelectorAll('[data-mode=play],[data-mode=resume],[data-action=resume]');
retry -= 1;
}
for (let button of buttons) {
let nextElementSibling = button.nextElementSibling;
let parentElement = button.parentElement;
let outerHTML = button.outerHTML;
button.parentElement.removeChild(button);
let newButton = document.createElement('button');
if (nextElementSibling) {
parentElement.insertBefore(newButton, nextElementSibling);
} else {
parentElement.append(newButton);
}
newButton.outerHTML = outerHTML;
}
buttons = document.querySelectorAll('[data-mode=play],[data-mode=resume]');
for (let button of buttons) {
button.removeAttribute('data-mode');
button.addEventListener('click', e => {
e.stopPropagation();
let itemid = /id=(.*?)&serverId/.exec(window.location.hash)[1];
openPotplayer(itemid);
});
}
buttons = document.querySelectorAll('[data-action=resume]');
for (let button of buttons) {
button.removeAttribute('data-action');
button.addEventListener('click', e => {
e.stopPropagation();
let item = e.target;
while (!item.hasAttribute('data-id')) { item = item.parentNode }
let itemid = item.getAttribute('data-id');
openPotplayer(itemid);
});
}
};

let lazyload = () => {
let items = document.querySelectorAll('[data-src].lazy');
let y = document.scrollingElement.scrollTop;
let intersectinglist = [];
for (let item of items) {
let windowHeight = document.body.offsetHeight;
let itemTop = item.getBoundingClientRect().top;
let itemHeight = item.offsetHeight;
if (itemTop + itemHeight >= 0 && itemTop <= windowHeight) {
intersectinglist.push(item);
}
}
for (let item of intersectinglist) {
item.style.setProperty('background-image', url("${item.getAttribute('data-src')}"));
item.classList.remove('lazy');
item.removeAttribute('data-src');
};
};

window.addEventListener('scroll', lazyload);

window.addEventListener('viewshow', async() => {
bindEvent();
window.addEventListener('hashchange', bindEvent);
});
})();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant