-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(titles): Use player API as primary source for main title
- Use movie_player.getPlayerResponse() as primary method to fetch original title - Keep oembed API as fallback method for reliability - Add script injection and custom event handling - Better error handling with multiple fallback levels
- Loading branch information
Showing
7 changed files
with
139 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (C) 2025-present YouGo (https://github.com/youg-o) | ||
* This program is licensed under the GNU Affero General Public License v3.0. | ||
* You may redistribute it and/or modify it under the terms of the license. | ||
* | ||
* Attribution must be given to the original author. | ||
* This program is distributed without any warranty; see the license for details. | ||
*/ | ||
|
||
|
||
|
||
(() => { | ||
const LOG_PREFIX = '[YNT]'; | ||
const LOG_STYLES = { | ||
MAIN_TITLE: { context: '[MAIN TITLE]', color: '#fcd34d' } | ||
}; | ||
|
||
function createLogger(category) { | ||
return (message, ...args) => { | ||
console.log( | ||
`%c${LOG_PREFIX}${category.context} ${message}`, | ||
`color: ${category.color}`, | ||
...args | ||
); | ||
}; | ||
} | ||
|
||
const mainTitleLog = createLogger(LOG_STYLES.MAIN_TITLE); | ||
|
||
function getOriginalTitle() { | ||
const player = document.getElementById('movie_player'); | ||
if (!player) { | ||
mainTitleLog('Player not found'); | ||
window.dispatchEvent(new CustomEvent('ynt-title-data', { | ||
detail: { title: null } | ||
})); | ||
return; | ||
} | ||
|
||
try { | ||
const response = player.getPlayerResponse(); | ||
// Debug logs | ||
//mainTitleLog('Player response:', response); | ||
//mainTitleLog('Video details:', response?.videoDetails); | ||
|
||
const title = response?.videoDetails?.title; | ||
|
||
if (title) { | ||
mainTitleLog('Found title from player response:', title); | ||
window.dispatchEvent(new CustomEvent('ynt-title-data', { | ||
detail: { title } | ||
})); | ||
} else { | ||
mainTitleLog('No title found in player response'); | ||
window.dispatchEvent(new CustomEvent('ynt-title-data', { | ||
detail: { title: null } | ||
})); | ||
} | ||
} catch (error) { | ||
mainTitleLog('Error getting title:', error); | ||
window.dispatchEvent(new CustomEvent('ynt-title-data', { | ||
detail: { title: null } | ||
})); | ||
} | ||
} | ||
|
||
getOriginalTitle(); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters