Does Spotify Track model work with local files?

I’m wondering if the Spotify Track model can handle local files or if it only works with tracks from the Spotify catalog?

I created a small Spotify application that adds up the total duration of tracks when you drag them to the sidebar. The app works perfectly for regular Spotify tracks but doesn’t seem to get any data from local music files on my computer.

Here’s my current code:

models.application.observe(models.EVENT.LINKSCHANGED, function () {
    var totalDuration = 0;
    var trackLinks = models.application.links;
    if (trackLinks.length) {
        for (var j = 0; j < trackLinks.length; j++) {
            var song = models.Track.fromURI(trackLinks[j], function(songData) {
                totalDuration = totalDuration + songData.duration;
            });
        }
    }

    document.getElementById("duration").innerHTML = formatTime(Math.round(totalDuration/1000));
});

The code runs without errors and calculates time correctly for streaming tracks. However, I specifically built this to measure the total length of my audiobook files stored locally. Is there any way to make this work with local content?

Yeah, local files are basically broken in the Spotify Track model. I ran into this exact problem - local files get treated as separate entities with almost no metadata access. Sure, you can create Track objects from local file URIs, but you can’t get duration, artist, album info, or anything useful through the standard API. Spotify doesn’t process or store metadata for your local files on their servers, so there’s nothing to pull from. For audiobook duration stuff, you’re better off using HTML5 Audio API or file system libraries that can read metadata directly from the files themselves. Or just handle local files completely separately from Spotify catalog tracks in your app logic.

Nope, the track model breaks with local files. When you drag local tracks, the API sees them but can’t grab duration or metadata - Spotify doesn’t store that stuff for personal files. You’ll just get undefined values. Try detecting local vs catalog tracks first and handle them differently.

The Spotify Track model barely works with local files. I’ve worked with the Spotify Apps API, and local files get treated completely differently than catalog tracks—most properties just return null or undefined. Local files don’t have the same metadata structure as streamed content, which is why your duration calculation isn’t working. The API recognizes local files but can’t access detailed properties like duration since this data isn’t in Spotify’s database. You may need to try different approaches for local file metadata. Some developers work around this by using libraries that read file metadata directly from the filesystem, but it depends on your environment and security restrictions.