Download a song by name or id.
971615
def song(netease, name, id):
    """"""
    if name:
        netease.download_song_by_search(name)

    if id:
        netease.download_song_by_id(id, 'song'+str(id))
858940
function play(name) {
        if (name === 'list') {
            return Object.keys(audio);
        }
        if (!(name in audio)) {
            d.error("Invalid audio name:", name);
            return;
        }

        audio[name].play();
    }
353436
def download_track(track, album_name=u'', keep_previews=False, folders=False, filenames=[], custom_path=''):
    

    hard_track_url = get_hard_track_url(track['id'])

    # We have no info on this track whatsoever.
    if not 'title' in track:
        return None

    if not keep_previews:
        if (track.get('duration', 0) < track.get('full_duration', 0)):
            puts_safe(colored.yellow("Skipping preview track") + colored.white(": " + track['title']))
            return None

    # May not have a "full name"
    name = track['user'].get('full_name', '')
    if name == '':
        name = track['user']['username']

    filename = sanitize_filename(name + ' - ' + track['title'] + '.mp3')

    if folders:
        name_path = join(custom_path, name)
        if not exists(name_path):
            mkdir(name_path)
        filename = join(name_path, filename)
    else:
        filename = join(custom_path, filename)

    if exists(filename):
        puts_safe(colored.yellow("Track already downloaded: ") + colored.white(track['title']))
        return None

    # Skip already downloaded track.
    if filename in filenames:
        return None

    if hard_track_url:
        puts_safe(colored.green("Scraping") + colored.white(": " + track['title']))
    else:
        # Region coded?
        puts_safe(colored.yellow("Unable to download") + colored.white(": " + track['title']))
        return None

    filename = download_file(hard_track_url, filename)
    tagged = tag_file(filename,
             artist=name,
             title=track['title'],
             year=track['created_at'][:4],
             genre=track['genre'],
             album=album_name,
             artwork_url=track['artwork_url'])
    if not tagged:
        wav_filename = filename[:-3] + 'wav'
        os.rename(filename, wav_filename)
        filename = wav_filename

    return filename
943780
def get(self):
        """"""
        method_name = "_download_" + self.name
        method = getattr(self, method_name)
        return method()
200276
def download_playlist_by_id(self, playlist_id, playlist_name):
        

        try:
            songs = self.crawler.get_playlist_songs(
                playlist_id)
        except RequestException as exception:
            click.echo(exception)
        else:
            folder = os.path.join(self.folder, playlist_name)
            for song in songs:
                self.download_song_by_id(song.song_id, song.song_name, folder)
1090276
def str_id(self):
        ""
        id_or_name = self.id_or_name
        if id_or_name is not None and isinstance(id_or_name, str):
            return id_or_name
        return None
627845
def trackSeek(path, artist, album, track, trackNum, fmt):
    """"""
    hiddenName = "(Hidden Track).{}".format(fmt)
    trackName = track + ".{}".format(fmt)
    songIn = instantiateSong(path)
    times = findGap(songIn)
    saveFiles(trackName, hiddenName, splitSong(songIn, times[0], times[1]), artist, album, trackNum)
    # return [path, track.rsplit('/',1)[0] +'/{}'.format(hiddenName)]
    return [trackName, hiddenName]
508400
def get_artist(self, id_):
        """"""
        endpoint = "artists/{id}".format(id=id_)
        return self._make_request(endpoint)
262589
def name(self):
        """"""
        instr_name = self.song.song_data.instrument_names[self.index]

        if type(instr_name) == bytes:
            instr_name = instr_name.decode('utf-8')

        return instr_name
34762
def download_file(file_id, file_name):
    ''''''
    extracted_out_dir = os.path.join(app.config['UPLOAD_FOLDER'], file_id)
    return send_file(os.path.join(extracted_out_dir, file_name))
622894
def download(self):
        
        mp3_directory = self._pre_download()
        self.data.swifter.apply(func=lambda arg: self._download(*arg, mp3_directory), axis=1, raw=True)
        return mp3_directory
1073420
def album(netease, name, id):
    """"""
    if name:
        netease.download_album_by_search(name)

    if id:
        netease.download_album_by_id(id, 'album'+str(id))
896371
def download_user_playlists_by_id(self, user_id):
        

        try:
            playlist = self.crawler.get_user_playlists(user_id)
        except RequestException as exception:
            click.echo(exception)
        else:
            self.download_playlist_by_id(
                playlist.playlist_id, playlist.playlist_name)
1164750
def download(self, directory='~/Music', song_name='%a - %s - %A'):
        
        formatted = self.format(song_name)
        path = os.path.expanduser(directory) + os.path.sep + formatted + '.mp3'
        try:
            raw = self.safe_download()
            with open(path, 'wb') as f:
                f.write(raw)
        except:
            raise
        return formatted
1132705
def download_playlist_by_search(self, playlist_name):
        

        try:
            playlist = self.crawler.search_playlist(
                playlist_name, self.quiet)
        except RequestException as exception:
            click.echo(exception)
        else:
            self.download_playlist_by_id(
                playlist.playlist_id, playlist.playlist_name)
886982
def download(self, id, attid): # pylint: disable=invalid-name,redefined-builtin
        
        resp = self.service.get_id(self._base(id), attid, params={'format': 'download'}, stream=True)
        b = io.BytesIO()
        stream.stream_response_to_file(resp, path=b)
        resp.close()
        b.seek(0)
        return (b, self.service.filename(resp))
1278741
def get_audio_metadata(fname):
    
    from mutagenx.easyid3 import EasyID3
    audio = EasyID3(fname)
    audio_dict = {}
    
    try:
        artist = audio["artist"]
    except KeyError:
        artist = ''
        
    try:    
        title = audio["title"]
    except KeyError:
        print("Cant get title")
        
    try:
        album = audio["album"]
    except KeyError:
        album = ''
        
    
    audio_dict['album'] = album
    audio_dict['title'] = title
    audio_dict['artist'] = artist
    
    return audio_dict