Searches for lyrics of a single song and returns a Result object with the
    various stats collected in the process.

    The optional parameter 'sources' specifies an alternative list of sources.
    If not present, the main list will be used.
976170
def get_lyrics(song, l_sources=None):
    
    if l_sources is None:
        l_sources = sources

    if song.lyrics and not CONFIG['overwrite']:
        logger.debug('%s already has embedded lyrics', song)
        return None

    runtimes = {}
    source = None
    for l_source in l_sources:
        start = time.time()
        try:
            lyrics = l_source(song)
        except (HTTPError, HTTPException, URLError, ConnectionError):
            lyrics = ''

        runtimes[l_source] = time.time() - start
        if lyrics != '':
            source = l_source
            break

    if lyrics != '':
        logger.info('++ %s: Found lyrics for %s\n', source.__name__, song)
        song.lyrics = lyrics
    else:
        logger.info("Couldn't find lyrics for %s\n", song)
        source = None

    return Result(song, source, runtimes)
1354756
def get_all_lyrics(artist, song, linesep='\n', timeout=None):
    """"""
    url = create_url(artist, song)
    response = _requests.get(url, timeout=timeout)
    soup = _BeautifulSoup(response.content, "html.parser")
    lyricboxes = soup.findAll('div', {'class': 'lyricbox'})

    if not lyricboxes:
        raise LyricsNotFound('Cannot download lyrics')

    for lyricbox in lyricboxes:
        for br in lyricbox.findAll('br'):
            br.replace_with(linesep)

    return [lyricbox.text.strip() for lyricbox in lyricboxes]
869522
def get_lyrics_letssingit(song_name):
    '''
    
    '''

    lyrics = ""
    url = "http://search.letssingit.com/cgi-exe/am.cgi?a=search&artist_id=&l=archive&s=" + \
        quote(song_name.encode('utf-8'))
    html = urlopen(url).read()
    soup = BeautifulSoup(html, "html.parser")
    link = soup.find('a', {'class': 'high_profile'})

    try:
        link = link.get('href')
        link = urlopen(link).read()
        soup = BeautifulSoup(link, "html.parser")

        try:
            lyrics = soup.find('div', {'id': 'lyrics'}).text
            lyrics = lyrics[3:]

        except AttributeError:
            lyrics = ""

    except:
        lyrics = ""

    return lyrics
594603
def songs(options = {page: 1})
      songs_url = "/artists/#{@id}/songs/?page=#{options[:page]}"

      fetch(songs_url)["response"]["songs"].map do |song|
        Song.new(
          artist: Artist.new(
            name: song["primary_artist"]["name"],
            id: song["primary_artist"]["id"],
            type: :primary
          ),
          title: song["title"],
          id: song["id"]
        )
      end
    end
857531
def download_song_by_id(self, song_id, song_name, folder='.'):
        

        try:
            url = self.crawler.get_song_url(song_id)
            if self.lyric:
                # use old api
                lyric_info = self.crawler.get_song_lyric(song_id)
            else:
                lyric_info = None
            song_name = song_name.replace('/', '')
            song_name = song_name.replace('.', '')
            self.crawler.get_song_by_url(url, song_name, folder, lyric_info)
        except RequestException as exception:
            click.echo(exception)
1073035
def lyric(id):
    
    if id is None:
        raise ParamsError()
    r = NCloudBot()
    r.method = 'LYRIC'
    r.params = {'id': id}
    r.send()

    return r.response
382167
def get_lyrics_threaded(song, l_sources=None):
    
    if l_sources is None:
        l_sources = sources

    if song.lyrics and not CONFIG['overwrite']:
        logger.debug('%s already has embedded lyrics', song)
        return None

    runtimes = {}
    queue = Queue()
    pool = [LyrThread(source, song, queue) for source in l_sources]
    for thread in pool:
        thread.start()

    for _ in range(len(pool)):
        result = queue.get()
        runtimes[result['source']] = result['runtime']
        if result['lyrics']:
            break

    if result['lyrics']:
        song.lyrics = result['lyrics']
        source = result['source']
    else:
        source = None

    return Result(song, source, runtimes)
912161
def process_hive(vargs):
    

    artist_url = vargs['artist_url']

    if 'hive.co' in artist_url:
        mc_url = artist_url
    else:
        mc_url = 'https://www.hive.co/downloads/download/' + artist_url

    filenames = scrape_hive_url(mc_url, num_tracks=vargs['num_tracks'], folders=vargs['folders'], custom_path=vargs['path'])

    if vargs['open']:
        open_files(filenames)

    return
590140
def lyricsmode(song):
    
    translate = {
        URLESCAPE: '',
        ' ': '_'
    }
    artist = song.artist.lower()
    artist = normalize(artist, translate)
    title = song.title.lower()
    title = normalize(title, translate)

    artist = re.sub(r'\_{2,}', '_', artist)
    title = re.sub(r'\_{2,}', '_', title)

    if artist[0:4].lower() == 'the ':
        artist = artist[4:]

    if artist[0:2].lower() == 'a ':
        prefix = artist[2]
    else:
        prefix = artist[0]

    url = 'http://www.lyricsmode.com/lyrics/{}/{}/{}.html'
    url = url.format(prefix, artist, title)
    soup = get_url(url)
    content = soup.find(id='lyrics_text')

    return content.get_text().strip()
985368
def get_first_song(self):
        
        count = 3
        while count > 0:
            song = self.requests_url('n')
            if song:
                return song
            count -= 1
            time.sleep(2)
        raise GenericError('获取第一首歌曲失败，无法完成初始化')
242172
def get_lyrics_genius(song_title):
    '''
    
    '''
    base_url = "http://api.genius.com"
    headers = {'Authorization': 'Bearer %s' %(GENIUS_KEY)}
    search_url = base_url + "/search"
    data = {'q': song_title}

    response = requests.get(search_url, data=data, headers=headers)
    json = response.json()
    song_api_path = json["response"]["hits"][0]["result"]["api_path"]

    song_url = base_url + song_api_path
    response = requests.get(song_url, headers=headers)
    json = response.json()
    path = json["response"]["song"]["path"]
    page_url = "http://genius.com" + path

    page = requests.get(page_url)
    soup = BeautifulSoup(page.text, "html.parser")
    div = soup.find('div',{'class': 'song_body-lyrics'})
    lyrics = div.find('p').getText()
  
    return lyrics
876607
def _find_playlist(self):
        
        data = None
        if self.id:
            data = self.connection.get_item(
                'find_playlist_by_id', playlist_id=self.id)
        elif self.reference_id:
            data = self.connection.get_item(
                'find_playlist_by_reference_id',
                reference_id=self.reference_id)

        if data:
            self._load(data)
301494
def azlyrics(song):
    
    artist = song.artist.lower()
    if artist[0:2] == 'a ':
        artist = artist[2:]
    artist = normalize(artist, URLESCAPES, '')
    title = song.title.lower()
    title = normalize(title, URLESCAPES, '')

    url = 'https://www.azlyrics.com/lyrics/{}/{}.html'.format(artist, title)
    soup = get_url(url)
    body = soup.find_all('div', class_='')[-1]
    return body.get_text().strip()
1236734
async def source(dev: Device, scheme):
    
    if scheme is None:
        schemes = await dev.get_schemes()
        schemes = [scheme.scheme for scheme in schemes]  # noqa: T484
    else:
        schemes = [scheme]

    for schema in schemes:
        try:
            sources = await dev.get_source_list(schema)
        except SongpalException as ex:
            click.echo("Unable to get sources for %s" % schema)
            continue
        for src in sources:
            click.echo(src)
            if src.isBrowsable:
                try:
                    count = await dev.get_content_count(src.source)
                    if count.count > 0:
                        click.echo("  %s" % count)
                        for content in await dev.get_contents(src.source):
                            click.echo("   %s\n\t%s" % (content.title, content.uri))
                    else:
                        click.echo("  No content to list.")
                except SongpalException as ex:
                    click.echo("  %s" % ex)
111856
def songs(self):
        
        if self._songs is None:
            self._songs = [Song.from_response(song, self._connection) for song in
                           self._connection.request(
                               'artistGetArtistSongs',
                               {'artistID': self.id},
                               self._connection.header('artistGetArtistSongs'))[1]]
        return iter(self._songs)
505877
def get_genres(self, *args, **kwargs):
        
        args = tuple(['genres'] + list(args))
        return self.get_music_library_information(*args, **kwargs)
1004691
async def songs(self):
    '''
    '''
    items = []
    for i in await self.items:
      if i.type == 'Audio':
        items.append(i)
      elif hasattr(i, 'songs'):
        items.extend(await i.songs)
    return items