code
string
signature
string
docstring
string
loss_without_docstring
float64
loss_with_docstring
float64
factor
float64
wrapped_func = SimpleCLFunction.from_string(''' double _negate_''' + func.get_cl_function_name() + '''( local mot_float_type* x, void* data, local mot_float_type* objective_list){ double return_val = ''' + func.get_cl_function_name() + '''(x...
def maximize(func, x0, nmr_observations, **kwargs)
Maximization of a function. This wraps the objective function to take the negative of the computed values and passes it then on to one of the minimization routines. Args: func (mot.lib.cl_function.CLFunction): A CL function with the signature: .. code-block:: c double...
4.227765
3.189315
1.325603
if method == 'Powell': return {'patience': 2, 'patience_line_search': None, 'reset_method': 'EXTRAPOLATED_POINT'} elif method == 'Nelder-Mead': return {'patience': 200, 'alpha': 1.0, 'beta': 0.5, 'gamma': 2.0, 'delta': 0.5, 'scale': 0.1, ...
def get_minimizer_options(method)
Return a dictionary with the default options for the given minimization method. Args: method (str): the name of the method we want the options off Returns: dict: a dictionary with the default options
3.86172
3.92338
0.984284
provided_options = provided_options or {} default_options = get_minimizer_options(method) result = {} for name, default in default_options.items(): if name in provided_options: result[name] = provided_options[name] else: result[name] = default_options[name]...
def _clean_options(method, provided_options)
Clean the given input options. This will make sure that all options are present, either with their default values or with the given values, and that no other options are present then those supported. Args: method (str): the method name provided_options (dict): the given options Return...
2.673778
3.286086
0.813666
options = options or {} nmr_problems = x0.shape[0] nmr_parameters = x0.shape[1] penalty_data, penalty_func = _get_penalty_function(nmr_parameters, constraints_func) eval_func = SimpleCLFunction.from_string(''' double evaluate(local mot_float_type* x, void* data){ double pe...
def _minimize_powell(func, x0, cl_runtime_info, lower_bounds, upper_bounds, constraints_func=None, data=None, options=None)
Options: patience (int): Used to set the maximum number of iterations to patience*(number_of_parameters+1) reset_method (str): one of 'EXTRAPOLATED_POINT' or 'RESET_TO_IDENTITY' lower case or upper case. patience_line_search (int): the patience of the searching algorithm. Defaults to the ...
4.613266
4.772212
0.966693
dependencies = [] data_requirements = {'scratch': LocalMemory('double', 1)} constraints_code = '' if constraints_func and constraints_func.get_nmr_constraints() > 0: nmr_constraints = constraints_func.get_nmr_constraints() dependencies.append(constraints_func) data_requirem...
def _get_penalty_function(nmr_parameters, constraints_func=None)
Get a function to compute the penalty term for the boundary conditions. This is meant to be used in the evaluation function of the optimization routines. Args: nmr_parameters (int): the number of parameters in the model constraints_func (mot.optimize.base.ConstraintFunction): function to compu...
3.75023
3.116638
1.203293
return_type, function_name, parameter_list, body = split_cl_function(cl_function) return SimpleConstraintFunction(return_type, function_name, parameter_list, body, dependencies=dependencies, nmr_constraints=nmr_constraints)
def from_string(cls, cl_function, dependencies=(), nmr_constraints=None)
Parse the given CL function into a SimpleCLFunction object. Args: cl_function (str): the function we wish to turn into an object dependencies (list or tuple of CLLibrary): The list of CL libraries this function depends on Returns: SimpleCLFunction: the CL data type ...
3.782197
3.851171
0.98209
schema = Schema({ 'lane' if not branch else 'branch': { Optional('name'): str, Optional('run_parallel'): bool, 'tasks': list } }) schema.validate(yaml_def) from schema import And, Use task_schema = Schema({ 'class': str, Optio...
def validate_schema(yaml_def, branch=False)
Validates the schema of a dict Parameters ---------- yaml_def : dict dict whose schema shall be validated branch : bool Indicates whether `yaml_def` is a dict of a top-level lane, or of a branch inside a lane (needed for recursion) Returns ------- bool True ...
3.9804
4.390933
0.906504
mtd = getattr(cls, mtd_name) py3_mtd_condition = (not (inspect.isfunction(mtd) or inspect.ismethod(mtd)) and hasattr(cls, mtd_name)) py2_mtd_condition = (not inspect.ismethod(mtd) and not isinstance(cls.__dict__[mtd_name], staticmethod)) if (PY3 an...
def validate_params(cls, mtd_name, *args, **kwargs)
Validates if the given args/kwargs match the method signature. Checks if: - at least all required args/kwargs are given - no redundant args/kwargs are given Parameters ---------- cls : Class mtd_name : str Name of the method whose parameters shall be validated args: list Pos...
2.344964
2.327914
1.007324
mtd = getattr(cls, mtd_name) required_params = [] optional_params = [] if hasattr(inspect, 'signature'): # Python 3 params = inspect.signature(mtd).parameters # pylint: disable=no-member for k in params.keys(): if params[k].default == inspect.Parameter.empty: # pyl...
def arg_spec(cls, mtd_name)
Cross-version argument signature inspection Parameters ---------- cls : class mtd_name : str Name of the method to be inspected Returns ------- required_params : list of str List of required, positional parameters optional_params : list of str List of optional p...
2.633827
2.638724
0.998144
if is_scalar(low): low = np.ones((nmr_distributions, 1)) * low if is_scalar(high): high = np.ones((nmr_distributions, 1)) * high kernel_data = {'low': Array(low, as_scalar=True), 'high': Array(high, as_scalar=True)} kernel = SimpleCLFunction.from_string(''' ...
def uniform(nmr_distributions, nmr_samples, low=0, high=1, ctype='float', seed=None)
Draw random samples from the Uniform distribution. Args: nmr_distributions (int): the number of unique continuous_distributions to create nmr_samples (int): The number of samples to draw low (double): The minimum value of the random numbers high (double): The minimum value of the ra...
3.748317
3.784362
0.990475
if is_scalar(mean): mean = np.ones((nmr_distributions, 1)) * mean if is_scalar(std): std = np.ones((nmr_distributions, 1)) * std kernel_data = {'mean': Array(mean, as_scalar=True), 'std': Array(std, as_scalar=True)} kernel = SimpleCLFunction.from_string(''' ...
def normal(nmr_distributions, nmr_samples, mean=0, std=1, ctype='float', seed=None)
Draw random samples from the Gaussian distribution. Args: nmr_distributions (int): the number of unique continuous_distributions to create nmr_samples (int): The number of samples to draw mean (float or ndarray): The mean of the distribution std (float or ndarray): The standard devi...
3.809194
3.812376
0.999165
if not thinning or thinning < 1: thinning = 1 if not burnin or burnin < 0: burnin = 0 max_samples_per_batch = max(1000 // thinning, 100) with self._logging(nmr_samples, burnin, thinning): if burnin > 0: for batch_start, batch...
def sample(self, nmr_samples, burnin=0, thinning=1)
Take additional samples from the given likelihood and prior, using this sampler. This method can be called multiple times in which the sample state is stored in between. Args: nmr_samples (int): the number of samples to return burnin (int): the number of samples to discard befo...
2.762755
2.712454
1.018545
kernel_data = self._get_kernel_data(nmr_samples, thinning, return_output) sample_func = self._get_compute_func(nmr_samples, thinning, return_output) sample_func.evaluate(kernel_data, self._nmr_problems, use_local_reduction=all(env.is_gpu for env in self._cl_...
def _sample(self, nmr_samples, thinning=1, return_output=True)
Sample the given number of samples with the given thinning. If ``return_output`` we will return the samples, log likelihoods and log priors. If not, we will advance the state of the sampler without returning storing the samples. Args: nmr_samples (int): the number of iterations to ...
4.069725
4.083171
0.996707
func = SimpleCLFunction.from_string(''' void compute(global mot_float_type* chain_position, global mot_float_type* log_likelihood, global mot_float_type* log_prior, local mot_float_type* x_tmp, ...
def _initialize_likelihood_prior(self, positions, log_likelihoods, log_priors)
Initialize the likelihood and the prior using the given positions. This is a general method for computing the log likelihoods and log priors for given positions. Subclasses can use this to instantiate secondary chains as well.
3.749031
3.770291
0.994361
kernel_data = { 'data': self._data, 'method_data': self._get_mcmc_method_kernel_data(), 'nmr_iterations': Scalar(nmr_samples * thinning, ctype='ulong'), 'iteration_offset': Scalar(self._sampling_index, ctype='ulong'), 'rng_state': Array(self._...
def _get_kernel_data(self, nmr_samples, thinning, return_output)
Get the kernel data we will input to the MCMC sampler. This sets the items: * data: the pointer to the user provided data * method_data: the data specific to the MCMC method * nmr_iterations: the number of iterations to sample * iteration_offset: the current sample index, that ...
2.738355
2.111799
1.296693
cl_func = ''' void compute(global uint* rng_state, global mot_float_type* current_chain_position, global mot_float_type* current_log_likelihood, global mot_float_type* current_log_prior, ulo...
def _get_compute_func(self, nmr_samples, thinning, return_output)
Get the MCMC algorithm as a computable function. Args: nmr_samples (int): the number of samples we will draw thinning (int): the thinning factor we want to use return_output (boolean): if the kernel should return output Returns: mot.lib.cl_function.CLFun...
3.531275
3.498425
1.00939
return SimpleCLFunction.from_string(''' mot_float_type _computeLogPrior(local const mot_float_type* x, void* data){ return ''' + self._log_prior_func.get_cl_function_name() + '''(x, data); } ''', dependencies=[self._log_prior_func])
def _get_log_prior_cl_func(self)
Get the CL log prior compute function. Returns: str: the compute function for computing the log prior.
10.620206
11.994408
0.88543
return SimpleCLFunction.from_string(''' double _computeLogLikelihood(local const mot_float_type* current_position, void* data){ return ''' + self._ll_func.get_cl_function_name() + '''(current_position, data); } ''', dependencies=[self._ll_func])
def _get_log_likelihood_cl_func(self)
Get the CL log likelihood compute function. This uses local reduction to compute the log likelihood for every observation in CL local space. The results are then summed in the first work item and returned using a pointer. Returns: str: the CL code for the log likelihood compute fun...
12.509809
12.980324
0.963752
return {'proposal_stds': Array(self._proposal_stds, 'mot_float_type', mode='rw', ensure_zero_copy=True), 'x_tmp': LocalMemory('mot_float_type', nmr_items=1 + self._nmr_params)}
def _get_mcmc_method_kernel_data_elements(self)
Get the mcmc method kernel data elements. Used by :meth:`_get_mcmc_method_kernel_data`.
25.912388
23.135136
1.120045
def get_cl_function(): nmr_params = parameters.shape[1] if len(parameters.shape) > 2: return SimpleCLFunction.from_string(''' void compute(global mot_float_type* parameters, global mot_float_type* log_likelihoods, ...
def compute_log_likelihood(ll_func, parameters, data=None, cl_runtime_info=None)
Calculate and return the log likelihood of the given model for the given parameters. This calculates the log likelihoods for every problem in the model (typically after optimization), or a log likelihood for every sample of every model (typically after sample). In the case of the first (after optimization)...
2.802325
2.565733
1.092212
return objective_func.evaluate({'data': data, 'parameters': Array(parameters, 'mot_float_type', mode='r')}, parameters.shape[0], use_local_reduction=True, cl_runtime_info=cl_runtime_info)
def compute_objective_value(objective_func, parameters, data=None, cl_runtime_info=None)
Calculate and return the objective function value of the given model for the given parameters. Args: objective_func (mot.lib.cl_function.CLFunction): A CL function with the signature: .. code-block:: c double <func_name>(local const mot_float_type* const x, ...
10.163044
9.199621
1.104724
redis = get_redis_client() log_key = 'log:{}'.format(username) raw_log = redis.lrange(log_key, 0, -1) log = [] for raw_item in raw_log: item = json.loads(raw_item.decode()) item['datetime'] = convert_timestamp(item.pop('time')) log.append(item) return log
def get_log(username)
Return a list of page views. Each item is a dict with `datetime`, `method`, `path` and `code` keys.
2.336538
2.248174
1.039305
redis = get_redis_client() token = get_random_string(length) token_key = 'token:{}'.format(token) redis.set(token_key, username) redis.expire(token_key, timeout) return token
def get_token(username, length=20, timeout=20)
Obtain an access token that can be passed to a websocket client.
2.368229
2.411502
0.982055
return { 'method': request.method, 'path': request.get_full_path(), 'code': response.status_code, 'time': time.time(), }
def get_log(self, request, response)
Return a dict of data to log for a given request and response. Override this method if you need to log a different set of values.
2.829105
2.590788
1.091986
song_id = song['id'] response = self._call( mm_calls.Export, self.uploader_id, song_id) audio = response.body suggested_filename = unquote( response.headers['Content-Disposition'].split("filename*=UTF-8''")[-1] ) return (audio, suggested_filename)
def download(self, song)
Download a song from a Google Music library. Parameters: song (dict): A song dict. Returns: tuple: Song content as bytestring, suggested filename.
5.74194
5.082411
1.129767
response = self._call( mm_calls.ClientState, self.uploader_id ) client_state = response.body.clientstate_response return (client_state.total_track_count, client_state.locker_track_limit)
def quota(self)
Get the uploaded track count and allowance. Returns: tuple: Number of uploaded tracks, number of tracks allowed.
14.850395
10.346949
1.435244
if not uploaded and not purchased: raise ValueError("'uploaded' and 'purchased' cannot both be False.") if purchased and uploaded: song_list = [] for chunk in self.songs_iter(export_type=1): song_list.extend(chunk) elif purchased: song_list = [] for chunk in self.songs_iter(export_type=2):...
def songs(self, *, uploaded=True, purchased=True)
Get a listing of Music Library songs. Returns: list: Song dicts.
2.075229
2.056439
1.009137
def track_info_to_dict(track_info): return dict( (field.name, value) for field, value in track_info.ListFields() ) while True: response = self._call( mm_calls.ExportIDs, self.uploader_id, continuation_token=continuation_token, export_type=export_type ) items = [ trac...
def songs_iter(self, *, continuation_token=None, export_type=1)
Get a paged iterator of Music Library songs. Parameters: continuation_token (str, Optional): The token of the page to return. Default: Not sent to get first page. export_type (int, Optional): The type of tracks to return. 1 for all tracks, 2 for promotional and purchased. Default: ``1`` Yields: l...
2.939041
2.997832
0.980389
self._username = username self._oauth(username, token=token) return self.is_authenticated
def login(self, username, *, token=None)
Log in to Google Music. Parameters: username (str, Optional): Your Google Music username. Used for keeping stored OAuth tokens for multiple accounts separate. device_id (str, Optional): A mobile device ID or music manager uploader ID. Default: MAC address is used. token (dict, Optional): An OAuth to...
8.028806
8.190268
0.980286
if self.logout(): return self.login(username, token=token) return False
def switch_user(self, username='', *, token=None)
Log in to Google Music with a different user. Parameters: username (str, Optional): Your Google Music username. Used for keeping stored OAuth tokens for multiple accounts separate. token (dict, Optional): An OAuth token compatible with ``requests-oauthlib``. Returns: bool: ``True`` if successfully au...
6.805519
6.608771
1.029771
pivot = floor(K/S) return [S/K * 1/d for d in range(1, pivot)] \ + [S/K * log(S/delta)] \ + [0 for d in range(pivot, K)]
def gen_tau(S, K, delta)
The Robust part of the RSD, we precompute an array for speed
5.805619
6.425298
0.903556
S = c * log(K/delta) * sqrt(K) tau = gen_tau(S, K, delta) rho = gen_rho(K) normalizer = sum(rho) + sum(tau) return [(rho[d] + tau[d])/normalizer for d in range(K)]
def gen_mu(K, delta, c)
The Robust Soliton Distribution on the degree of transmitted blocks
5.702886
5.777405
0.987102
mu = gen_mu(K, delta, c) return [sum(mu[:d+1]) for d in range(K)]
def gen_rsd_cdf(K, delta, c)
The CDF of the RSD on block degree, precomputed for sampling speed
5.709478
5.584617
1.022358
self.state = PRNG_A * self.state % PRNG_M return self.state
def _get_next(self)
Executes the next iteration of the PRNG evolution process, and returns the result
19.37051
9.066401
2.136516
p = self._get_next() / PRNG_MAX_RAND for ix, v in enumerate(self.cdf): if v > p: return ix + 1 return ix + 1
def _sample_d(self)
Samples degree given the precomputed distributions above and the linear PRNG output
10.95883
8.875634
1.23471
if seed: self.state = seed blockseed = self.state d = self._sample_d() have = 0 nums = set() while have < d: num = self._get_next() % self.K if num not in nums: nums.add(num) have += 1 ...
def get_src_blocks(self, seed=None)
Returns the indices of a set of `d` source blocks sampled from indices i = 1, ..., K-1 uniformly, where `d` is sampled from the RSD described above.
5.811159
5.089307
1.141837
with open(fn, 'rb') as f: for block in encode.encoder(f, blocksize, seed, c, delta): sys.stdout.buffer.write(block)
def run(fn, blocksize, seed, c, delta)
Run the encoder until the channel is broken, signalling that the receiver has successfully reconstructed the file
3.236217
3.187067
1.015422
subscribed = next( ( config_item['value'] == 'true' for config_item in self.config() if config_item['key'] == 'isNautilusUser' ), None ) if subscribed: self.tier = 'aa' else: self.tier = 'fr' return subscribed
def is_subscribed(self)
The subscription status of the account linked to the :class:`MobileClient` instance.
5.535928
5.297343
1.045039
response = self._call( mc_calls.FetchAlbum, album_id, include_description=include_description, include_tracks=include_songs ) album_info = response.body return album_info
def album(self, album_id, *, include_description=True, include_songs=True)
Get information about an album. Parameters: album_id (str): An album ID. Album IDs start with a 'B'. include_description (bool, Optional): Include description of the album in the returned dict. include_songs (bool, Optional): Include songs from the album in the returned dict. Default: ``True``. Retur...
4.571253
5.118708
0.893048
response = self._call( mc_calls.FetchArtist, artist_id, include_albums=include_albums, num_related_artists=num_related_artists, num_top_tracks=num_top_tracks ) artist_info = response.body return artist_info
def artist( self, artist_id, *, include_albums=True, num_related_artists=5, num_top_tracks=5 )
Get information about an artist. Parameters: artist_id (str): An artist ID. Artist IDs start with an 'A'. include_albums (bool, Optional): Include albums by the artist in returned dict. Default: ``True``. num_related_artists (int, Optional): Include up to given number of related artists in returned dict...
2.715102
2.910788
0.932772
response = self._call( mc_calls.PodcastBrowse, podcast_genre_id=podcast_genre_id ) podcast_series_list = response.body.get('series', []) return podcast_series_list
def browse_podcasts(self, podcast_genre_id='JZCpodcasttopchartall')
Get the podcasts for a genre from the Podcasts browse tab. Parameters: podcast_genre_id (str, Optional): A podcast genre ID as found in :meth:`browse_podcasts_genres`. Default: ``'JZCpodcasttopchartall'``. Returns: list: Podcast dicts.
4.500231
5.425839
0.829407
response = self._call( mc_calls.PodcastBrowseHierarchy ) genres = response.body.get('groups', []) return genres
def browse_podcasts_genres(self)
Get the genres from the Podcasts browse tab dropdown. Returns: list: Genre groups that contain sub groups.
15.091697
12.169761
1.240098
response = self._call( mc_calls.BrowseStations, station_category_id ) stations = response.body.get('stations', []) return stations
def browse_stations(self, station_category_id)
Get the stations for a category from Browse Stations. Parameters: station_category_id (str): A station category ID as found with :meth:`browse_stations_categories`. Returns: list: Station dicts.
5.310962
5.649726
0.940039
response = self._call( mc_calls.BrowseStationCategories ) station_categories = response.body.get('root', {}).get('subcategories', []) return station_categories
def browse_stations_categories(self)
Get the categories from Browse Stations. Returns: list: Station categories that can contain subcategories.
7.788645
7.102973
1.096533
response = self._call( mc_calls.Config ) config_list = response.body.get('data', {}).get('entries', []) return config_list
def config(self)
Get a listing of mobile client configuration settings.
9.858028
7.257434
1.358335
if device['id'].startswith('0x'): self.device_id = device['id'][2:] elif device['id'].startswith('ios:'): self.device_id = device['id'].replace(':', '') else: self.device_id = device['id']
def device_set(self, device)
Set device used by :class:`MobileClient` instance. Parameters: device (dict): A device dict as returned by :meth:`devices`.
2.957528
2.757938
1.072369
response = self._call( mc_calls.DeviceManagementInfo ) registered_devices = response.body.get('data', {}).get('items', []) return registered_devices
def devices(self)
Get a listing of devices registered to the Google Music account.
10.769996
8.938294
1.204927
response = self._call( mc_calls.ExploreGenres, parent_genre_id ) genre_list = response.body.get('genres', []) return genre_list
def explore_genres(self, parent_genre_id=None)
Get a listing of song genres. Parameters: parent_genre_id (str, Optional): A genre ID. If given, a listing of this genre's sub-genres is returned. Returns: list: Genre dicts.
5.091036
5.531322
0.920401
response = self._call( mc_calls.ExploreTabs, num_items=num_items, genre_id=genre_id ) tab_list = response.body.get('tabs', []) explore_tabs = {} for tab in tab_list: explore_tabs[tab['tab_type'].lower()] = tab return explore_tabs
def explore_tabs(self, *, num_items=100, genre_id=None)
Get a listing of explore tabs. Parameters: num_items (int, Optional): Number of items per tab to return. Default: ``100`` genre_id (genre_id, Optional): Genre ID from :meth:`explore_genres` to explore. Default: ``None``. Returns: dict: Explore tabs content.
3.346982
3.414561
0.980209
response = self._call( mc_calls.ListenNowGetDismissedItems ) dismissed_items = response.body.get('items', []) return dismissed_items
def listen_now_dismissed_items(self)
Get a listing of items dismissed from Listen Now tab.
6.826358
5.837325
1.169433
response = self._call( mc_calls.ListenNowGetListenNowItems ) listen_now_item_list = response.body.get('listennow_items', []) listen_now_items = defaultdict(list) for item in listen_now_item_list: type_ = f"{ListenNowItemType(item['type']).name}s" listen_now_items[type_].append(item) return di...
def listen_now_items(self)
Get a listing of Listen Now items. Note: This does not include situations; use the :meth:`situations` method instead. Returns: dict: With ``albums`` and ``stations`` keys of listen now items.
3.966595
3.537674
1.121244
playlist_song_info = next( ( playlist_song for playlist in self.playlists(include_songs=True) for playlist_song in playlist['tracks'] if playlist_song['id'] == playlist_song_id ), None ) return playlist_song_info
def playlist_song(self, playlist_song_id)
Get information about a playlist song. Note: This returns the playlist entry information only. For full song metadata, use :meth:`song` with the ``'trackId'`` field. Parameters: playlist_song_id (str): A playlist song ID. Returns: dict: Playlist song information.
2.408598
3.045396
0.790898
prev, next_ = get_ple_prev_next( self.playlist_songs(playlist), after=after, before=before, index=index, position=position ) if 'storeId' in song: song_id = song['storeId'] elif 'trackId' in song: song_id = song['trackId'] else: song_id = song['id'] mutation = mc_calls.Playlist...
def playlist_song_add( self, song, playlist, *, after=None, before=None, index=None, position=None )
Add a song to a playlist. Note: * Provide no optional arguments to add to end. * Provide playlist song dicts for ``after`` and/or ``before``. * Provide a zero-based ``index``. * Provide a one-based ``position``. Songs are inserted *at* given index or position. It's also possible to add to the end ...
3.189549
3.56002
0.895936
playlist_songs = self.playlist_songs(playlist) prev, next_ = get_ple_prev_next( playlist_songs, after=after, before=before, index=index, position=position ) songs_len = len(songs) for i, song in enumerate(songs): if 'storeId' in song: song_id = song['storeId'] elif 'trackId' in ...
def playlist_songs_add( self, songs, playlist, *, after=None, before=None, index=None, position=None )
Add songs to a playlist. Note: * Provide no optional arguments to add to end. * Provide playlist song dicts for ``after`` and/or ``before``. * Provide a zero-based ``index``. * Provide a one-based ``position``. Songs are inserted *at* given index or position. It's also possible to add to the end b...
3.06021
3.328789
0.919316
self.playlist_songs_delete([playlist_song]) return self.playlist(playlist_song['playlistId'], include_songs=True)
def playlist_song_delete(self, playlist_song)
Delete song from playlist. Parameters: playlist_song (str): A playlist song dict. Returns: dict: Playlist dict including songs.
5.686433
6.134212
0.927003
if not more_itertools.all_equal( playlist_song['playlistId'] for playlist_song in playlist_songs ): raise ValueError( "All 'playlist_songs' must be from the same playlist." ) mutations = [mc_calls.PlaylistEntriesBatch.delete(playlist_song['id']) for playlist_song in playlist_songs] self._ca...
def playlist_songs_delete(self, playlist_songs)
Delete songs from playlist. Parameters: playlist_songs (list): A list of playlist song dicts. Returns: dict: Playlist dict including songs.
4.436568
4.406376
1.006852
playlist_songs = self.playlist( playlist_song['playlistId'], include_songs=True )['tracks'] prev, next_ = get_ple_prev_next( playlist_songs, after=after, before=before, index=index, position=position ) mutation = mc_calls.PlaylistEntriesBatch.update( playlist_song, preceding_e...
def playlist_song_move( self, playlist_song, *, after=None, before=None, index=None, position=None )
Move a song in a playlist. Note: * Provide no optional arguments to move to end. * Provide playlist song dicts for ``after`` and/or ``before``. * Provide a zero-based ``index``. * Provide a one-based ``position``. Songs are inserted *at* given index or position. It's also possible to move to the e...
3.311302
3.843991
0.861423
if not more_itertools.all_equal( playlist_song['playlistId'] for playlist_song in playlist_songs ): raise ValueError( "All 'playlist_songs' must be from the same playlist." ) playlist = self.playlist( playlist_songs[0]['playlistId'], include_songs=True ) prev, next_ = get_ple_prev_...
def playlist_songs_move( self, playlist_songs, *, after=None, before=None, index=None, position=None )
Move songs in a playlist. Note: * Provide no optional arguments to move to end. * Provide playlist song dicts for ``after`` and/or ``before``. * Provide a zero-based ``index``. * Provide a one-based ``position``. Songs are inserted *at* given index or position. It's also possible to move to the en...
3.026658
3.11486
0.971683
playlist_type = playlist.get('type') playlist_song_list = [] if playlist_type in ('USER_GENERATED', None): start_token = None playlist_song_list = [] while True: response = self._call( mc_calls.PlaylistEntryFeed, max_results=49995, start_token=start_token ) items = respons...
def playlist_songs(self, playlist)
Get a listing of songs from a playlist. Paramters: playlist (dict): A playlist dict. Returns: list: Playlist song dicts.
2.447482
2.425262
1.009162
playlist_info = next( ( playlist for playlist in self.playlists(include_songs=include_songs) if playlist['id'] == playlist_id ), None ) return playlist_info
def playlist(self, playlist_id, *, include_songs=False)
Get information about a playlist. Parameters: playlist_id (str): A playlist ID. include_songs (bool, Optional): Include songs from the playlist in the returned dict. Default: ``False`` Returns: dict: Playlist information.
2.476412
3.475058
0.712625
share_state = 'PUBLIC' if make_public else 'PRIVATE' playlist = self._call( mc_calls.PlaylistsCreate, name, description, share_state ).body if songs: playlist = self.playlist_songs_add(songs, playlist) return playlist
def playlist_create( self, name, description='', *, make_public=False, songs=None )
Create a playlist. Parameters: name (str): Name to give the playlist. description (str): Description to give the playlist. make_public (bool, Optional): If ``True`` and account has a subscription, make playlist public. Default: ``False`` songs (list, Optional): A list of song dicts to add to the ...
4.188157
6.137904
0.682343
if all( value is None for value in (name, description, public) ): raise ValueError( 'At least one of name, description, or public must be provided' ) playlist_id = playlist['id'] playlist = self.playlist(playlist_id) name = name if name is not None else playlist['name'] description = (...
def playlist_edit(self, playlist, *, name=None, description=None, public=None)
Edit playlist(s). Parameters: playlist (dict): A playlist dict. name (str): Name to give the playlist. description (str, Optional): Description to give the playlist. make_public (bool, Optional): If ``True`` and account has a subscription, make playlist public. Default: ``False`` Returns: d...
2.973779
3.051652
0.974482
mutation = mc_calls.PlaylistBatch.create( playlist['name'], playlist['description'], 'SHARED', owner_name=playlist.get('ownerName', ''), share_token=playlist['shareToken'] ) response_body = self._call( mc_calls.PlaylistBatch, mutation ).body playlist_id = response_body['mutate_respo...
def playlist_subscribe(self, playlist)
Subscribe to a public playlist. Parameters: playlist (dict): A public playlist dict. Returns: dict: Playlist information.
5.409009
5.549558
0.974674
playlist_list = [] for chunk in self.playlists_iter(page_size=49995): for playlist in chunk: if include_songs: playlist['tracks'] = self.playlist_songs(playlist) playlist_list.append(playlist) return playlist_list
def playlists(self, *, include_songs=False)
Get a listing of library playlists. Parameters: include_songs (bool, Optional): Include songs in the returned playlist dicts. Default: ``False``. Returns: list: A list of playlist dicts.
3.386512
3.886386
0.871378
start_token = None while True: response = self._call( mc_calls.PlaylistFeed, max_results=page_size, start_token=start_token ) items = response.body.get('data', {}).get('items', []) if items: yield items start_token = response.body.get('nextPageToken') if start_token is None:...
def playlists_iter(self, *, start_token=None, page_size=250)
Get a paged iterator of library playlists. Parameters: start_token (str): The token of the page to return. Default: Not sent to get first page. page_size (int, Optional): The maximum number of results per returned page. Max allowed is ``49995``. Default: ``250`` Yields: list: Playlist dicts.
3.069045
3.413746
0.899026
podcast_info = self._call( mc_calls.PodcastFetchSeries, podcast_series_id, max_episodes=max_episodes ).body return podcast_info
def podcast(self, podcast_series_id, *, max_episodes=50)
Get information about a podcast series. Parameters: podcast_series_id (str): A podcast series ID. max_episodes (int, Optional): Include up to given number of episodes in returned dict. Default: ``50`` Returns: dict: Podcast series information.
5.977476
8.393706
0.712138
if device_id is None: device_id = self.device_id podcast_list = [] for chunk in self.podcasts_iter(device_id=device_id, page_size=49995): podcast_list.extend(chunk) return podcast_list
def podcasts(self, *, device_id=None)
Get a listing of subsribed podcast series. Paramaters: device_id (str, Optional): A mobile device ID. Default: Use ``device_id`` of the :class:`MobileClient` instance. Returns: list: Podcast series dict.
3.057047
3.087705
0.990071
if device_id is None: device_id = self.device_id start_token = None prev_items = None while True: response = self._call( mc_calls.PodcastSeries, device_id, max_results=page_size, start_token=start_token ) items = response.body.get('data', {}).get('items', []) # Google does ...
def podcasts_iter(self, *, device_id=None, page_size=250)
Get a paged iterator of subscribed podcast series. Parameters: device_id (str, Optional): A mobile device ID. Default: Use ``device_id`` of the :class:`MobileClient` instance. page_size (int, Optional): The maximum number of results per returned page. Max allowed is ``49995``. Default: ``250`` Y...
2.954924
2.845299
1.038528
response = self._call( mc_calls.PodcastFetchEpisode, podcast_episode_id ) podcast_episode_info = [ podcast_episode for podcast_episode in response.body if not podcast_episode['deleted'] ] return podcast_episode_info
def podcast_episode(self, podcast_episode_id)
Get information about a podcast_episode. Parameters: podcast_episode_id (str): A podcast episode ID. Returns: dict: Podcast episode information.
4.166706
4.51454
0.922952
if device_id is None: device_id = self.device_id podcast_episode_list = [] for chunk in self.podcast_episodes_iter( device_id=device_id, page_size=49995 ): podcast_episode_list.extend(chunk) return podcast_episode_list
def podcast_episodes(self, *, device_id=None)
Get a listing of podcast episodes for all subscribed podcasts. Paramaters: device_id (str, Optional): A mobile device ID. Default: Use ``device_id`` of the :class:`MobileClient` instance. Returns: list: Podcast episode dicts.
2.937038
2.913846
1.007959
if device_id is None: device_id = self.device_id start_token = None prev_items = None while True: response = self._call( mc_calls.PodcastEpisode, device_id, max_results=page_size, start_token=start_token ) items = response.body.get('data', {}).get('items', []) # Google does...
def podcast_episodes_iter(self, *, device_id=None, page_size=250)
Get a paged iterator of podcast episode for all subscribed podcasts. Parameters: device_id (str, Optional): A mobile device ID. Default: Use ``device_id`` of the :class:`MobileClient` instance. page_size (int, Optional): The maximum number of results per returned page. Max allowed is ``49995``. Def...
2.943867
2.986096
0.985858
results = defaultdict(list) for type_, results_ in self.search_library( query, max_results=max_results, **kwargs ).items(): results[type_].extend(results_) for type_, results_ in self.search_google( query, max_results=max_results, **kwargs ).items(): results[type_].extend(results...
def search(self, query, *, max_results=100, **kwargs)
Search Google Music and library for content. Parameters: query (str): Search text. max_results (int, Optional): Maximum number of results per type per location to retrieve. I.e up to 100 Google and 100 library for a total of 200 for the default value. Google only accepts values up to 100. Defau...
2.089134
2.051754
1.018219
response = self._call( mc_calls.Query, query, max_results=max_results, **kwargs ) clusters = response.body.get('clusterDetail', []) results = defaultdict(list) for cluster in clusters: result_type = QueryResultType(cluster['cluster']['type']).name entries = cluster.get('entries', []) ...
def search_google(self, query, *, max_results=100, **kwargs)
Search Google Music for content. Parameters: query (str): Search text. max_results (int, Optional): Maximum number of results per type to retrieve. Google only accepts values up to 100. Default: ``100`` kwargs (bool, Optional): Any of ``albums``, ``artists``, ``genres``, ``playlists``, ``podcast...
3.736409
3.607075
1.035856
def match_fields(item, fields): return any( query.casefold() in item.get(field, '').casefold() for field in fields ) types = [ ( 'playlists', ['description', 'name'], self.playlists ), ( 'podcasts', ['author', 'description', 'title'], self.podcasts ), ( ...
def search_library(self, query, *, max_results=100, **kwargs)
Search Google Music for content. Parameters: query (str): Search text. max_results (int, Optional): Maximum number of results per type to retrieve. Default: ``100`` kwargs (bool, Optional): Any of ``playlists``, ``podcasts``, ``songs``, ``stations``, ``videos`` set to ``True`` will include that ...
2.344822
2.165538
1.08279
response = self._call( mc_calls.QuerySuggestion, query ) suggested_queries = response.body.get('suggested_queries', []) return [ suggested_query['suggestion_string'] for suggested_query in suggested_queries ]
def search_suggestion(self, query)
Get search query suggestions for query. Parameters: query (str): Search text. Returns: list: Suggested query strings.
4.742895
4.417585
1.07364
station_info = { 'seed': { 'albumId': album['albumId'], 'seedType': StationSeedType.album.value }, 'num_entries': num_songs, 'library_content_only': only_library, } if recently_played is not None: station_info['recently_played'] = recently_played response = self._call( mc_calls.R...
def shuffle_album( self, album, *, num_songs=100, only_library=False, recently_played=None )
Get a listing of album shuffle/mix songs. Parameters: album (dict): An album dict. num_songs (int, Optional): The maximum number of songs to return from the station. Default: ``100`` only_library (bool, Optional): Only return content from library. Default: False recently_played (list, Optional): ...
3.827746
4.119484
0.929181
station_info = { 'num_entries': num_songs, 'library_content_only': only_library } if only_artist: station_info['seed'] = { 'artistId': artist['artistId'], 'seedType': StationSeedType.artist_only.value } else: station_info['seed'] = { 'artistId': artist['artistId'], 'seedType'...
def shuffle_artist( self, artist, *, num_songs=100, only_library=False, recently_played=None, only_artist=False )
Get a listing of artist shuffle/mix songs. Parameters: artist (dict): An artist dict. num_songs (int, Optional): The maximum number of songs to return from the station. Default: ``100`` only_library (bool, Optional): Only return content from library. Default: False recently_played (list, Optional...
3.004378
3.098546
0.969609
station_info = { 'num_entries': num_songs, 'library_content_only': only_library } if 'storeId' in song: station_info['seed'] = { 'trackId': song['storeId'], 'seedType': StationSeedType.store_track.value } else: station_info['seed'] = { 'trackLockerId': song['id'], 'seedType':...
def shuffle_song( self, song, *, num_songs=100, only_library=False, recently_played=None )
Get a listing of song shuffle/mix songs. Parameters: song (dict): A song dict. num_songs (int, Optional): The maximum number of songs to return from the station. Default: ``100`` only_library (bool, Optional): Only return content from library. Default: False recently_played (list, Optional): A li...
3.501131
3.571386
0.980328
response = self._call( mc_calls.ListenNowSituations, tz_offset ) situation_list = response.body.get('situations', []) return situation_list
def situations(self, *, tz_offset=None)
Get a listing of situations. Parameters: tz_offset (int, Optional): A time zone offset from UTC in seconds.
9.043975
11.135544
0.812172
if song_id.startswith('T'): song_info = self._call( mc_calls.FetchTrack, song_id ).body else: song_info = next( ( song for song in self.songs() if song['id'] == song_id ), None ) return song_info
def song(self, song_id)
Get information about a song. Parameters: song_id (str): A song ID. Returns: dict: Song information.
3.870963
3.725571
1.039025
mutations = [mc_calls.TrackBatch.add(song) for song in songs] response = self._call( mc_calls.TrackBatch, mutations ) success_ids = [ res['id'] for res in response.body['mutate_response'] if res['response_code'] == 'OK' ] return success_ids
def songs_add(self, songs)
Add store songs to your library. Parameters: songs (list): A list of store song dicts. Returns: list: Songs' library IDs.
5.874266
5.456503
1.076562
mutations = [mc_calls.TrackBatch.delete(song['id']) for song in songs] response = self._call( mc_calls.TrackBatch, mutations ) success_ids = [ res['id'] for res in response.body['mutate_response'] if res['response_code'] == 'OK' ] # TODO: Report failures. # failure_ids = [ # res['i...
def songs_delete(self, songs)
Delete songs from library. Parameters: song (list): A list of song dicts. Returns: list: Successfully deleted song IDs.
3.420251
3.301976
1.03582
if 'storeId' in song: song_id = song['storeId'] elif 'trackId' in song: song_id = song['trackId'] else: song_id = song['id'] song_duration = song['durationMillis'] event = mc_calls.ActivityRecordRealtime.play(song_id, song_duration) response = self._call( mc_calls.ActivityRecordRealtime, ...
def song_play(self, song)
Add play to song play count. Parameters: song (dict): A song dict. Returns: bool: ``True`` if successful, ``False`` if not.
4.639574
4.420092
1.049655
if 'storeId' in song: song_id = song['storeId'] elif 'trackId' in song: song_id = song['trackId'] else: song_id = song['id'] event = mc_calls.ActivityRecordRealtime.rate(song_id, rating) response = self._call( mc_calls.ActivityRecordRealtime, event ) return True if response.body['even...
def song_rate(self, song, rating)
Rate song. Parameters: song (dict): A song dict. rating (int): 0 (not rated), 1 (thumbs down), or 5 (thumbs up). Returns: bool: ``True`` if successful, ``False`` if not.
4.659651
4.345735
1.072235
song_list = [] for chunk in self.songs_iter(page_size=49995): song_list.extend(chunk) return song_list
def songs(self)
Get a listing of library songs. Returns: list: Song dicts.
5.478621
5.622259
0.974452
start_token = None while True: response = self._call( mc_calls.TrackFeed, max_results=page_size, start_token=start_token ) items = response.body.get('data', {}).get('items', []) if items: yield items start_token = response.body.get('nextPageToken') if start_token is None: ...
def songs_iter(self, *, page_size=250)
Get a paged iterator of library songs. Parameters: page_size (int, Optional): The maximum number of results per returned page. Max allowed is ``49995``. Default: ``250`` Yields: list: Song dicts.
3.531566
3.721005
0.949089
station_info = { 'station_id': station_id, 'num_entries': num_songs, 'library_content_only': False } if recently_played is not None: station_info['recently_played'] = recently_played response = self._call( mc_calls.RadioStationFeed, station_infos=[station_info] ) station_feed = respo...
def station(self, station_id, *, num_songs=25, recently_played=None)
Get information about a station. Parameters: station_id (str): A station ID. Use 'IFL' for I'm Feeling Lucky. num_songs (int, Optional): The maximum number of songs to return from the station. Default: ``25`` recently_played (list, Optional): A list of dicts in the form of {'id': '', 'type'} where `...
3.366876
3.687335
0.913092
response = self._call( mc_calls.RadioStationFeed, num_entries=num_songs, num_stations=num_stations ) station_feed = response.body.get('data', {}).get('stations', []) return station_feed
def station_feed(self, *, num_songs=25, num_stations=4)
Generate stations. Note: A Google Music subscription is required. Parameters: num_songs (int, Optional): The total number of songs to return. Default: ``25`` num_stations (int, Optional): The number of stations to return when no station_infos is provided. Default: ``5`` Returns: list: Station i...
4.953547
5.148795
0.962079
station_id = station['id'] station = self.station( station_id, num_songs=num_songs, recently_played=recently_played ) return station.get('tracks', [])
def station_songs(self, station, *, num_songs=25, recently_played=None)
Get a listing of songs from a station. Parameters: station (str): A station dict. num_songs (int, Optional): The maximum number of songs to return from the station. Default: ``25`` recently_played (list, Optional): A list of dicts in the form of {'id': '', 'type'} where ``id`` is a song ID and ``type`` ...
3.023885
3.290816
0.918886
station_list = [] for chunk in self.stations_iter(page_size=49995): for station in chunk: if ( (generated and not station.get('inLibrary')) or (library and station.get('inLibrary')) ): station_list.append(station) return station_list
def stations(self, *, generated=True, library=True)
Get a listing of library stations. The listing can contain stations added to the library and generated from the library. Parameters: generated (bool, Optional): Include generated stations. Default: True library (bool, Optional): Include library stations. Default: True Returns: list: Station in...
3.539317
3.95224
0.895522
start_token = None while True: response = self._call( mc_calls.RadioStation, max_results=page_size, start_token=start_token ) yield response.body.get('data', {}).get('items', []) start_token = response.body.get('nextPageToken') if start_token is None: break
def stations_iter(self, *, page_size=250)
Get a paged iterator of library stations. Parameters: page_size (int, Optional): The maximum number of results per returned page. Max allowed is ``49995``. Default: ``250`` Yields: list: Station dicts.
3.965162
4.199515
0.944195
if device_id is None: device_id = self.device_id stream_url = self.stream_url( item, device_id=device_id, quality=quality, session_token=session_token ) response = self.session.get(stream_url) audio = response.content return audio
def stream(self, item, *, device_id=None, quality='hi', session_token=None)
Get MP3 stream of a podcast episode, library song, station_song, or store song. Note: Streaming requires a ``device_id`` from a valid, linked mobile device. Parameters: item (str): A podcast episode, library song, station_song, or store song. A Google Music subscription is required to stream store songs...
2.123631
1.931344
1.099561
if device_id is None: device_id = self.device_id if 'episodeId' in item: # Podcast episode. response = self._call( mc_calls.PodcastEpisodeStreamURL, item['episodeId'], quality=quality, device_id=device_id ) elif 'wentryid' in item: # Free account station song. response = self._c...
def stream_url(self, item, *, device_id=None, quality='hi', session_token=None)
Get a URL to stream a podcast episode, library song, station_song, or store song. Note: Streaming requires a ``device_id`` from a valid, linked mobile device. Parameters: item (str): A podcast episode, library song, station_song, or store song. A Google Music subscription is required to stream store son...
2.553039
2.309386
1.105505
thumbs_up_songs = [] if library is True: thumbs_up_songs.extend( song for song in self.songs() if song.get('rating', '0') == '5' ) if store is True: response = self._call(mc_calls.EphemeralTop) thumbs_up_songs.extend(response.body.get('data', {}).get('items', [])) return thumbs_up...
def thumbs_up_songs(self, *, library=True, store=True)
Get a listing of 'Thumbs Up' store songs. Parameters: library (bool, Optional): Include 'Thumbs Up' songs from library. Default: True generated (bool, Optional): Include 'Thumbs Up' songs from store. Default: True Returns: list: Dicts of 'Thumbs Up' songs.
4.103029
4.354963
0.94215
response = self._call(mc_calls.BrowseTopChart) top_charts = response.body return top_charts
def top_charts(self)
Get a listing of the default top charts.
14.963835
13.655745
1.09579
response = self._call(mc_calls.BrowseTopChartForGenre, genre_id) top_chart_for_genre = response.body return top_chart_for_genre
def top_charts_for_genre(self, genre_id)
Get a listing of top charts for a top chart genre. Parameters: genre_id (str): A top chart genre ID as found with :meth:`top_charts_genres`.
6.605506
9.547132
0.691884
response = self._call(mc_calls.BrowseTopChartGenres) top_chart_genres = response.body.get('genres', []) return top_chart_genres
def top_charts_genres(self)
Get a listing of genres from the browse top charts tab.
8.218795
6.4854
1.267276
payload = decode.decode(stream) sys.stdout.write(payload.decode('utf8'))
def run(stream=sys.stdin.buffer)
Reads from stream, applying the LT decoding algorithm to incoming encoded blocks until sufficiently many blocks have been received to reconstruct the entire file.
9.113885
8.190227
1.112776
f_bytes = f.read() blocks = [int.from_bytes(f_bytes[i:i+blocksize].ljust(blocksize, b'0'), sys.byteorder) for i in range(0, len(f_bytes), blocksize)] return len(f_bytes), blocks
def _split_file(f, blocksize)
Block file byte contents into blocksize chunks, padding last one if necessary
2.955191
2.690976
1.098186
# Generate seed if not provided if seed is None: seed = randint(0, 1 << 31 - 1) # get file blocks filesize, blocks = _split_file(f, blocksize) # init stream vars K = len(blocks) prng = sampler.PRNG(params=(K, delta, c)) prng.set_seed(seed) # block generation loop ...
def encoder(f, blocksize, seed=None, c=sampler.DEFAULT_C, delta=sampler.DEFAULT_DELTA)
Generates an infinite sequence of blocks to transmit to the receiver
6.045417
6.153264
0.982473