# Genre python program

**URL:** <https://discourse.beets.io/t/genre-python-program/2318>\
**Category:** Help\
**Created:** [April 5, 2023, 9:34pm UTC](https://discourse.beets.io/t/genre-python-program/2318 "2023-04-05T21:34:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![A-D](https://avatars.discourse-cdn.com/v4/letter/a/50afbb/32.png) [@A-D](https://discourse.beets.io/u/A-D)\
**Post date:** [April 5, 2023, 9:34pm UTC](https://discourse.beets.io/t/genre-python-program/2318/1 "2023-04-05T21:34:41Z")

</div>

Hi  
I wanna make a program that takes song names and artists from an excel sheet and adds genres (1 - 3) to the same row according to the song.  
For this i’d like to use the LastGenre plugin, but i am a noob tbh and don’t understand the woring of it/ how to implement or even use it.

Im writing it all in python btw

thanks 🙂

---

<div class="post-metadata">

**Author:** ![RollingStar](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/rollingstar/32/728_2.png) [@RollingStar](https://discourse.beets.io/u/RollingStar)\
**Post date:** [April 7, 2023, 5:31pm UTC](https://discourse.beets.io/t/genre-python-program/2318/2 "2023-04-07T17:31:15Z")

</div>

Can you explain a bit more? You might not need beets itself for this.

Can you make a mockup in Excel of 3 lines of what the results would look like? And paste that here as a screenshot?

Honestly, it sounds like a big project for a novice user. I’ll explain what you can do, but it might sound like gibberish. We have a doc for it but I find it confusing: [Writing Plugins — beets 1.6.0 documentation](https://beets.readthedocs.io/en/stable/dev/plugins.html)

You might be able to just copy the lastgenre folder into your own folder, and build python code around it.

> **[beets/beetsplug/lastgenre at 018396ccf74a35e56ab346ad390476a0e347307a ·...](https://github.com/beetbox/beets/tree/018396ccf74a35e56ab346ad390476a0e347307a/beetsplug/lastgenre)**
>
> 018396ccf74a35e56ab346ad390476a0e347307a/beetsplug/lastgenre

Or, you could use lastgenre to look up every track in your beets database. once you’ve done that, you could export a CSV (excel compatible) with every track in your db and their top 3 genres. you could do this by copying your beets.db database to a fresh file, and opening it with DB Browser (SQLite).

you can even use beets queries to subset the list, or SQL; whichever is easier for you.

if you wanted a list of every song except the beatles it would be something like this in SQL:

select \* from table  
where lower(albumartist) not like “%beatles%”

or if you just want techno, something like this (not sure how the syntax is exactly)

select \* from table  
where “techo” in genres

Good luck!

---

<div class="post-metadata">

**Author:** ![A-D](https://avatars.discourse-cdn.com/v4/letter/a/50afbb/32.png) [@A-D](https://discourse.beets.io/u/A-D)\
**Post date:** [April 12, 2023, 9:08pm UTC](https://discourse.beets.io/t/genre-python-program/2318/3 "2023-04-12T21:08:56Z")

</div>

Hi,  
First of, my apologies for the late reply.  
Secondly, a bit more explanation:  
the program should look up the song name and artist (column A and B) and paste the 3 most popular genre or tags in column D, E & F (see picture)

How it does that doesn’t matter, but it should be the genre linked to the song. By that i mean: f.e. last.fm has genres linked to songs, spotify has genres linked to the artist.

 ![image](https://canada1.discourse-cdn.com/flex029/uploads/beets/original/1X/238e62b988b51a843e1f0178ef518ac64d0ea690.png)

A csv is okay, i know how to import that into excel.

Thanks for your help 🙂

---

<div class="post-metadata">

**Author:** ![RollingStar](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/rollingstar/32/728_2.png) [@RollingStar](https://discourse.beets.io/u/RollingStar)\
**Post date:** [April 16, 2023, 6:32pm UTC](https://discourse.beets.io/t/genre-python-program/2318/4 "2023-04-16T18:32:19Z")

</div>

Yep, here’s what I would do:

1. See if there’s any other APIs in Python for the Last.fm genres. They will be simpler than editing a beets plugin to work outside of it. You could also try musicbrainz which should have genre tags and has a robust and well documented API.

2. If there are none, do what I said:

> You might not need beets itself for this. …

> Honestly, it sounds like a big project for a novice user. I’ll explain what you can do, but it might sound like gibberish. We have a doc for it but I find it confusing: [Writing Plugins — beets 1.6.0 documentation](https://beets.readthedocs.io/en/stable/dev/plugins.html)

> You might be able to just copy the lastgenre folder into your own folder, and build python code around it.

> <https://github.com/beetbox/beets/tree/018396ccf74a35e56ab346ad390476a0e347307a/beetsplug/lastgenre>
>
> //github.com/beetbox/beets/tree/018396ccf74a35e56ab346ad390476a0e347307a/beetsplug/lastgenre

---

<div class="post-metadata">

**Author:** ![A-D](https://avatars.discourse-cdn.com/v4/letter/a/50afbb/32.png) [@A-D](https://discourse.beets.io/u/A-D)\
**Post date:** [April 17, 2023, 10:56am UTC](https://discourse.beets.io/t/genre-python-program/2318/5 "2023-04-17T10:56:30Z")

</div>

Thank you very much!
