Browse Source

0.1.1

pull/1/head
Alexander Popov 6 years ago
parent
commit
9685d8aa8a
  1. 1
      .gitignore
  2. 0
      LICENSE.txt
  3. 18
      README.md
  4. 28
      lastfm_import.py
  5. 15
      samples/getTracks.py
  6. 2
      setup.cfg
  7. 26
      setup.py

1
.gitignore vendored

@ -1 +1,2 @@
*.json
*.pyc

0
LICENSE → LICENSE.txt

18
README.md

@ -1,9 +1,19 @@
**How to use**
![Version](https://img.shields.io/pypi/v/lastfm_import.svg?style=flat-square)
![License](https://img.shields.io/pypi/l/lastfm_import.svg.svg?style=flat-square)
![PyVersion](https://img.shields.io/pypi/pyversions/lastfm_import.svg.svg?style=flat-square)
**How to use as standartalone app**
1. Rename `config.json.example` to `config.json` and edit.
2. Run this `python lastfm-import.py` or `~/lastfm-import.py`.
3. PROFIT!!
2. Run this `python lastfm_import.py` or `~/lastfm_import.py`.
3. PROFIT!!
***How to use as library**
see [getTracks.py](https://github.com/iiiypuk/lastfm-import/blob/master/samples/getTracks.py).
My `>57,5k` tracks scrobbles sized `~8.2Mb`.
**TODO**
`-` web service
`-` more output types (sqlite, csv)
`-` confirugurabled output
`-` confirugurabled output
`-` continue backup

28
lastfm-import.py → lastfm_import.py

@ -4,12 +4,9 @@ import json
import urllib.request
__author__ = 'Alexander Popov'
__version__ = (0, 1, 0,)
__version__ = '0.1.1'
__license__ = 'Unlicense'
with open('./config.json') as f:
CONFIG = json.loads(f.read())
def get_pages(username, api_key):
response = urllib.request.urlopen(
@ -20,19 +17,28 @@ def get_pages(username, api_key):
return(pages)
def get_scrobbles(username, api_key, page):
response = json.loads(
urllib.request.urlopen(
'http://ws.audioscrobbler.com/2.0/'
'?method=user.getrecenttracks&user=%s'
'&api_key=%s&page=%d&format=json' %
(username, api_key, page,))
.read().decode("utf8"))['recenttracks']['track']
return(response)
if __name__ == '__main__':
with open('./config.json') as f:
CONFIG = json.loads(f.read())
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']
response = get_scrobbles(CONFIG['username'], CONFIG['api_key'], COUNT)
for track in response:
TRACKS.append({'artist': track['artist']['#text'],

15
samples/getTracks.py

@ -0,0 +1,15 @@
#!/usr/bin/env python3
import lastfm_import as lfm
API_KEY = '0e5070361556658180f9b1518b341eda'
USERNAME = 'goodgame'
if __name__ == '__main__':
pages = lfm.get_pages(USERNAME, API_KEY)
for page in range(1, pages + 1):
tracks = lfm.get_scrobbles(USERNAME, API_KEY, page)
for track in tracks:
print('%s - %s' % (track['artist']['#text'], track['name'],))

2
setup.cfg

@ -0,0 +1,2 @@
[metadata]
description-file=README.md

26
setup.py

@ -0,0 +1,26 @@
from distutils.core import setup
import lastfm_import
setup(
name='lastfm_import',
version=lastfm_import.__version__,
description='Last.fm backup scrobbles library'
' and standartalone program.',
author=lastfm_import.__author__,
author_email='iiiypuk@fastmail.fm',
url='https://github.com/iiiypuk/lastfm-import',
py_modules=['lastfm_import'],
scripts=['lastfm_import.py'],
license=lastfm_import.__license__,
platforms='any',
keywords=['last.fm', 'lastfm', 'import'],
classifiers=['License :: Public Domain',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
],
)
Loading…
Cancel
Save