Skip to content

Lastgenre plugin whitelist - #10

Merged
sampsyo merged 2 commits into
beetbox:masterfrom
Kraymer:lastgenre-whitelist
Oct 7, 2011
Merged

Lastgenre plugin whitelist#10
sampsyo merged 2 commits into
beetbox:masterfrom
Kraymer:lastgenre-whitelist

Conversation

@Kraymer

@Kraymer Kraymer commented Sep 24, 2011

Copy link
Copy Markdown
Contributor

After reading http://beets.readthedocs.org/en/latest/plugins/lastgenre.html I decided to try to implement the genres whitelist.
I opted for a list entered by user in the config file. Because genre name can contain spaces, genres must be separated by comma. That's not homogeneous with the plugins names option of the [beets] section where separator is space, do you see a better solution ?

[lastgenre]
genres_whitelist: blues,acid jazz,afro-beat,afro-cuban jazz

@sampsyo

sampsyo commented Sep 25, 2011

Copy link
Copy Markdown
Member

Cool! Thanks for taking care of this. I think the comma thing is fine; that's the right way to do it when tags can have spaces.

What do you think about a default whitelist? I'm not sure where to source the data from, but I would guess that a sufficiently large default set would cover most people's needs.

@Kraymer

Kraymer commented Sep 25, 2011

Copy link
Copy Markdown
Contributor Author

Yes a default whitelist would be better to avoid to have genres like "best music 2011" to be retrieved from lastfm.
I see 2 slightly different ways to do it :

  • whitelist pre-filled in the config file, but an exhaustive list can be quite long
  • whitelist of known genres hardcoded in the plugin code + whitelist in config file (default:empty) acting as a filter to keep only genres explicitely allowed by user

One possible source: http://en.wikipedia.org/wiki/List_of_popular_music_genres

@sampsyo

sampsyo commented Sep 25, 2011

Copy link
Copy Markdown
Member

Wow, that Wikipedia page is surprisingly complete! Maybe I'll look into writing a little script that will scrape the complete list of genres...

I think maybe having a hard-coded (but overridable) default list would be best. If the user specifies a white list, then it replaces the default one. (Perhaps there could also be an option to just add to or subtract from the default list rather than replace it.)

@sampsyo

sampsyo commented Sep 25, 2011

Copy link
Copy Markdown
Member

So I wrote a quick scraper for these genre lists:
https://gist.github.com/1241307
That has the scraper script as well as its sample output (1500 genres!). I'm thinking of including this as a package resource (in a text file) that can then be read and tossed into a set at plugin load time.

@Kraymer

Kraymer commented Sep 26, 2011

Copy link
Copy Markdown
Contributor Author

Nice list! so with the possibility to replace the whitelist and add genres to the list that gives a good flexibility :

# Override default whitelist contained in genres.txt
genres_whitelist = 
# Add genres to whitelist
add_genres = 

or just specify the genres file in the config ?

genres_whitelist = beetsplug/lastgenre/whitelist.txt

or add += and -= operators to the config parser ?

genres_whitelist += pop,funk

Another related issue is "genre matching". For example, for my library I use a set of 30 genres, that I would define as my genres_whitelist.
It would be nice if beets could "convert" lastfm-fetched genres into my accepted genres when possible.
eg "alternative pop" => "pop" is the kind of conversion i'm thinking of
it would require the scraped genres to be written following a tree structure in YAML format for example:

blues
electronic
  dance
    house
    goa transe
    chillout
pop

So, say the plugin fetch the tag "chillout" that is not in my whitelist, it parses the tree for bottom to top chillout->dance->electronic until it reads a tag that is allowed. What do you think?

@sampsyo
sampsyo merged commit 0805e50 into beetbox:master Oct 7, 2011
@sampsyo

sampsyo commented Oct 7, 2011

Copy link
Copy Markdown
Member

Merged your patches along with a new change that makes the config parameter point to a text file (rather than inlining the whitelist). The default whitelist is included with beets. Thanks for the contribution!

Let me know if you make progress on the "canonicalization" idea. Seems interesting.

@snejus snejus added the lastgenre lastgenre plugin label Apr 5, 2026
snejus added a commit that referenced this pull request May 17, 2026
Fixes #6601 

Added `import contextvars` and changed `_extend_pipeline` to capture the
current context and run the inner pipeline within it to ensure the
`music_dir` context variable is available when the inner pipeline
resolves paths, preventing the relative-path bug that caused could not
get filesize errors and removing 0 old duplicated items during merge.

Works perfectly after the fix:

```bash
arsaboo@arsmusic:~$ beet import -m -I -t ~/shared/music/ --set genre="Filmi" --search-id 7MwKD3kEFMov4LQqyhnmzL

/home/arsaboo/shared/music (1 items)

  Match (75.2%):
  King - Lukkhe
  ≠ artist, tracks
  Spotify, None, 2026, None, Warner Music India, None, None
  https://open.spotify.com/album/7MwKD3kEFMov4LQqyhnmzL
  ≠ Artist: King; OAFF; Savera; Sunny M.R. -> King
  * Album: Lukkhe
     ≠ (#2) Khamoshiyaan (3:03) -> (#2) Khamoshiyaan (feat. Romy & Manreet Khara) (3:03)
Missing tracks (13/14 - 92.9%):
 ! Bulletproof (#1) (3:09)
 ! Jee Lenge (#3) (3:25)
 ! Headshot (#4) (3:10)
 ! Ruh Teri (feat. Manreet Khara & Agrim Joshi) (#5) (2:31)
 ! Roobaroo (#6) (3:17)
 ! Savere (#7) (2:29)
 ! Haal (#8) (3:29)
 ! Haal (The Journey) (#9) (6:13)
 ! Nachdi Shaam (#10) (2:22)
 ! Hoga Bada Mera Naam (#11) (1:58)
 ! All Eyes On Us (#12) (3:13)
 ! Swan Song (Hoya Azaad) (#13) (3:17)
 ! Bhaari Pangey (#14) (2:19)
➜ [A]pply, More candidates, Skip, Use as-is, as Tracks, Group albums,
Enter search, enter Id, aBort, eDit, edit Candidates, Print tracks,
Open files with Picard? a
This album is already in the library!
Old: 3 items, MP3, 320kbps, 9:45, 22.9 MiB
New: 1 items, MP3, 320kbps, 3:03, 7.8 MiB
➜ [S]kip new, Keep all, Remove old, Merge all? m

/home/arsaboo/shared/music
/data/music/Hindi Music/L/Lukkhe [30718] (2026)/Lukkhe (2026) - Bulletproof.mp3
/data/music/Hindi Music/L/Lukkhe [30718] (2026)/Lukkhe (2026) - Headshot.mp3
/data/music/Hindi Music/L/Lukkhe [30718] (2026)/Lukkhe (2026) - Jee Lenge.mp3 (4 items)

  Match (82.6%):
  King - Lukkhe
  ≠ artist, tracks
  Spotify, None, 2026, None, Warner Music India, None, None
  https://open.spotify.com/album/7MwKD3kEFMov4LQqyhnmzL
  ≠ Artist: OAFF; Savera; Ruaa Kayy; Romy; Manreet Khara -> King
  * Album: Lukkhe
     * (#1) Bulletproof (3:09)
     ≠ (#2) Khamoshiyaan (3:03) -> (#2) Khamoshiyaan (feat. Romy & Manreet Khara) (3:03)
     * (#3) Jee Lenge (3:25)
     * (#4) Headshot (3:10)
Missing tracks (10/14 - 71.4%):
 ! Ruh Teri (feat. Manreet Khara & Agrim Joshi) (#5) (2:31)
 ! Roobaroo (#6) (3:17)
 ! Savere (#7) (2:29)
 ! Haal (#8) (3:29)
 ! Haal (The Journey) (#9) (6:13)
 ! Nachdi Shaam (#10) (2:22)
 ! Hoga Bada Mera Naam (#11) (1:58)
 ! All Eyes On Us (#12) (3:13)
 ! Swan Song (Hoya Azaad) (#13) (3:17)
 ! Bhaari Pangey (#14) (2:19)
➜ [A]pply, More candidates, Skip, Use as-is, as Tracks, Group albums,
Enter search, enter Id, aBort, eDit, edit Candidates, Print tracks,
Open files with Picard? a
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lastgenre lastgenre plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants