本文整理汇总了Python中musicbrainzngs.set_rate_limit函数的典型用法代码示例。如果您正苦于以下问题:Python set_rate_limit函数的具体用法?Python set_rate_limit怎么用?Python set_rate_limit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了set_rate_limit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self):
log = logging.getLogger('util.importer.Importer.__init__')
musicbrainzngs.set_useragent("NRG Processor", "0.01", "http://anorg.net/")
musicbrainzngs.set_rate_limit(MUSICBRAINZ_RATE_LIMIT)
if MUSICBRAINZ_HOST:
musicbrainzngs.set_hostname(MUSICBRAINZ_HOST)
示例2: configure
def configure():
"""Set up the python-musicbrainz-ngs module according to settings
from the beets configuration. This should be called at startup.
"""
musicbrainzngs.set_hostname(config["musicbrainz"]["host"].get(unicode))
musicbrainzngs.set_rate_limit(
config["musicbrainz"]["ratelimit_interval"].as_number(), config["musicbrainz"]["ratelimit"].get(int)
)
示例3: __init__
def __init__(self):
musicbrainzngs.set_useragent("NRG Processor", "0.01", "http://anorg.net/")
musicbrainzngs.set_rate_limit(MUSICBRAINZ_RATE_LIMIT)
self.file_metadata = None
if MUSICBRAINZ_HOST:
musicbrainzngs.set_hostname(MUSICBRAINZ_HOST)
示例4: turn_off_musicbrainz_rate_limiting_if_cassette_exists
def turn_off_musicbrainz_rate_limiting_if_cassette_exists(cassette_name):
# if cassettes exist, turn off rate limiting
cassette = os.path.join(CASSETTE_LIBRARY_DIR, cassette_name)
if os.path.exists(cassette):
logger.info('Cassettes directory existsing, turning off rate-limiting')
musicbrainzngs.set_rate_limit(False)
else:
musicbrainzngs.set_rate_limit()
logger.warn("Couldn't find cassettes, going to hit real musicbrainz API")
示例5: configure
def configure():
"""Set up the python-musicbrainz-ngs module according to settings
from the beets configuration. This should be called at startup.
"""
hostname = config['musicbrainz']['host'].as_str()
musicbrainzngs.set_hostname(hostname)
musicbrainzngs.set_rate_limit(
config['musicbrainz']['ratelimit_interval'].as_number(),
config['musicbrainz']['ratelimit'].get(int),
)
示例6: setUp
def setUp(self):
musicbrainzngs.set_rate_limit(3, 3)
self.cop = Timecop()
self.cop.install()
@musicbrainz._rate_limit
def limited():
pass
self.func = limited
示例7: __init__
def __init__(self):
musicbrainzngs.set_useragent("NRG Processor", "0.01", "http://anorg.net/")
musicbrainzngs.set_rate_limit(MUSICBRAINZ_RATE_LIMIT)
self.pp = pprint.PrettyPrinter(indent=4)
self.pp.pprint = lambda d: None
if MUSICBRAINZ_HOST:
musicbrainzngs.set_hostname(MUSICBRAINZ_HOST)
示例8: test_invalid_args
def test_invalid_args(self):
""" Passing invalid arguments to set_rate_limit should throw
an exception """
try:
musicbrainzngs.set_rate_limit(1, 0)
self.fail("Required exception wasn't raised")
except ValueError as e:
self.assertTrue("new_requests" in str(e))
try:
musicbrainzngs.set_rate_limit(0, 1)
self.fail("Required exception wasn't raised")
except ValueError as e:
self.assertTrue("limit_or_interval" in str(e))
try:
musicbrainzngs.set_rate_limit(1, -1)
self.fail("Required exception wasn't raised")
except ValueError as e:
self.assertTrue("new_requests" in str(e))
try:
musicbrainzngs.set_rate_limit(0, -1)
self.fail("Required exception wasn't raised")
except ValueError as e:
self.assertTrue("limit_or_interval" in str(e))
示例9: startmb
def startmb():
mbuser = None
mbpass = None
if headphones.CONFIG.MIRROR == "musicbrainz.org":
mbhost = "musicbrainz.org"
mbport = 80
sleepytime = 1
elif headphones.CONFIG.MIRROR == "custom":
mbhost = headphones.CONFIG.CUSTOMHOST
mbport = int(headphones.CONFIG.CUSTOMPORT)
mbuser = headphones.CONFIG.CUSTOMUSER
mbpass = headphones.CONFIG.CUSTOMPASS
sleepytime = int(headphones.CONFIG.CUSTOMSLEEP)
elif headphones.CONFIG.MIRROR == "headphones":
mbhost = "musicbrainz.codeshy.com"
mbport = 80
mbuser = headphones.CONFIG.HPUSER
mbpass = headphones.CONFIG.HPPASS
sleepytime = 0
else:
return False
musicbrainzngs.set_useragent("headphones", "0.0", "https://github.com/rembo10/headphones")
musicbrainzngs.set_hostname(mbhost + ":" + str(mbport))
# Their rate limiting should be redundant to our lock
if sleepytime == 0:
musicbrainzngs.set_rate_limit(False)
else:
# calling it with an it ends up blocking all requests after the first
musicbrainzngs.set_rate_limit(limit_or_interval=float(sleepytime))
mb_lock.minimum_delta = sleepytime
# Add headphones credentials
if headphones.CONFIG.MIRROR == "headphones" or headphones.CONFIG.CUSTOMAUTH:
if not mbuser or not mbpass:
logger.warn("No username or password set for MusicBrainz server")
else:
musicbrainzngs.hpauth(mbuser, mbpass)
# Let us know if we disable custom authentication
if not headphones.CONFIG.CUSTOMAUTH and headphones.CONFIG.MIRROR == "custom":
musicbrainzngs.disable_hpauth()
logger.debug(
"Using the following server values: MBHost: %s, MBPort: %i, Sleep Interval: %i", mbhost, mbport, sleepytime
)
return True
示例10: main
def main():
parser = IrankOptionParser()
parser.add_option('--threshold', default=5, type='int', help='include only artists with at least THRESHOLD files in collection')
parser.add_option('--target', type='int', help='update only TARGET artists and then exit')
parser.add_option('--max-age', metavar='DAYS', type='int', help='if --target is given, also update all artists which haven\'t been updated in DAYS days')
parser.add_option('--min-age', metavar='DAYS', type='int', help='if --target is given, ignore artists which have been checked within DAYS days')
parser.add_option('--update-only', help='don\'t print RSS feed', action='store_true')
parser.add_option('--full', help='wipe existing DB', action='store_true')
parser.add_option('--quick', help='don\'t update DB if it already exists', action='store_true')
options, args = parser.parse_args()
logging.basicConfig(level=logging.DEBUG if options.verbose else logging.WARN)
app = IrankApp(options)
mb_path = os.path.join(app.base_path, 'musicbrainz.sqlite')
if options.full:
try:
os.unlink(mb_path)
except OSError as e:
if e.errno != errno.ENOENT: raise
existing = os.path.exists(mb_path)
mbdb = (load_db if existing else init_db)(mb_path)
version = irank.version()
mb.set_useragent("irank", version, "https://github.com/gfxmonk/python-irank")
logging.debug("setting rate limit to 2/s")
mb.set_rate_limit(new_requests = 2)
try:
if not (existing and options.quick):
db = irank_db.load(app.db_path)
populate_db(mbdb, options, db)
db.close()
if not options.update_only:
releases = mbdb.execute('''select
artist, title, date
from releases
order by date desc
limit 100''')
doc = make_feed(releases)
print(doc.toprettyxml())
finally:
mbdb.close()
示例11: startmb
def startmb():
mbuser = None
mbpass = None
if headphones.MIRROR == "musicbrainz.org":
mbhost = "musicbrainz.org"
mbport = 80
sleepytime = 1
elif headphones.MIRROR == "custom":
mbhost = headphones.CUSTOMHOST
mbport = int(headphones.CUSTOMPORT)
sleepytime = int(headphones.CUSTOMSLEEP)
elif headphones.MIRROR == "headphones":
mbhost = "144.76.94.239"
mbport = 8181
mbuser = headphones.HPUSER
mbpass = headphones.HPPASS
sleepytime = 0
else:
return False
musicbrainzngs.set_useragent("headphones","0.0","https://github.com/rembo10/headphones")
musicbrainzngs.set_hostname(mbhost + ":" + str(mbport))
if sleepytime == 0:
musicbrainzngs.set_rate_limit(False)
else:
#calling it with an it ends up blocking all requests after the first
musicbrainzngs.set_rate_limit(limit_or_interval=float(sleepytime))
# Add headphones credentials
if headphones.MIRROR == "headphones":
if not mbuser and mbpass:
logger.warn("No username or password set for VIP server")
else:
musicbrainzngs.hpauth(mbuser,mbpass)
logger.debug('Using the following server values: MBHost: %s, MBPort: %i, Sleep Interval: %i', mbhost, mbport, sleepytime)
return True
示例12: find_releases
import mutagen
from mutagen.easyid3 import EasyID3
from mutagen.easymp4 import EasyMP4
from mutagen.oggvorbis import OggVorbis
from mutagen.flac import FLAC
from optparse import OptionParser
import os
import smtplib
import urllib
musicbrainzngs.set_useragent(
"new_music_finder.py",
"0.2",
"https://joetotaro.net",
)
musicbrainzngs.set_rate_limit(limit_or_interval=1.0, new_requests=1)
FORMAT = '%(asctime)s %(levelname)s %(funcName)s:%(lineno)d %(message)s'
def find_releases(artists_set, year_month):
good = u""
questionable = u""
for artist in artists_set:
result = musicbrainzngs.search_releases(
query=u"artist:\"{}\" AND date:{}-?? AND status:official AND primarytype:album".format(artist, year_month))
if not result['release-list']:
Logger.debug("no release found for artist %s", artist)
music_brains_links = u""
示例13: get_symbtrmu2
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see http://www.gnu.org/licenses/
import urllib2
import urllib
import json
import cookielib
import re
import sys
import compmusic
import musicbrainzngs as mb
mb.set_useragent("Dunya", "0.1")
mb.set_rate_limit(True)
mb.set_hostname("musicbrainz.org")
domain = "https://musicbrainz.org"
password = '####'
username = '####'
login_url = '/login'
work_url = '/work/%s/edit'
auth_token = "###"
symbtrmu2_url = 'http://dunya.compmusic.upf.edu/document/by-id/%s/symbtrmu2'
dunya_fuzzy_url = 'http://dunya.compmusic.upf.edu/api/makam/fuzzy'
mb_cache = {}
def get_symbtrmu2(work_mbid):
示例14: Stats
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see http://www.gnu.org/licenses/
import sys
import os
import argparse
import collections
import compmusic.file
import compmusic.musicbrainz
import musicbrainzngs as mb
mb.set_useragent("Dunya", "0.1")
mb.set_rate_limit(False)
mb.set_hostname("sitar.s.upf.edu:8090")
import eyed3
import logging
eyed3.utils.log.log.setLevel(logging.ERROR)
class Stats(object):
# How many recordings are done for each work
# key is workid
work_recording_counts = collections.Counter()
# artists. could be artists of the release, or as release
# rels, or as track rels
artists = set()
示例15: set_up_musicbrainzngs
def set_up_musicbrainzngs( user_agent_app, user_agent_version ):
"""
Call this before running `mp3_tag_fixer.py`
"""
musicbrainzngs.set_useragent( user_agent_app, user_agent_version )
musicbrainzngs.set_rate_limit( limit_or_interval=1.0, new_requests=1 )