Last FM plays import script
#16
Thank you Karellen, I followed your words and could import the CVS and saved the database.

Now, I have trouble with step 5 on my Mac with python --version Python 2.7.10
(I'm using Kodi 18.3 on libreelec. python --version Python 2.7.15 throws the same error.)

python:
python last_fm_import.py
Traceback (most recent call last):
  File "last_fm_import.py", line 118, in <module>
    main()
  File "last_fm_import.py", line 94, in main
    cur.execute("SELECT DISTINCT Artist, Title FROM plays")
sqlite3.OperationalError: no such table: plays

My Kodi database is named MyMusic72.db.

2 zero byte files are created as well.
Image

This is what I have done:
Image
Image

Step 2 tells something about Artist,Album,Title,DatePlayed

Should I change it to Artist,Album,Title,plays and create the database again?

EDIT: no, that did not work either.
Reply
#17
(2019-07-29, 11:11)xbozzo Wrote: Should I change it to Artist,Album,Title,plays and create the database again?

EDIT: no, that did not work either.
The name of the field "DatePlayed" is not the problem. The clue is in the error message:
"sqlite3.OperationalError: no such table: plays"
 
The script is complaining that there is no table called "plays".

Sorry I have not read pack the rest of this thread to understand more details, and I just don't have the spare time.
Reply
#18
(2019-07-29, 13:53)DaveBlake Wrote: The script is complaining that there is no table called "plays".

I was under the impression, that a table "plays" was created, as shown in the above screenshot:
Image

Maybe the script complains about a missing table plays in the kodi database MyMusic72.db ?

Anyone?
Reply
#19
Just a thought, but I know from some of my clients how easy it can be at times to overlook something.  @xbozzo , you have clicked "Write changes" to actually write the new db back to disk ?
Learning Linux the hard way !!
Reply
#20
(2019-07-29, 14:06)black_eagle Wrote: Just a thought, but I know from some of my clients how easy it can be at times to overlook something.  @xbozzo , you have clicked "Write changes" to actually write the new db back to disk ?
Valid point :-) but the screenshot is made from the re-opened database lastfm.db on my harddrive.

(in addition, DB Browser asks for saving, when you try to close an edited/unsaved database. Also, the keyboard-shortcut CMD+S for save is working too) ;-)

When I browse the db, there is a table called plays
Image
Reply
#21
Ok, analyzing the script, I found the culprit:

python:
    # create a database connection
    database = "databases\lastfm.db"
    conn = create_connection(database)

    # create a database2 connection
    database2 = "databases\MyMusic72.db"
    conn2 = create_connection(database2)

The script tries to open/write (or whatever) the databases from a subdirectory databases\ which is non-existant.

Moreover, the \ backslash is not working as a folder separator here on Mac, (nor on LibreElec/OpenElec/*nix). Its just part of the filename, as you can see in the above screenshot.


I had posted the screenshot before, but did not realize it could be a problem, because on Mac a filename can look this way w/o causing a problem:
Image

So, I changed the script slightly (just removed the databases\ part)
python:
   # create a database connection
    database = "lastfm.db"
    conn = create_connection(database)

    # create a database2 connection
    database2 = "MyMusic72.db"
    conn2 = create_connection(database2)

...and voilá,  it worked :-)

Thank you all for helping me nailing it down to a point, where I can fix it :-))
Reply
#22
Awesome, great to hear it worked. Thanks all for the help...

Hopefully one day someone more skilled in python will write a Kodi Add-on which does all this automatically Smile The last.fm API works pretty good so it should be easy to bypass the export to csv bit.

I still use this script all the time with my Kodi installs and it makes Music come alive when you have the plays for the last 10 years backed up online and distributed around my Kodi clients.
Reply
#23
(2019-07-29, 22:58)docwra Wrote: The last.fm API works pretty good
No, it does not ;-)

I tried those Browsers: Internet Explorer (Win), Google Chrome (Mac/Win), Safari (Mac), Waterfox (Win/Mac) and Vivaldi (Win) and none of them could load the whole 222,002 Scrobbles of my last.fm user.

The progress always stopped at 420/1111, so I guess, there is a strange character or some limitation, or just too less RAM involved.

I checked all the exported/saved data and they all had slighlty different content (mostly some doublettes were not exported/skipped sometimes and sometimes not).

I tried an alternate api key and request delays from 0 to 500ms,
but hey, at least the great Webservice at https://benjaminbenben.com/lastfm-to-csv/ allows to save partial states of the exported data, so I now have about 80.400 scrobbles imported in Kodi. ;-]

This is not a problem we need to discuss here, but its a pitty that things always have to be that complicated ;-/
Reply
#24
@docwra Thanks so much for this Smile  Took me 4 or 5 attempts but finally imported ~38k playcounts into kodi!

FYI: it got stuck on a Tori Amos song called Dātura from an album called To Venus and Back.  I don't think the script liked the ā - think it said it was not a UTF-8 character or something.
Reply
#25
Cool glad it helped Smile

Obviously this could be made into an Add-on by someone with better knowledge than me, but for a one off it works great in importing Last.Fm history!
Reply
#26
(2019-07-29, 11:11)xbozzo Wrote: Thank you Karellen, I followed your words and could import the CVS and saved the database.

Now, I have trouble with step 5 on my Mac with python --version Python 2.7.10
(I'm using Kodi 18.3 on libreelec. python --version Python 2.7.15 throws the same error.)

python:
python last_fm_import.py
Traceback (most recent call last):
  File "last_fm_import.py", line 118, in <module>
    main()
  File "last_fm_import.py", line 94, in main
    cur.execute("SELECT DISTINCT Artist, Title FROM plays")
sqlite3.OperationalError: no such table: plays

My Kodi database is named MyMusic72.db.

2 zero byte files are created as well.
Image

This is what I have done:
ImageImageStep 2 tells something about Artist,Album,Title,DatePlayed

Should I change it to Artist,Album,Title,plays and create the database again?

EDIT: no, that did not work either.

Hi
A newby here. I get exactly the same message and followed the same steps and removed the reference to '\databases' moved the script into the 'databases folder and have been trying to run the script from there but get exactly the same error as before. Desperate to get this to work.
Any ideas, please?
Johnny
Reply
#27
I think the table name has to be 'lastfm'

I was a complete novice when I tried this & it took me a few attempts to get it right.  I think the database is called lastfm and the table inside the database is also called lastfm, not plays.  I could be completely wrong though!
Reply
#28
(2019-11-26, 20:39)dubwat Wrote: I think the table name has to be 'lastfm'

I was a complete novice when I tried this & it took me a few attempts to get it right.  I think the database is called lastfm and the table inside the database is also called lastfm, not plays.  I could be completely wrong though!

Pretty sure from looking at the code and this quote
(2018-10-10, 22:08)docwra Wrote: Basically the table needed to be called "plays"

that the table needs to be called plays

@docwra is that last.fm api returning json ? I have a whole python class for returning and updating music info through Kodi's json api. I don't have a user account on last.fm but if you can post a few examples of what their api returns I can feed that into my local_library_utils class and hopefully update the play count that way. If it works OK, should be quite easy to roll an addon that does it all for you. No promises mind, time is always limited, but I have already written half of the stuff to do this anyway. I do need to know what their api returns though as I imagine you have access to different data if you have an account on there.

I have an api key that I use to grab the data that BBC Radio 2 scrobble so my radio helper can get art etc when I'm listening to that but that's public info.
Learning Linux the hard way !!
Reply
#29
(2019-11-26, 21:38)black_eagle Wrote:
(2019-11-26, 20:39)dubwat Wrote: I think the table name has to be 'lastfm'

I was a complete novice when I tried this & it took me a few attempts to get it right.  I think the database is called lastfm and the table inside the database is also called lastfm, not plays.  I could be completely wrong though!

Pretty sure from looking at the code and this quote
(2018-10-10, 22:08)docwra Wrote: Basically the table needed to be called "plays"

that the table needs to be called plays

@docwra is that last.fm api returning json ? I have a whole python class for returning and updating music info through Kodi's json api. I don't have a user account on last.fm but if you can post a few examples of what their api returns I can feed that into my local_library_utils class and hopefully update the play count that way. If it works OK, should be quite easy to roll an addon that does it all for you. No promises mind, time is always limited, but I have already written half of the stuff to do this anyway. I do need to know what their api returns though as I imagine you have access to different data if you have an account on there.

I have an api key that I use to grab the data that BBC Radio 2 scrobble so my radio helper can get art etc when I'm listening to that but that's public info.
This sound great, would really appreciate a addon like this.
I have no idea about the api stuff and no clou where to look for the info you ne but
I can share my account if you wannt, so you can take a look at what ever you need, just drop me a pm.
Reply
#30
(2019-07-29, 14:33)xbozzo Wrote: Ok, analyzing the script, I found the culprit:

python:
    # create a database connection
    database = "databases\lastfm.db"
    conn = create_connection(database)

    # create a database2 connection
    database2 = "databases\MyMusic72.db"
    conn2 = create_connection(database2)

The script tries to open/write (or whatever) the databases from a subdirectory databases\ which is non-existant.

Moreover, the \ backslash is not working as a folder separator here on Mac, (nor on LibreElec/OpenElec/*nix). Its just part of the filename, as you can see in the above screenshot.


I had posted the screenshot before, but did not realize it could be a problem, because on Mac a filename can look this way w/o causing a problem:
Image

So, I changed the script slightly (just removed the databases\ part)
python:
   # create a database connection
    database = "lastfm.db"
    conn = create_connection(database)

    # create a database2 connection
    database2 = "MyMusic72.db"
    conn2 = create_connection(database2)

...and voilá,  it worked :-)

Thank you all for helping me nailing it down to a point, where I can fix it :-))

Was having the same issue in Linux but this seems to have been sorted it.

Put both database in the same folder as the script. 
Edited the lines as you did
It ran through and completed fine..


But, on checking the data (was doing this on a test db from an old backup), somethings amiss... two of the top 6 tracks are totally wrong and #7 is missing..

Image

And the real #1 track has 0 plays associated with it

edit: Solved the random two tracks with hundreds to many players, but not solved why its not important all tracks. Quite a lot of tracks its not importing the data for.
Reply

Logout Mark Read Team Forum Stats Members Help
Last FM plays import script1