def setup(self, session=None): """Create the `discogs_client` field. Authenticate if necessary. """ c_key = self.config['apikey'].as_str() c_secret = self.config['apisecret'].as_str() # Try using a configured user token (bypassing OAuth login). user_token = self.config['user_token'].as_str() if user_token: # The rate limit for authenticated users goes up to 60 # requests per minute. self.rate_limit_per_minute = 60 self.discogs_client = Client(USER_AGENT, user_token=user_token) return # Get the OAuth token from a file or log in. try: with open(self._tokenfile()) as f: tokendata = json.load(f) except IOError: # No token yet. Generate one. token, secret = self.authenticate(c_key, c_secret) else: token = tokendata['token'] secret = tokendata['secret'] self.discogs_client = Client(USER_AGENT, c_key, c_secret, token, secret)
def __init__(self): super(DiscogsPlugin, self).__init__() self.config.add({ 'apikey': 'rAzVUQYRaoFjeBjyWuWZ', 'apisecret': 'plxtUTqoCzwxZpqdPysCwGuBSmZNdZVy', 'tokenfile': 'discogs_token.json', 'source_weight': 0.5, }) c_key = self.config['apikey'].get(unicode) c_secret = self.config['apisecret'].get(unicode) # Get the OAuth token from a file or log in. try: with open(self._tokenfile()) as f: tokendata = json.load(f) except IOError: # No token yet. Generate one. token, secret = self.authenticate(c_key, c_secret) else: token = tokendata['token'] secret = tokendata['secret'] self.discogs_client = Client(USER_AGENT, c_key, c_secret, token, secret)
def authenticate(self, c_key, c_secret): # Get the link for the OAuth page. auth_client = Client(USER_AGENT, c_key, c_secret) try: _, _, url = auth_client.get_authorize_url() except CONNECTION_ERRORS as e: self._log.debug(u'connection error: {0}', e) raise beets.ui.UserError(u'communication with Discogs failed') beets.ui.print_(u"To authenticate with Discogs, visit:") beets.ui.print_(url) # Ask for the code and validate it. code = beets.ui.input_(u"Enter the code:") try: token, secret = auth_client.get_access_token(code) except DiscogsAPIError: raise beets.ui.UserError(u'Discogs authorization failed') except CONNECTION_ERRORS as e: self._log.debug(u'connection error: {0}', e) raise beets.ui.UserError(u'Discogs token request failed') # Save the token for later use. self._log.debug(u'Discogs token {0}, secret {1}', token, secret) with open(self._tokenfile(), 'w') as f: json.dump({'token': token, 'secret': secret}, f) return token, secret
def __init__(self): self.consumer_key = 'pDGCsGkOvnpeoypQDyMp' self.consumer_secret = 'MXrkZgMMofvlTBVMWwGIYIgdfjXWXhvM' if self.is_authenticated(): from access_tokens import access_token, access_secret self.discogs = Client(USER_AGENT, consumer_key=self.consumer_key, consumer_secret=self.consumer_secret, token=access_token, secret=access_secret) # If user does not have access token and secret we need to use OAuth else: self.discogs = Client(USER_AGENT) self.get_request_token()
def __init__(self): super(DiscogsPlugin, self).__init__() self.config.add({ 'source_weight': 0.5, }) self.discogs_client = Client('beets/%s +http://beets.radbox.org/' % beets.__version__)
def file_client(): client = Client('test_client/0.1 +http://example.org') client._base_url = '' client._fetcher = LoggingDelegator( FilesystemFetcher(os.path.dirname(os.path.abspath(__file__)) + '/res')) client._verbose = True client.got = got client.posted = posted return client
def setUp(self): # Filesystem client self.d = Client('test_client/0.1 +http://example.org') self.d._base_url = '' self.d._fetcher = LoggingDelegator( FilesystemFetcher( os.path.dirname(os.path.abspath(__file__)) + '/res')) self.d._verbose = True # Memory client responses = { '/artists/1': (b'{"id": 1, "name": "Badger"}', 200), '/500': (b'{"message": "mushroom"}', 500), '/204': (b'', 204), } self.m = Client('ua') self.m._base_url = '' self.m._fetcher = LoggingDelegator(MemoryFetcher(responses))
def memory_client(): responses = { '/artists/1': (b'{"id": 1, "name": "Badger"}', 200), '/500': (b'{"message": "mushroom"}', 500), '/204': (b'', 204), } client = Client('ua') client._base_url = '' client._fetcher = LoggingDelegator(MemoryFetcher(responses)) client.got = got client.posted = posted return client
def test_user_agent(file_client): """User-Agent should be properly set""" file_client.artist(1).name bad_client = Client('') with pytest.raises(ConfigurationError): bad_client.artist(1).name try: bad_client.artist(1).name except ConfigurationError as e: assert 'User-Agent' in str(e)
def test_user_agent(self): """User-Agent should be properly set""" self.d.artist(1).name bad_client = Client('') self.assertRaises(ConfigurationError, lambda: bad_client.artist(1).name) try: bad_client.artist(1).name except ConfigurationError as e: self.assertTrue('User-Agent' in str(e))
def setup(self, session=None): """Create the `discogs_client` field. Authenticate if necessary. """ c_key = self.config['apikey'].as_str() c_secret = self.config['apisecret'].as_str() # Get the OAuth token from a file or log in. try: with open(self._tokenfile()) as f: tokendata = json.load(f) except IOError: # No token yet. Generate one. token, secret = self.authenticate(c_key, c_secret) else: token = tokendata['token'] secret = tokendata['secret'] self.discogs_client = Client(USER_AGENT, c_key, c_secret, token, secret)
def authenticate(self, c_key, c_secret): # Get the link for the OAuth page. auth_client = Client(USER_AGENT, c_key, c_secret) _, _, url = auth_client.get_authorize_url() beets.ui.print_("To authenticate with Discogs, visit:") beets.ui.print_(url) # Ask for the code and validate it. code = beets.ui.input_("Enter the code:") try: token, secret = auth_client.get_access_token(code) except DiscogsAPIError: raise beets.ui.UserError('Discogs authorization failed') # Save the token for later use. log.debug('Discogs token {0}, secret {1}'.format(token, secret)) with open(self._tokenfile(), 'w') as f: json.dump({'token': token, 'secret': secret}, f) return token, secret
def __init__(self, user_token=None): self.client = Client(Discogs.APP_VERSION, user_token=user_token)
app = QtGui.QApplication(sys.argv) iconpath = resource_path(os.path.join(ICN_DIR, 'discopy.ico')) start = time() splashpath = resource_path(os.path.join(ICN_DIR, SPLSH_SCRN)) splash = QtGui.QSplashScreen(QtGui.QPixmap(splashpath)) splash.show() while time() - start < 2: sleep(0.001) app.processEvents() win = DiscoPy( Ui_MainWindow(), settingsHandler, Client('discopy/0.1', CONSUMER_KEY, CONSUMER_SECRET, TOKEN, SECRET), NameBuilder(), TagData, ImageHandler()) win.setWindowIcon(QtGui.QIcon(iconpath)) win.set_rename_dialog(RenameDialog(settingsHandler, win)) splash.finish(win) # import ctypes # appid = 'discopy.0.1' # ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(appid) win.center() win.show()
# Importing discogs_client from https://github.com/joalla/discogs_client from discogs_client import Client d = Client('ZorroDiscogClient/0.1', user_token='pKyILjZnXBGRToDMAcXdcGDpPtMTgNyzqRSVBBJO') # General search query def search(query): results = d.search(query, format='vinyl') return results # Search by barcode def searchbarcode(query): results = d.search(query, type='release', format='vinyl') return results # Searches by artist ID def searchartistid(artistid): results = d.artist(artistid) print(results.name) # Searched by release id def searchreleaseid(releaseid): results = d.release(releaseid) print(results.title) print(results.artists) print(results.year)
import time import os from discogs_client import Client from discogs_client.exceptions import HTTPError user_token = os.environ.get('DISCOGS_TOKEN') dgs_client = Client('EventbriteTest/1.2.1', user_token=user_token) class DiscoGSError(RuntimeError): pass def retryer(max_retries=10, timeout=5): def wraps(func): def inner(*args, **kwargs): for i in range(max_retries): try: result = func(*args, **kwargs) except HTTPError: time.sleep(timeout) continue else: return result else: raise DiscoGSError return inner
import os import audio import net import utils from dotenv import load_dotenv from discogs_client import Client load_dotenv() DISCOGS_USER_TOKEN = os.getenv('DISCOGS_USER_TOKEN') discogs_api = Client('Katalog', user_token=DISCOGS_USER_TOKEN) def get_release(discogs_id): return discogs_api.release(discogs_id) # release = get_release(34534) # video_urls = [video.url for video in release.videos] # styles = release.styles # genres = release.genres # audio.download_wav(video_urls[0]) # wav_filename = utils.video_url_to_wav_filename(video_urls[0]) # import IPython.display as play # play.Audio(wav_filename) # waveform, samplerate = net.load_tensor(wav_filename) # print(40)