Example #1
0
def api():
    global __rdio__, __rdio_state__
    if not __rdio__:
        __rdio__ = Rdio("u4lennlndjhvfnitfntn3mcvzi", "YO2oHvLK5rOCQTnFJvNq-Q", __rdio_state__)
        if not __rdio_state__.get('device_code'):
            url, device_code = __rdio__.begin_authentication()
            raw_input('After entering the device code "{}" into {} press enter'.format(device_code, url))
            __rdio__.complete_authentication()
            print __rdio_state__
    return __rdio__
Example #2
0
class RdioHelper:

    RDIO_USER_CONFIG = "~/.rdio-tool.json"

    def __init__(self, options):

        # load the persistent state
        config_path = os.path.expanduser(self.RDIO_USER_CONFIG)
        if os.path.exists(config_path):
            self.config = json.load(file(config_path))
        else:
            self.config = {"auth_state": {}}

        # set up the keys
        if options.consumer_key is not None:
            self.config["consumer_key"] = options.consumer_key
        if options.consumer_secret is not None:
            self.config["consumer_secret"] = options.consumer_secret

        # create the Rdio client object
        self.client = Rdio(self.config["consumer_key"], self.config["consumer_secret"], self.config["auth_state"])

        if options.authenticate:
            import webbrowser

            webbrowser.open(self.client.begin_authentication("oob"))
            verifier = raw_input("Enter the PIN from the Rdio site: ").strip()
            self.client.complete_authentication(verifier)

        # save state
        with file(config_path, "w") as f:
            json.dump(self.config, f, indent=True)
            f.write("\n")

    def authenticate(self):
        import webbrowser

        webbrowser.open(self.client.begin_authentication("oob"))
        verifier = raw_input("Enter the PIN from the Rdio site: ").strip()
        self.client.complete_authentication(verifier)

    def getObjectFromShortCode(self, short_code):
        return self.client.getObjectFromShortCode(short_code=short_code)

    def getObjectFromUrl(self, path):
        return self.client.getObjectFromUrl(url=path)

    def getNewReleases(self, **args):
        return self.client.getNewReleases(**args)

    def getArtistsInCollection(self, **args):
        return self.client.getArtistsInCollection(**args)
Example #3
0
def get_base_rdio_client():
    config = _get_stored_config()
    config = _add_missing_config(config)
    needs_auth = len(config.client_state) == 0

    rdio = Rdio(
        config.credentials.client_id,
        config.credentials.client_secret,
        config.client_state
    )

    if needs_auth:
        rdio.begin_authentication()
        url, device_code = rdio.begin_authentication()
        print u"Please enter device code {} on {}".format(device_code, url)
        rdio.complete_authentication()

    _set_stored_config(config)
    return rdio
parser.add_argument('-c',
        dest='track_count',
        action='store',
        default=3,
        help="How many tracks per artists to add to playlist. Defaults to 3")
args = parser.parse_args()

if not args.input_file or not args.pl_name or not args.pl_desc:
    raise InputError('You must specify an input file containing a list of artists, \
            a name for your playlist, and a description for the playlist')

# Oauth authentication needed for creating the new playlist
state = {}
r = Rdio(CONSUMER_KEY, CONSUMER_SECRET, state)
print 'Get PIN code from the following URL: %s' % r.begin_authentication('oob')
r.complete_authentication(raw_input('enter pin code:'))

# Read the list of artists
artists = open(args.input_file, 'r').readlines()

# Find track keys for top 3 tracks per artist
pl_tracks = []
for a in artists:
    try:
        url = '/artist/' + a.strip().title().replace(' ', '_').replace('&', '') + '/'
        artist_key = r.getObjectFromUrl(url=url)['key']
        tracks = r.getTracksForArtist(artist=artist_key, count=args.track_count)
        # make sure key is for a track and for the right artist
        track_keys = [t['key'] for t in tracks \
                if t['artistUrl'].lower() == url.lower() \
                and t['key'].startswith('t')]
Example #5
0
#!/usr/bin/python
from rdio_consumer_credentials import *

from rdioapi import Rdio
state = {}
r = Rdio(RDIO_CONSUMER_KEY, RDIO_CONSUMER_SECRET, state)

import webbrowser
webbrowser.open(r.begin_authentication('oob'))
verifier = raw_input('Enter the PIN from the Rdio site: ').strip()
r.complete_authentication(verifier)

from pprint import pprint

i = 0
batch = 2500
while True:
  print "fetching collection tracks %d -> %d" % (i, i+batch)
  tracks = r.call('getTracksInCollection', count=i+batch, start=i)
  trackIds = []
  for t in tracks:
    if 'isAvailableOffline' in t and t['isAvailableOffline']:
      trackIds.append(t['key'])
  print "\tfound %d synced tracks tracks" % (len(trackIds))
  if len(trackIds):
    keys = ','.join(trackIds)
    r.call('setAvailableOffline', offline=False, keys=keys)
 
  i += batch
  if len(tracks) < batch:
    print "that was it"