logo Netzschleuder network catalog, repository, and centrifuge

History of lastfm

The changes to the source code of this entry in the repository, newest first, each with the differences it made to the entry's files. They are also listed on GitLab.

[entries] Add the date when each entry was added, and remove icon_hash by Tiago de Paula Peixoto beff7c9
The dates are those of the commits that first added the entries' files
(2020-08-11 for the entries of the initial commit); renamed entries keep
the date of their first name.

Changed: none
diff --git a/entries/lastfm/__init__.py b/entries/lastfm/__init__.py
index 83d5cdc..f8ff439 100644
--- a/entries/lastfm/__init__.py
+++ b/entries/lastfm/__init__.py
@@ -40,7 +40,7 @@ The networks have the following properties:
 tags = ['Social', 'Online', 'Preferences', 'Bipartite', 'Unweighted', 'Multigraph', 'Timestamps', 'Metadata']
 url = ['https://www.upf.edu/web/mtg/lastfm1k', 'https://zenodo.org/records/6090214']
 citation = [('Ò. Celma, "Music Recommendation and Discovery: The Long Tail, Long Fail, and Long Play in the Digital Music Space." Springer (2010).', 'https://doi.org/10.1007/978-3-642-13287-2')]
-icon_hash = '57fe75bb8cf714f319c3ac25'
+date_added = '2020-08-11'
 upstream_license = ("Non-commercial use (distributed with permission of Last.fm)", "https://zenodo.org/records/6090214")
 # the server refuses non-browser user agents (open_url() falls back to one);
 # the same file is on Zenodo (record 6090214)
[entries] Prefix the properties in the descriptions with (Node), (Edge) or (Graph) by Tiago de Paula Peixoto bc3dbbd
The lists of properties at the end of the descriptions marked edge
properties with "Edge" but left node properties unmarked, or grouped
them in "Nodes: `a`, ...; `b`, ..." items, so the kind of a property
was often unclear. Every item now starts with (Node), (Edge) or (Graph),
followed by the property names, a colon and the explanation, one item
per property or group of properties; qualifications (kinds of nodes,
networks) follow the names in parentheses. Properties that were only
named got a short explanation, and a few items that named the wrong
kind of property were corrected.
diff --git a/entries/lastfm/__init__.py b/entries/lastfm/__init__.py
index 8d4f9cb..83d5cdc 100644
--- a/entries/lastfm/__init__.py
+++ b/entries/lastfm/__init__.py
@@ -28,15 +28,15 @@ The artists and songs are identified by their MusicBrainz identifiers (MBID), or
 
 The networks have the following properties:
 
-- `name`: the identifier of the user (e.g. `user_000639`), or the name of the artist or song.
-- `is_user`: whether the node is a user (otherwise an artist or a song).
-- `mbid`: the MusicBrainz identifier of the artist or song (empty for users and for artists and songs without one).
-- `artist`, `artist_mbid`: the name and MusicBrainz identifier of the artist of the song (network `song` only; empty for users).
-- `gender`: the gender of the user (`m`, `f`, or empty if not given; empty for artists and songs).
-- `age`: the age of the user (-1 if not given, and for artists and songs).
-- `country`: the country of the user (empty if not given, and for artists and songs).
-- `signup`: the date of registration of the user, in Unix time (-1 if not given, and for artists and songs).
-- Edge `time`: the time of the listening event, in Unix time."""
+- (Node) `name`: the identifier of the user (e.g. `user_000639`), or the name of the artist or song.
+- (Node) `is_user`: whether the node is a user (otherwise an artist or a song).
+- (Node) `mbid`: the MusicBrainz identifier of the artist or song (empty for users and for artists and songs without one).
+- (Node) `artist`, `artist_mbid`: the name and MusicBrainz identifier of the artist of the song (network `song` only; empty for users).
+- (Node) `gender`: the gender of the user (`m`, `f`, or empty if not given; empty for artists and songs).
+- (Node) `age`: the age of the user (-1 if not given, and for artists and songs).
+- (Node) `country`: the country of the user (empty if not given, and for artists and songs).
+- (Node) `signup`: the date of registration of the user, in Unix time (-1 if not given, and for artists and songs).
+- (Edge) `time`: the time of the listening event, in Unix time."""
 tags = ['Social', 'Online', 'Preferences', 'Bipartite', 'Unweighted', 'Multigraph', 'Timestamps', 'Metadata']
 url = ['https://www.upf.edu/web/mtg/lastfm1k', 'https://zenodo.org/records/6090214']
 citation = [('Ò. Celma, "Music Recommendation and Discovery: The Long Tail, Long Fail, and Long Play in the Digital Music Space." Springer (2010).', 'https://doi.org/10.1007/978-3-642-13287-2')]
[entries] Remove unneeded code from the entries by Tiago de Paula Peixoto 2c69f19
Unneeded "global files" statements, unused imports and variables,
f-strings without placeholders, duplicate keys in foodweb_little_rock
(keeping the order and the values used), and the second definition of
get_lines() in twitter_higgs. Nothing changes in the networks or
descriptions.

Changed: none
diff --git a/entries/lastfm/__init__.py b/entries/lastfm/__init__.py
index f84ff40..8d4f9cb 100644
--- a/entries/lastfm/__init__.py
+++ b/entries/lastfm/__init__.py
@@ -102,7 +102,6 @@ class _Items:
 @coerce_props()
 @annotate()
 def parse(alts=None):
-    global files
     name = __name__.split(".")[-1]
     todo = [alt for fnames, alt, fmt in files if alts is None or alt in alts]
     if not todo:
[entries] Move contact, convote_mentions, douban, email_company, epinions, flixster, football_league_results, hyves, lastfm, libimseti, livemocha, reuters, sa_companies, sister_cities, tripadvisor_ratings, wikilens_ratings and wikipedia_discussions_de to their original sources by Tiago de Paula Peixoto 8f097de
These entries downloaded KONECT's copies of the data. They now download
the original data (live, from pinned Wayback Machine snapshots, or by
re-extracting from public dumps), gaining the metadata KONECT dropped
(names, identifiers, timestamps, attributes), with descriptions and
citations rewritten from the original sources and factual errors fixed
(years and periods of contact, email_company, douban, flixster,
libimseti, sa_companies; the rated objects of epinions; the sign of
convote_mentions; songs merged by title alone in lastfm).

New networks: the trust network of epinions, the links of
wikilens_ratings, the JSON crawl of tripadvisor_ratings, and current
versions of sister_cities and wikipedia_discussions_de next to the ones
KONECT used. asu_social_networks only loses its mention of KONECT.

Changed: upstream contact convote_mentions douban email_company epinions flixster football_league_results hyves lastfm libimseti livemocha reuters sa_companies sister_cities tripadvisor_ratings wikilens_ratings wikipedia_discussions_de
diff --git a/entries/lastfm/__init__.py b/entries/lastfm/__init__.py
index ccd9501..f84ff40 100644
--- a/entries/lastfm/__init__.py
+++ b/entries/lastfm/__init__.py
@@ -16,35 +16,162 @@
 # You should have received a copy of the GNU Affero General Public License along
 # with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+import calendar
+from array import array as pyarray
+
 from .. import *
 
-title = "last.fm listening habits (2007)"
-description = """Two bipartite networks from the music website last.fm, giving the user-song and user-band interactions. Nodes are users and songs/bands, and an edge (i,j) denotes that a user i listens to the song/band j.[^icon]
-[^icon]: Description obtained from the [ICON](https://icon.colorado.edu) project."""
-tags = ['Social', 'Online', 'Unweighted']
-url = 'http://konect.cc/networks/lastfm_band'
-citation = [('Ò. Celma Herrada, "The Long Tail in Recommender Systems. In: Music Recommendation and Discovery." Springer, Berlin, Heidelberg (2010).', 'https://doi.org/10.1007/978-3-642-13287-2_4')]
+title = "Last.fm listening histories (2009)"
+description = r"""Bipartite networks of the users of the music website Last.fm and the artists and songs they listened to, from the complete listening histories (until 5 May 2009) of 992 users, collected by Òscar Celma through the Last.fm API (method user.getRecentTracks). Each edge is a listening event ("scrobble"): an edge connects a user to an artist (network `band`) or to a song (network `song`) each time the user listened to a song of the artist, or to the song, with the time of the event, so that the networks are multigraphs with 19,150,868 edges each. All users of the data set's user profiles are included.
+
+The artists and songs are identified by their MusicBrainz identifiers (MBID), or, for those without one, by their names as given: an artist without an MBID by its name, and a song without an MBID by its name together with its artist (so that the same artist or song may appear under different spellings, and several artists with the same name are merged; different songs with the same title are only merged if they are by the same artist without an MBID). An artist or song with an MBID that appears with several names is named after its first occurrence.
+
+The networks have the following properties:
+
+- `name`: the identifier of the user (e.g. `user_000639`), or the name of the artist or song.
+- `is_user`: whether the node is a user (otherwise an artist or a song).
+- `mbid`: the MusicBrainz identifier of the artist or song (empty for users and for artists and songs without one).
+- `artist`, `artist_mbid`: the name and MusicBrainz identifier of the artist of the song (network `song` only; empty for users).
+- `gender`: the gender of the user (`m`, `f`, or empty if not given; empty for artists and songs).
+- `age`: the age of the user (-1 if not given, and for artists and songs).
+- `country`: the country of the user (empty if not given, and for artists and songs).
+- `signup`: the date of registration of the user, in Unix time (-1 if not given, and for artists and songs).
+- Edge `time`: the time of the listening event, in Unix time."""
+tags = ['Social', 'Online', 'Preferences', 'Bipartite', 'Unweighted', 'Multigraph', 'Timestamps', 'Metadata']
+url = ['https://www.upf.edu/web/mtg/lastfm1k', 'https://zenodo.org/records/6090214']
+citation = [('Ò. Celma, "Music Recommendation and Discovery: The Long Tail, Long Fail, and Long Play in the Digital Music Space." Springer (2010).', 'https://doi.org/10.1007/978-3-642-13287-2')]
 icon_hash = '57fe75bb8cf714f319c3ac25'
-upstream_prefix = 'http://konect.cc/files'
-files = [('download.tsv.lastfm_band.tar.bz2', "band", 'konect'),
-         ('download.tsv.lastfm_song.tar.bz2', "song", 'konect')]
+upstream_license = ("Non-commercial use (distributed with permission of Last.fm)", "https://zenodo.org/records/6090214")
+# the server refuses non-browser user agents (open_url() falls back to one);
+# the same file is on Zenodo (record 6090214)
+upstream_prefix = 'http://mtg.upf.edu/static/datasets/last.fm'
+_d = 'lastfm-dataset-1K.tar.gz:lastfm-dataset-1K'
+_fnames = (f'{_d}/userid-timestamp-artid-artname-traid-traname.tsv',
+           f'{_d}/userid-profile.tsv')
+files = [(_fnames, "band", None),
+         (_fnames, "song", None)]
+
+# Limit on the number of listening events read, for checks (None: all)
+_check_rows = None
 
 def fetch_upstream(force=False):
     return fetch_upstream_files(__name__.split(".")[-1], upstream_prefix, files,
                                 force)
 
+# (not calendar.month_abbr, which depends on the locale)
+_MONTHS = {m: i + 1 for i, m in enumerate(["Jan", "Feb", "Mar", "Apr", "May",
+                                           "Jun", "Jul", "Aug", "Sep", "Oct",
+                                           "Nov", "Dec"])}
+
+def _time(s):
+    "Unix time of a time such as 2009-04-08T01:57:47Z."
+    return calendar.timegm((int(s[0:4]), int(s[5:7]), int(s[8:10]),
+                            int(s[11:13]), int(s[14:16]), int(s[17:19])))
+
+class _Items:
+    "The artists or songs of a network, and the listening events."
+    def __init__(self, songs):
+        self.songs = songs
+        self.index = {}
+        self.names = []
+        self.mbids = []
+        self.artists = []
+        self.artist_mbids = []
+        self.src, self.tgt = pyarray("q"), pyarray("q")
+
+    def add(self, u, ambid, aname, tmbid, tname):
+        if self.songs:
+            akey = ambid if ambid else "name:" + aname
+            key = tmbid if tmbid else ("name:", akey, tname)
+            name, mbid = tname, tmbid
+        else:
+            key = ambid if ambid else "name:" + aname
+            name, mbid = aname, ambid
+        i = self.index.get(key)
+        if i is None:
+            i = self.index[key] = len(self.names)
+            self.names.append(name)
+            self.mbids.append(mbid)
+            if self.songs:
+                self.artists.append(aname)
+                self.artist_mbids.append(ambid)
+        self.src.append(u)
+        self.tgt.append(i)
+
 @cache_network()
 @coerce_props()
 @annotate()
 def parse(alts=None):
     global files
     name = __name__.split(".")[-1]
-    for fnames, alt, fmt in files:
-        if alts is not None and alt not in alts:
-            continue
-        if isinstance(fnames, str):
-            fnames = [fnames]
-        with ExitStack() as stack:
-            fs = [stack.enter_context(open_upstream_file(name, fn, "rb")) for fn in fnames]
-            g = parse_graph(fs, fmt, directed=True)
+    todo = [alt for fnames, alt, fmt in files if alts is None or alt in alts]
+    if not todo:
+        return
+
+    # "<user>\t<gender>\t<age>\t<country>\t<signup date, e.g. Apr 27, 2005>",
+    # after a header line
+    users = {}
+    profiles = []
+    with open_upstream_file(name, _fnames[1], "r", errors="replace") as f:
+        for line in f:
+            if line.startswith("#"):
+                continue
+            user, gender, age, country, signup = line.rstrip("\n").split("\t")
+            users[user] = len(users)
+            t = -1
+            if signup:
+                m, d, y = signup.replace(",", "").split()
+                t = calendar.timegm((int(y), _MONTHS[m], int(d), 0, 0, 0))
+            profiles.append((gender, int(age) if age else -1, country, t))
+
+    # both networks are built in one pass over the listening events:
+    # "<user>\t<time>\t<artist MBID>\t<artist name>\t<track MBID>\t<track name>"
+    items = {alt: _Items(alt == "song") for alt in todo}
+    times = pyarray("q")
+    nskipped = 0
+    with open_upstream_file(name, _fnames[0], "r", errors="replace") as f:
+        for n, line in enumerate(f):
+            if _check_rows is not None and n >= _check_rows:
+                break
+            fields = line.rstrip("\n").split("\t")
+            if len(fields) < 6:
+                nskipped += 1
+                continue
+            user, t, ambid, aname, tmbid = fields[:5]
+            tname = "\t".join(fields[5:])
+            u = users.get(user)
+            if u is None:
+                u = users[user] = len(users)
+                profiles.append(("", -1, "", -1))
+            times.append(_time(t))
+            for it in items.values():
+                it.add(u, ambid, aname, tmbid, tname)
+    if nskipped > 0:
+        print(f"lastfm: {nskipped} malformed lines skipped")
+    times = numpy.frombuffer(times, dtype="int64")
+
+    nu = len(users)
+    for alt in todo:
+        it = items.pop(alt)
+        g = Graph(directed=False)
+        g.add_vertex(nu + len(it.names))
+        g.vp.name = g.new_vp("string", vals=list(users.keys()) + it.names)
+        g.vp.is_user = g.new_vp("bool")
+        g.vp.is_user.a[:nu] = True
+        g.vp.mbid = g.new_vp("string", vals=[""] * nu + it.mbids)
+        if it.songs:
+            g.vp.artist = g.new_vp("string", vals=[""] * nu + it.artists)
+            g.vp.artist_mbid = g.new_vp("string", vals=[""] * nu + it.artist_mbids)
+        g.vp.gender = g.new_vp("string", vals=[p[0] for p in profiles] + [""] * len(it.names))
+        g.vp.age = g.new_vp("int32_t", val=-1)
+        g.vp.age.a[:nu] = [p[1] for p in profiles]
+        g.vp.country = g.new_vp("string", vals=[p[2] for p in profiles] + [""] * len(it.names))
+        g.vp.signup = g.new_vp("int64_t", val=-1)
+        g.vp.signup.a[:nu] = [p[3] for p in profiles]
+        g.ep.time = g.new_ep("int64_t")
+        g.add_edge_list(numpy.column_stack([numpy.frombuffer(it.src, dtype="int64"),
+                                            numpy.frombuffer(it.tgt, dtype="int64") + nu,
+                                            times]),
+                        eprops=[g.ep.time])
+        del it
         yield alt, g
Update copyright information by Tiago de Paula Peixoto 73a4f0d
diff --git a/entries/lastfm/__init__.py b/entries/lastfm/__init__.py
index 245f8e2..ccd9501 100644
--- a/entries/lastfm/__init__.py
+++ b/entries/lastfm/__init__.py
@@ -1,7 +1,7 @@
 #! /usr/bin/env python
 # -*- coding: utf-8 -*-
 #
-# Copyright (C) 2020-2024 Tiago de Paula Peixoto <tiago@skewed.de>
+# Copyright (C) 2020-2026 Tiago de Paula Peixoto <tiago@skewed.de>
 #
 # This program is free software: you can redistribute it and/or modify it under
 # the terms of the GNU Affero General Public License as published by the Free
Update copyright information by Tiago de Paula Peixoto 3d288ea
diff --git a/entries/lastfm/__init__.py b/entries/lastfm/__init__.py
index 256d56e..245f8e2 100644
--- a/entries/lastfm/__init__.py
+++ b/entries/lastfm/__init__.py
@@ -1,7 +1,7 @@
 #! /usr/bin/env python
 # -*- coding: utf-8 -*-
 #
-# Copyright (C) 2020-2023 Tiago de Paula Peixoto <tiago@skewed.de>
+# Copyright (C) 2020-2024 Tiago de Paula Peixoto <tiago@skewed.de>
 #
 # This program is free software: you can redistribute it and/or modify it under
 # the terms of the GNU Affero General Public License as published by the Free
Update copyright information by Tiago de Paula Peixoto 8d005ae
diff --git a/entries/lastfm/__init__.py b/entries/lastfm/__init__.py
index faf9758..256d56e 100644
--- a/entries/lastfm/__init__.py
+++ b/entries/lastfm/__init__.py
@@ -1,7 +1,7 @@
 #! /usr/bin/env python
 # -*- coding: utf-8 -*-
 #
-# Copyright (C) 2021 Tiago de Paula Peixoto <tiago@skewed.de>
+# Copyright (C) 2020-2023 Tiago de Paula Peixoto <tiago@skewed.de>
 #
 # This program is free software: you can redistribute it and/or modify it under
 # the terms of the GNU Affero General Public License as published by the Free
Update copyright info by Tiago de Paula Peixoto db2efcc
diff --git a/entries/lastfm/__init__.py b/entries/lastfm/__init__.py
index 9e04f94..faf9758 100644
--- a/entries/lastfm/__init__.py
+++ b/entries/lastfm/__init__.py
@@ -1,7 +1,7 @@
 #! /usr/bin/env python
 # -*- coding: utf-8 -*-
 #
-# Copyright (C) 2020 Tiago de Paula Peixoto <tiago@skewed.de>
+# Copyright (C) 2021 Tiago de Paula Peixoto <tiago@skewed.de>
 #
 # This program is free software: you can redistribute it and/or modify it under
 # the terms of the GNU Affero General Public License as published by the Free
Un-orphan KONECT datasets by Tiago de Paula Peixoto 894eba5
KONECT has been brought back from the dead for the time being.
diff --git a/entries/lastfm/__init__.py b/entries/lastfm/__init__.py
index 986803f..9e04f94 100644
--- a/entries/lastfm/__init__.py
+++ b/entries/lastfm/__init__.py
@@ -26,7 +26,6 @@ url = 'http://konect.cc/networks/lastfm_band'
 citation = [('Ò. Celma Herrada, "The Long Tail in Recommender Systems. In: Music Recommendation and Discovery." Springer, Berlin, Heidelberg (2010).', 'https://doi.org/10.1007/978-3-642-13287-2_4')]
 icon_hash = '57fe75bb8cf714f319c3ac25'
 upstream_prefix = 'http://konect.cc/files'
-orphan = True
 files = [('download.tsv.lastfm_band.tar.bz2', "band", 'konect'),
          ('download.tsv.lastfm_song.tar.bz2', "song", 'konect')]
 
Update citations to use DOIs by Tiago de Paula Peixoto e878874
diff --git a/entries/lastfm/__init__.py b/entries/lastfm/__init__.py
index d5f53c2..986803f 100644
--- a/entries/lastfm/__init__.py
+++ b/entries/lastfm/__init__.py
@@ -23,7 +23,7 @@ description = """Two bipartite networks from the music website last.fm, giving t
 [^icon]: Description obtained from the [ICON](https://icon.colorado.edu) project."""
 tags = ['Social', 'Online', 'Unweighted']
 url = 'http://konect.cc/networks/lastfm_band'
-citation = [('Ò. Celma Herrada. "Music recommendation and discovery in the long tail.” PhD Thesis (2008).', 'http://repositori.upf.edu/handle/10230/12223')]
+citation = [('Ò. Celma Herrada, "The Long Tail in Recommender Systems. In: Music Recommendation and Discovery." Springer, Berlin, Heidelberg (2010).', 'https://doi.org/10.1007/978-3-642-13287-2_4')]
 icon_hash = '57fe75bb8cf714f319c3ac25'
 upstream_prefix = 'http://konect.cc/files'
 orphan = True
Add support for 'orphan' datasets and tag konect entries by Tiago de Paula Peixoto e330b80
diff --git a/entries/lastfm/__init__.py b/entries/lastfm/__init__.py
index bad12f0..d5f53c2 100644
--- a/entries/lastfm/__init__.py
+++ b/entries/lastfm/__init__.py
@@ -26,6 +26,7 @@ url = 'http://konect.cc/networks/lastfm_band'
 citation = [('Ò. Celma Herrada. "Music recommendation and discovery in the long tail.” PhD Thesis (2008).', 'http://repositori.upf.edu/handle/10230/12223')]
 icon_hash = '57fe75bb8cf714f319c3ac25'
 upstream_prefix = 'http://konect.cc/files'
+orphan = True
 files = [('download.tsv.lastfm_band.tar.bz2', "band", 'konect'),
          ('download.tsv.lastfm_song.tar.bz2', "song", 'konect')]
 
Change license from GPLv3 to AGPLv3 by Tiago de Paula Peixoto d754be5
diff --git a/entries/lastfm/__init__.py b/entries/lastfm/__init__.py
index 35e61b4..bad12f0 100644
--- a/entries/lastfm/__init__.py
+++ b/entries/lastfm/__init__.py
@@ -3,18 +3,18 @@
 #
 # Copyright (C) 2020 Tiago de Paula Peixoto <tiago@skewed.de>
 #
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
+# This program is free software: you can redistribute it and/or modify it under
+# the terms of the GNU Affero General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option) any
+# later version.
 #
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
+# details.
 #
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+# You should have received a copy of the GNU Affero General Public License along
+# with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 from .. import *
 
Add explicit attribution to descriptions obtained from ICON by Tiago de Paula Peixoto 1645314
diff --git a/entries/lastfm/__init__.py b/entries/lastfm/__init__.py
index a25b7c8..35e61b4 100644
--- a/entries/lastfm/__init__.py
+++ b/entries/lastfm/__init__.py
@@ -19,7 +19,8 @@
 from .. import *
 
 title = "last.fm listening habits (2007)"
-description = "Two bipartite networks from the music website last.fm, giving the user-song and user-band interactions. Nodes are users and songs/bands, and an edge (i,j) denotes that a user i listens to the song/band j."
+description = """Two bipartite networks from the music website last.fm, giving the user-song and user-band interactions. Nodes are users and songs/bands, and an edge (i,j) denotes that a user i listens to the song/band j.[^icon]
+[^icon]: Description obtained from the [ICON](https://icon.colorado.edu) project."""
 tags = ['Social', 'Online', 'Unweighted']
 url = 'http://konect.cc/networks/lastfm_band'
 citation = [('Ò. Celma Herrada. "Music recommendation and discovery in the long tail.” PhD Thesis (2008).', 'http://repositori.upf.edu/handle/10230/12223')]
Initial commit by Tiago de Paula Peixoto cc85872
diff --git a/entries/lastfm/__init__.py b/entries/lastfm/__init__.py
new file mode 100644
index 0000000..a25b7c8
--- /dev/null
+++ b/entries/lastfm/__init__.py
@@ -0,0 +1,49 @@
+#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2020 Tiago de Paula Peixoto <tiago@skewed.de>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+from .. import *
+
+title = "last.fm listening habits (2007)"
+description = "Two bipartite networks from the music website last.fm, giving the user-song and user-band interactions. Nodes are users and songs/bands, and an edge (i,j) denotes that a user i listens to the song/band j."
+tags = ['Social', 'Online', 'Unweighted']
+url = 'http://konect.cc/networks/lastfm_band'
+citation = [('Ò. Celma Herrada. "Music recommendation and discovery in the long tail.” PhD Thesis (2008).', 'http://repositori.upf.edu/handle/10230/12223')]
+icon_hash = '57fe75bb8cf714f319c3ac25'
+upstream_prefix = 'http://konect.cc/files'
+files = [('download.tsv.lastfm_band.tar.bz2', "band", 'konect'),
+         ('download.tsv.lastfm_song.tar.bz2', "song", 'konect')]
+
+def fetch_upstream(force=False):
+    return fetch_upstream_files(__name__.split(".")[-1], upstream_prefix, files,
+                                force)
+
+@cache_network()
+@coerce_props()
+@annotate()
+def parse(alts=None):
+    global files
+    name = __name__.split(".")[-1]
+    for fnames, alt, fmt in files:
+        if alts is not None and alt not in alts:
+            continue
+        if isinstance(fnames, str):
+            fnames = [fnames]
+        with ExitStack() as stack:
+            fs = [stack.enter_context(open_upstream_file(name, fn, "rb")) for fn in fnames]
+            g = parse_graph(fs, fmt, directed=True)
+        yield alt, g