import.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/python
  2. #
  3. # Lastscrape -- recovers data from libre.fm
  4. # Copyright (C) 2009 Free Software Foundation, Inc
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. import os.path
  20. import sys
  21. sys.path.append(os.path.join(sys.path[0], '../scripts'))
  22. from datetime import datetime
  23. import getpass
  24. from gobble import get_parser, GobbleServer, GobbleTrack
  25. import time
  26. from urllib import urlencode
  27. from urllib2 import urlopen
  28. if __name__ == '__main__':
  29. usage = "%prog [-s <SERVER>] <USERNAME> <SCROBBLE DUMP>"
  30. parser = get_parser(usage=usage)
  31. opts,args = parser.parse_args()
  32. if len(args) != 2:
  33. parser.error("All arguments are required.")
  34. username,data = args
  35. server = opts.server
  36. password = getpass.getpass()
  37. gobbler = GobbleServer(server, username, password)
  38. n = 0
  39. for line in file(data):
  40. n = n + 1
  41. artist,track,timestamp = line.strip().split("\t")
  42. dt = datetime.strptime(timestamp, "%Y-%m-%dT%H:%M:%SZ")
  43. gobbler.add_track(GobbleTrack(artist, track, dt))
  44. print "%d: Adding to post %s playing %s" % (n, artist, track)
  45. gobbler.submit()