first version
This commit is contained in:
commit
00fc65ced2
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
*.json
|
24
LICENSE
Normal file
24
LICENSE
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
This is free and unencumbered software released into the public domain.
|
||||||
|
|
||||||
|
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||||
|
distribute this software, either in source code form or as a compiled
|
||||||
|
binary, for any purpose, commercial or non-commercial, and by any
|
||||||
|
means.
|
||||||
|
|
||||||
|
In jurisdictions that recognize copyright laws, the author or authors
|
||||||
|
of this software dedicate any and all copyright interest in the
|
||||||
|
software to the public domain. We make this dedication for the benefit
|
||||||
|
of the public at large and to the detriment of our heirs and
|
||||||
|
successors. We intend this dedication to be an overt act of
|
||||||
|
relinquishment in perpetuity of all present and future rights to this
|
||||||
|
software under copyright law.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||||
|
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
For more information, please refer to <http://unlicense.org>
|
9
README.md
Normal file
9
README.md
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
**How to use**
|
||||||
|
1. Rename `config.json.example` to `config.json` and edit.
|
||||||
|
2. Run this `python lastfm-import.py` or `~/lastfm-import.py`.
|
||||||
|
3. PROFIT!!
|
||||||
|
|
||||||
|
**TODO**
|
||||||
|
`-` web service
|
||||||
|
`-` more output types (sqlite, csv)
|
||||||
|
`-` confirugurabled output
|
4
config.json.example
Normal file
4
config.json.example
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"username" : "",
|
||||||
|
"api_key" : ""
|
||||||
|
}
|
48
lastfm-import.py
Normal file
48
lastfm-import.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import json
|
||||||
|
import urllib.request
|
||||||
|
|
||||||
|
__author__ = 'Alexander Popov'
|
||||||
|
__version__ = (0, 1, 0,)
|
||||||
|
__license__ = 'Unlicense'
|
||||||
|
|
||||||
|
with open('./config.json') as f:
|
||||||
|
CONFIG = json.loads(f.read())
|
||||||
|
|
||||||
|
|
||||||
|
def get_pages(username, api_key):
|
||||||
|
response = urllib.request.urlopen(
|
||||||
|
'http://ws.audioscrobbler.com/2.0/'
|
||||||
|
'?method=user.getrecenttracks&user=%s&api_key=%s&format=json' %
|
||||||
|
(username, api_key,)).read().decode("utf8")
|
||||||
|
pages = int(json.loads(response)['recenttracks']['@attr']['totalPages'])
|
||||||
|
|
||||||
|
return(pages)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
PAGES = get_pages(CONFIG['username'], CONFIG['api_key'])
|
||||||
|
COUNT = 1
|
||||||
|
TRACKS = []
|
||||||
|
while COUNT <= PAGES:
|
||||||
|
print('\r%d%%' % (COUNT * 100 / PAGES), end='')
|
||||||
|
response = json.loads(
|
||||||
|
urllib.request.urlopen(
|
||||||
|
'http://ws.audioscrobbler.com/2.0/'
|
||||||
|
'?method=user.getrecenttracks&user=%s'
|
||||||
|
'&api_key=%s&page=%d&format=json' %
|
||||||
|
(CONFIG['username'], CONFIG['api_key'], COUNT,))
|
||||||
|
.read().decode("utf8"))['recenttracks']['track']
|
||||||
|
|
||||||
|
for track in response:
|
||||||
|
TRACKS.append({'artist': track['artist']['#text'],
|
||||||
|
'name': track['name'],
|
||||||
|
'album': track['album']['#text'],
|
||||||
|
'date': track['date']['uts']})
|
||||||
|
|
||||||
|
COUNT += 1
|
||||||
|
|
||||||
|
with open('%s.json' % (CONFIG['username']), 'w+', encoding='utf-8') as f:
|
||||||
|
f.write(
|
||||||
|
json.dumps(TRACKS, indent=4, sort_keys=True, ensure_ascii=False))
|
||||||
|
print('\r%d tracks saved in %s.json!' % (len(TRACKS), CONFIG['username'],))
|
Loading…
Reference in New Issue
Block a user