libgugemusic: Google Music Streaming & Download
Posted | archive
Basic structure
Google (China) Music website frontend is very traditional:
http://www.google.cn/music/song?id=S2894c9e5fc5df536
http://www.google.cn/music/album?id=B700dfba92c77567d
http://www.google.cn/music/artist?id=A21d5906abfad070c
Streaming
Google (China) Music service includes an online player made with Flex. The Streaming of .mp3 files & .lrc lyrics files is powered by ChinaCache. Here's a sample streaming query with XML result
In the URL query, parameter sig=7df9df980d74d35d28efe461842d76f1
refers to: MD5.hash(KeyContainer.PLAYER_KEY + param1.id);
,
where KeyContainer.PLAYER_KEYM
is defined at com.google.music.projectm.player.generated.KeyContainer.as
as follows:
package com.google.music.projectm.player.generated
{
public class KeyContainer extends Object
{
static public const PLAYER_KEY:String = "eca5badc586962b6521ffa54d9d731b0";
public function KeyContainer()
{
return;
}
}
}
So the pseudo algorism for sig
is:
md5("eca5badc586962b6521ffa54d9d731b0" + "S40dbcfe0c610fa09") = "7df9df980d74d35d28efe461842d76f1"
Download
Download is pretty easy, just try this link:
http://www.google.cn/music/top100/musicdownload?id=Sc623893aee83dfb4
and parse the <a>
element:
<a href="/music/top100/url?q=http%3A%2F%2Ffile1.top100.cn%2F200905031622%2FFA4C7C8006CDB6F605DE00A4714A421A%2FSpecial_28506%2FWTF.mp3&ct=rdl&cad=dl&ei=V1T9SdDnNpuYsAKE8ua6AQ&sig=9EC3F52AC3B1F3857871AAF885AD2A2D"><img src="http://www.gstatic.cn/top100/images/download_icon.png" alt="" style="border: none;"></a>
libgugemusic
libgugemusic.py is a simple library for interacting with Google (China) Music service written in pure Python
Example:
>>> import libgugemusic
>>> libgugemusic.download_mp3_by_id('S40dbcfe0c610fa09')
'http://file3.top100.cn/200905031859/42B67F4B5A23786601DB7781B75E509A/Special_12
3690/%E8%8A%B1%E8%9D%B4%E8%9D%B6.mp3'
>>> libgugemusic.stream_mp3_by_id('S40dbcfe0c610fa09')
{'songUrl': 'http://audio2.top100.cn/200905031859/6186071D9F22FB7C15048C81BE0241
7B/streaming2/Special_123690/%E8%8A%B1%E8%9D%B4%E8%9D%B6.mp3', 'lyricsUrl': 'htt
p://lyric.top100.cn/Special_123690/M0123690001.lrc', 'label': '\xe5\x8d\x8e\xe7\
xba\xb3\xe5\x94\xb1\xe7\x89\x87\xe5\x85\xac\xe5\x8f\xb8(Warner Music)', 'provide
rId': 'M0123690001', 'albumThumbnailLink': 'http://www.gstatic.cn/base_media?q=h
ttp://pic.top100.cn/SpecialImg/middle_special_123690.jpg&size=2&hl=cn&am
p;fact=194&dhm=8bddb8f1'}
You can get libgugemusic.py on my Google Code SVN repository
I'll expand this library with music location function, and finally integrate Google (China) Music service with Last.FM radio.getPlaylist
as an alternative to Last.FM, Pandora & Spotify.
Comments