Much more data is exposed by the API, but we don't use it
		'''
		page = 1
		while True:
			d = self.api_call('user.getlovedtracks', user=user, page=page, limit=limit)
			for track in d['lovedtracks']['track']:
				yield (track['artist']['name'], track['name'])

			if page == 1:
				totalPages = int(d['lovedtracks']['@attr']['totalPages'])
			if page >= totalPages:
				break
			page += 1

if __name__ == "__main__":
	if len(sys.argv) < 2:
		print >> sys.stderr, sys.argv[0],'<lastfm username>'
		exit(1)
	username = sys.argv[1]

	lastfm = LastFmLink('1db991b8f9e0b37d79aea6191b4d5cc7')
	rdio = PlaylistCreator()
	if not rdio.authenticated:
		print "You need to authenticate to Rdio. Run ./authenticate.py then try again"
		sys.exit(1)

	print "Getting loved tracks for %s from last.fm" %(username,)
	tracks = list(lastfm.get_loved_tracks(username))
	print "Putting them into playlist '%s' on your Rdio account" % (PLAYLIST_NAME,)
	rdio.make_playlist(PLAYLIST_NAME, PLAYLIST_DESCRIPTION, tracks)
#!/usr/bin/env python

PLAYLIST_NAME = "My Top Rated"
PLAYLIST_DESCRIPTION = "Imported from iTunes"

import sys, logging
from playlistcreator import PlaylistCreator
pc = PlaylistCreator()
if not pc.authenticated:
    print 'You need to authenticate by running ./authenticate.py first'
    sys.exit(0)

logging.basicConfig(level=logging.WARNING)

from ScriptingBridge import *
itunes = SBApplication.applicationWithBundleIdentifier_("com.apple.iTunes")
playlist = itunes.sources()[0].playlists().objectWithName_(PLAYLIST_NAME)
itunes_tracks = playlist.tracks()
rdio_tracks = []
for track in itunes_tracks:
    #logging.info("%s - %s" % (track.artist().encode("ascii", "replace"), track.name().encode("ascii", "replace")))
    rdio_tracks.append((track.artist(), track.name()))

pc.make_playlist(PLAYLIST_NAME, PLAYLIST_DESCRIPTION, rdio_tracks)
PLAYLIST_NAME='Hype Machine Popular'
PLAYLIST_DESC='Hype Machine Popular tracks, see http://hypem.com/popular'

import sys, logging
logging.basicConfig(level=logging.ERROR)
from playlistcreator import PlaylistCreator
pc = PlaylistCreator()
if not pc.authenticated:
  print 'You need to authenticate by running ./authenticate.py first'
  sys.exit(0)

logging.basicConfig(level=logging.ERROR)

# the Hype Machine "popular" page includes a bunch of structures like:
#   <h3 class="track_name"><a>artist name</a> <a>track name</a></h3>
# we can parse that out into (artistname, trackname) pairs

from BeautifulSoup import BeautifulSoup
from urllib import urlopen

bs = BeautifulSoup(urlopen(URL))

tracks = []

for node in [tn for tn in bs.findAll('h3') if tn.get('class') == 'track_name']:
  artist, track = [a.text for a in node.findChildren('a')]
  tracks.append((artist, track))

# now build a playlist
pc.make_playlist(PLAYLIST_NAME, PLAYLIST_DESC, tracks)
#!/usr/bin/env python

PLAYLIST_NAMES=["My Top Rated"] # Supports a list
PLAYLIST_DESCRIPTION="Imported from iTunes"

import sys, logging
from playlistcreator import PlaylistCreator
from ScriptingBridge import *

pc = PlaylistCreator()
if not pc.authenticated:
  print 'You need to authenticate by running ./authenticate.py first'
  sys.exit(0)

logging.basicConfig(level=logging.WARNING)

for playlist_name in PLAYLIST_NAMES:
  itunes = SBApplication.applicationWithBundleIdentifier_("com.apple.iTunes")
  playlist = itunes.sources()[0].playlists().objectWithName_(playlist_name)
  itunes_tracks = playlist.tracks()
  rdio_tracks = []
  for track in itunes_tracks:
    #logging.info("%s - %s" % (track.artist().encode("ascii", "replace"), track.name().encode("ascii", "replace")))
    rdio_tracks.append((track.artist(),track.name()))

  if rdio_tracks:
    pc.make_playlist(playlist_name, PLAYLIST_DESCRIPTION, rdio_tracks)

Example #5
0
PLAYLIST_NAME = 'Hype Machine Popular'
PLAYLIST_DESC = 'Hype Machine Popular tracks, see http://hypem.com/popular'

import sys, logging
logging.basicConfig(level=logging.ERROR)
from playlistcreator import PlaylistCreator
pc = PlaylistCreator()
if not pc.authenticated:
    print 'You need to authenticate by running ./authenticate.py first'
    sys.exit(0)

logging.basicConfig(level=logging.ERROR)

# the Hype Machine "popular" page includes a bunch of structures like:
#   <h3 class="track_name"><a>artist name</a> <a>track name</a></h3>
# we can parse that out into (artistname, trackname) pairs

from BeautifulSoup import BeautifulSoup
from urllib import urlopen

bs = BeautifulSoup(urlopen(URL))

tracks = []

for node in [tn for tn in bs.findAll('h3') if tn.get('class') == 'track_name']:
    artist, track = [a.text for a in node.findChildren('a')]
    tracks.append((artist, track))

# now build a playlist
pc.make_playlist(PLAYLIST_NAME, PLAYLIST_DESC, tracks)
#!/usr/bin/env python

PLAYLIST_NAME="My Top Rated"
PLAYLIST_DESCRIPTION="Imported from iTunes"

import sys, logging
from playlistcreator import PlaylistCreator
pc = PlaylistCreator()
if not pc.authenticated:
  print 'You need to authenticate by running ./authenticate.py first'
  sys.exit(0)

logging.basicConfig(level=logging.WARNING)


from ScriptingBridge import *
itunes = SBApplication.applicationWithBundleIdentifier_("com.apple.iTunes")
playlist = itunes.sources()[0].playlists().objectWithName_(PLAYLIST_NAME)
itunes_tracks = playlist.tracks()
rdio_tracks = []
for track in itunes_tracks:
    #logging.info("%s - %s" % (track.artist().encode("ascii", "replace"), track.name().encode("ascii", "replace")))
    rdio_tracks.append((track.artist(),track.name()))

pc.make_playlist(PLAYLIST_NAME, PLAYLIST_DESCRIPTION, rdio_tracks)