Michael Lavelle

  • Software Engineering
  • Music
  • Archive
  • RSS

Importing SoundCloud favorites into Ex.Fm using Java and spring-social-music

I’m loving Ex.Fm and wanted to import my SoundCloud favorites into my Ex.Fm profile as loved tracks.   Spent this afternoon making some changes to spring-social-exfm and spring-social-soundcloud modules to allow me to do this with a few lines of Java code.

Here’s a snippet from my new spring-social-music sample utils module that does the job…

// Construct a new SoundCloudTemplate only authorized by api key, as user-level authorization is not needed
// to retrieve favorite tracks
SoundCloud soundCloud = new SoundCloudTemplate(soundCloudApiKey);
		
// Construct a new ExFmTemplate authorized for a specific user, specifying api base url, username and password
ExFm exFm = new ExFmTemplate("http://ex.fm/api/v3",exFmUserId,exFmPassword);
		
// Retrieve the first page of SoundCloud favorite tracks
Page<Track> soundCloudFavorites = soundCloud.usersOperations().userOperations(soundCloudUserId).getFavorites(new PageRequest(0,soundCloudFetchPageSize));
		
// For each page of SoundCloud favorite tracks...
for (int pageNumber = 0; pageNumber < soundCloudFavorites.getTotalPages();pageNumber++)
{
	// For each SoundCloud favorite track on current page, love the track on Ex.Fm using the stream url
	for (Track soundCloudTrack : soundCloudFavorites)
	{
		sleepForLimitRate();
		try
		{
			exFm.songOperations().loveSongBySourceUrl(soundCloudTrack.getStreamUrl());
		}
		catch (ResourceNotFoundException e)
		{
			// Failed to love song as Ex.Fm can't find information about the soundcloud track with this url
		}
	}
// Get next page of tracks from SoundCloud if available if (soundCloudFavorites.hasNextPage()) soundCloudFavorites = soundCloud.usersOperations().userOperations(soundCloudUserId).getFavorites(new PageRequest(pageNumber + 1,soundCloudFetchPageSize)); }



Checkout the spring-social-music module to see the full source code and dependencies used by the snippet above, or add the following repository and dependency to your maven project in order to use or modify the simple utility class for your project.

	<repositories>
<repository>
<id>opensourceagility-snapshots</id>
<url>http://repo.opensourceagility.com/snapshots</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.springsocialmusic</groupId>
<artifactId>spring-social-music</artifactId>
<version>1.0.1-SNAPSHOT</version>
</dependency>
</dependencies>

The utility class to import SoundCloud favorites into Ex.Fm as loved tracks could then be called as shown below:

SoundCloudToExFmMigrator soundCloudToExFmMigrator = new SoundCloudToExFmMigrator(mySoundCloudApiKey);
		soundCloudToExFmMigrator.loveSoundCloudFavoritesOnExFm(fromSoundCloudUserName, exFmUserName,exFmPassword);




    • #ex.fm
    • #java
    • #soundcloud
    • #spring social
    • #springsocial
    • #software engineering
    • #exfm
  • 1 year ago
  • 4
  • Permalink
  • Share
    Tweet

About

Avatar

Software Engineer, Musician, Mathematician & novice Archer.

Currently living in London

See my homepage for an overview of my Java projects and commercial experience.
  • java
  • machine learning
  • electropop
  • spring-social
  • cloudplaylists
  • ex.fm

Me, Elsewhere

  • @michaellavelle on Twitter
  • michaellavelle on Last.fm
  • michaellavelle on Soundcloud
  • Linkedin Profile
  • michaellavelle on github

Twitter

loading tweets…

Following

I Dig These Posts

  • Post via christianoshi
    "Winehouse is dead, phone hacking, riots...and, of course, the weather is beyond shit"

    image

    Interview: Courtney Nichols / Photo: Yael Fachler

    ...

    Post via christianoshi
  • Post via michaellavelle
    The dance music of 1987 still an influence 25 years later

    2012:

    1987:

    Post via michaellavelle
  • Post via michaellavelle
    Making Connections with Spring Social

    Craig Walls talks at SpringOne 2GX 2012 about Spring Social.

    Check out the “Spring Social Project...

    Post via michaellavelle
  • Post via taichionthehillnomore
    Tai Chi training

    Training deeply and training for physical strength are not the same thing. Understand your intention to train efficiently.
    If you...

    Post via taichionthehillnomore
See more →
  • RSS
  • Random
  • Archive
  • Mobile

Effector Theme by Carlo Franco.

Powered by Tumblr