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

Get genre from Google Music #1569

Closed
oblomovx opened this issue Aug 15, 2015 · 8 comments
Closed

Get genre from Google Music #1569

oblomovx opened this issue Aug 15, 2015 · 8 comments
Labels
feature features we would like to implement newplugin

Comments

@oblomovx
Copy link

I like how the Google Play music store has set up it's genres: A few big main genres.
Is it possible to scrape the genre from there?

@Kraymer
Copy link
Contributor

Kraymer commented Aug 15, 2015

Google Play is not a possible source for lastgenre plugin.
Yet, you can achieve a probably similar result by using the canonicalization with the google play genres listed as "seeds" in the yaml file.

@oblomovx
Copy link
Author

Yes, I did fiddle with the canonicalization. It works alright, but the genre tagging is not very acccurate:

lastgenre: genre for album New Kids on the Block - Face the Music (album): Pop
lastgenre: genre for album New Kids on the Block - Hangin' Tough (album): Pop
lastgenre: genre for album New Kids on the Block - Step by Step (album): Alternative Rock
lastgenre: genre for album New Kids on the Block - Tour Souvenir Collection (artist): Pop

But I guess that is to blame on the Last.fm users.

@sampsyo sampsyo added feature features we would like to implement newplugin labels Aug 16, 2015
@sampsyo sampsyo changed the title Get Genre from Google Music Get genre from Google Music Aug 16, 2015
@sampsyo
Copy link
Member

sampsyo commented Aug 16, 2015

Interesting idea. Do you know anything about how we might go about that—an API, etc.?

Also, FWIW, you might get more consistent results out of lastgenre by using artist mode instead of album mode.

@oblomovx
Copy link
Author

There is no official API, only on unofficial one at https://github.com/simon-weber/gmusicapi (seems quite well maintained)

Don't know if it is feasible to scrape google music itself?

@oblomovx
Copy link
Author

I have no experience with Python, only php. I created a very simple form that takes an artist and album as input en returns the genres listed for that album. Would be great if anyone could make it into a beets plugin!

<?php

$baseUrl = "https://play.google.com";
$albumSearch = "/store/search?c=music&docType=2&hl=en&q=";

echo "<form method='POST' action='./'>";
echo "<p><input type='text' name='artist'/></p>";
echo "<p><input type='text' name='album'/></p>";
echo "<p><input type='submit' /></p>";
echo "</form>";

if(!isset($_POST['album'])){
    exit;
}

$artist = urlencode($_POST['artist']);
$album = urlencode($_POST['album']);

$url = $baseUrl.$albumSearch.$artist."+".$album;

$result = file_get_contents($url);

$dom = new DOMDocument();
@$dom->loadHTML($result);

$xpath = new DOMXpath($dom);
$albums = $xpath->query('//div[@class="search-page"]//a[@class="card-click-target"]');

$albumUrl = "https://play.google.com".$albums->item(0)->getAttribute('href')."&hl=en";

$result = file_get_contents($albumUrl);

@$dom->loadHTML($result);

$xpath = new DOMXpath($dom);
$genres = $xpath->query('//div[@class="meta-info"][1]//a');

echo "<p>".$_POST['artist']." - ".$_POST['album']."</p>";
foreach($genres as $genre){
    echo $genre->nodeValue."<br/>";
}

@LordSputnik
Copy link
Contributor

The problem with this, and any form of HTML scraping, is that if Google changes the page layout slightly or the way they represent genre information, the code will break.

Which is why an API is helpful - the developers usually guarantee it to be stable, or at least warn people in advance if it's likely to change.

@jake-g
Copy link

jake-g commented Sep 8, 2015

the unofficial gmusic api is great. I use it to sync and create playlists. Not sure if you can pull genre from any query as a free user. The question is where does google get the genre? and can we scrape that...I've been using lastfm genres, but it has alot of possibilities...sometimes too many (i know there are whitelists and stuff). I was thinking of moving the lastfm tags to comments or some other tag and use a more conservative subset for genre field. like google or wikipedia or discogs maybe?

@wisp3rwind
Copy link
Member

Closing, since there's no more Google Play Music: #4089

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature features we would like to implement newplugin
Projects
None yet
Development

No branches or pull requests

6 participants