-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(plugin): Skip Live Songs - Automatically skip most non-studio recordings #4093
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
Open
amontariol
wants to merge
27
commits into
pear-devs:master
Choose a base branch
from
amontariol:skip-live-songs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
925ef98
Plugin that tries to skip live versions of songs
amontariol bee0523
Update src/plugins/skip-live-songs/index.ts
amontariol 7ab5bf3
Update src/plugins/skip-live-songs/index.ts
amontariol 63776bf
Update src/plugins/skip-live-songs/index.ts
amontariol 4e6256e
Update src/plugins/skip-live-songs/index.ts
amontariol e1f559e
Update src/plugins/skip-live-songs/index.ts
amontariol f63bb72
Update src/plugins/skip-live-songs/patterns.ts
amontariol 43992d7
Update src/plugins/skip-live-songs/patterns.ts
amontariol 10c4584
Update src/plugins/skip-live-songs/patterns.ts
amontariol c60d715
Update src/plugins/skip-live-songs/patterns.ts
amontariol 0f9c16e
Update src/plugins/skip-live-songs/patterns.ts
amontariol 70e6ce1
Update src/plugins/skip-live-songs/index.ts
amontariol e2c07fe
Update src/plugins/skip-live-songs/index.ts
amontariol 41f8334
Update src/plugins/skip-live-songs/patterns.ts
amontariol 473c942
Update src/plugins/skip-live-songs/index.ts
amontariol 548c536
Update src/plugins/skip-live-songs/index.ts
amontariol dd350d4
Update src/plugins/skip-live-songs/patterns.ts
amontariol 16df9f3
Update src/plugins/skip-live-songs/patterns.ts
amontariol 0000964
Update src/plugins/skip-live-songs/patterns.ts
amontariol 445448b
Update src/plugins/skip-live-songs/patterns.ts
amontariol 36c3d09
Update src/plugins/skip-live-songs/patterns.ts
amontariol 2f02ace
Apply suggestions from code review
amontariol 5e58654
Update src/plugins/skip-live-songs/index.ts
amontariol d6c4f78
Update src/plugins/skip-live-songs/index.ts
amontariol e6a9339
Update src/plugins/skip-live-songs/index.ts
amontariol 2c3bf5e
Update src/plugins/skip-live-songs/index.ts
amontariol 142109a
Update src/plugins/skip-live-songs/index.ts
amontariol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,88 @@ | ||
| import { t } from '@/i18n'; | ||
| import { createPlugin } from '@/utils'; | ||
|
|
||
| import type { SongInfo } from '@/providers/song-info'; | ||
| import { nonStudioPatterns } from './patterns'; | ||
amontariol marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export default createPlugin({ | ||
| name: () => t('plugins.skip-live-songs.name'), | ||
| description: () => t('plugins.skip-live-songs.description'), | ||
| restartNeeded: false, | ||
| config: { | ||
| enabled: false, | ||
| }, | ||
| renderer: { | ||
| lastSkippedVideoId: '', | ||
|
|
||
| _skipLiveHandler: undefined as unknown as | ||
| | ((songInfo: SongInfo) => void) | ||
| | undefined, | ||
|
|
||
| start({ ipc }) { | ||
| console.debug('[Skip Live Songs] Renderer started'); | ||
|
|
||
| const SELECTORS = [ | ||
| 'yt-icon-button.next-button', | ||
| '.next-button', | ||
| 'button[aria-label*="Next"]', | ||
| 'button[aria-label*="next"]', | ||
| '#player-bar-next-button', | ||
| 'ytmusic-player-bar .next-button', | ||
| '.player-bar .next-button', | ||
| ]; | ||
|
|
||
| const handler = (songInfo: SongInfo) => { | ||
| const titleToCheck = songInfo.alternativeTitle || songInfo.title; | ||
| if (!titleToCheck) return; | ||
|
|
||
| // Skip if we've already attempted this video id | ||
| if (songInfo.videoId === this.lastSkippedVideoId) return; | ||
|
|
||
| const isNonStudio = nonStudioPatterns.some((pattern) => | ||
| pattern.test(titleToCheck), | ||
| ); | ||
|
|
||
| if (!isNonStudio) return; // studio version — nothing to do | ||
|
|
||
| // Mark as attempted so we don't loop repeatedly | ||
| this.lastSkippedVideoId = songInfo.videoId; | ||
| console.info( | ||
| `[Skip Live Songs] Skipping non-studio song: "${titleToCheck}" (id: ${songInfo.videoId})`, | ||
| ); | ||
|
|
||
| let clicked = false; | ||
| for (const sel of SELECTORS) { | ||
| const button = document.querySelector<HTMLElement>(sel); | ||
| if (button) { | ||
| button.click(); | ||
| console.debug( | ||
| `[Skip Live Songs] Clicked next button using selector: ${sel}`, | ||
| ); | ||
| clicked = true; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (!clicked) { | ||
| console.warn( | ||
| '[Skip Live Songs] Could not find next button with any configured selector', | ||
| ); | ||
| } | ||
| }; | ||
|
|
||
| this._skipLiveHandler = handler; | ||
| ipc.on('peard:update-song-info', handler); | ||
| }, | ||
|
|
||
| // Unregister the ipc handler on plugin stop to avoid duplicate listeners on hot reload | ||
| stop({ ipc }) { | ||
| if (this._skipLiveHandler) { | ||
| ipc.removeAllListeners('peard:update-song-info'); | ||
| this._skipLiveHandler = undefined; | ||
| console.debug( | ||
| '[Skip Live Songs] Renderer stopped and listeners removed', | ||
| ); | ||
| } | ||
| }, | ||
| }, | ||
| }); | ||
amontariol marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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,34 @@ | ||
| /** | ||
| * Patterns to detect non-studio recordings | ||
| * | ||
| * Add or modify patterns here to customize what gets skipped. | ||
| * All patterns are not case-sensitive. | ||
| */ | ||
|
|
||
| export const nonStudioPatterns = [ | ||
| // "Live" in specific contexts (not as part of song title) | ||
| /[\(\[]live[\)\]]/i, // "(Live)" or "[Live]" in parentheses/brackets | ||
amontariol marked this conversation as resolved.
Show resolved
Hide resolved
amontariol marked this conversation as resolved.
Show resolved
Hide resolved
amontariol marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /live\s+(at|from|in|on|with|@)/i, // "Live at", "Live from", "Live in", etc. | ||
| /live\s+with\b/i, // "Live with" (e.g. "Live with the SFSO") | ||
| /-\s*live\s*$/i, // "- Live" at the end of title | ||
| /:\s*live\s*$/i, // ": Live" at the end of title | ||
| // Concert/Performance indicators | ||
| /\b(concert|festival|tour)\b/i, // Concert, Festival, Tour | ||
| /\(.*?(concert|live performance|live recording).*?(19|20)\d{2}\)/i, // (Live 1985), (Concert 2024) | ||
| // Recording types | ||
| /\b(acoustic|unplugged|rehearsal|demo)\b/i, // Acoustic, Unplugged, Rehearsal, Demo | ||
| // Venues | ||
| /\b(arena|stadium|center|centre|hall)\b/i, // Arena, Stadium, Center, Hall | ||
| /\bmadison\s+square\s+garden\b/i, // Madison Square Garden | ||
| /day\s+on\s+the\s+green/i, // Day on the Green | ||
| // Famous venues/festivals | ||
| /\b(wembley|glastonbury|woodstock|coachella)\b/i, // Wembley, Glastonbury, Woodstock, Coachella | ||
| // Dates and locations | ||
| /\b(january|february|march|april|may|june|july|august|september|october|november|december)\s+\d+/i, // "September 22", "August 31" | ||
| /\b\d{1,2}[/-]\d{1,2}[/-]\d{2,4}\b/, // Date formats: 09/22/2024, 9-22-24 | ||
| /\b[A-Z][a-z]+,\s*[A-Z]{2}\b/, // Locations: "Oakland, CA", "London, UK" | ||
| /\b[A-Z][a-z]+\s+City\b/i, // Cities: "Mexico City", "New York City" | ||
| /\b(tokyo|paris|berlin|sydney)\b/i, // More cities | ||
| /\b(bbc|radio|session)\b/i, // Radio sessions | ||
| ]; | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.