Beispiel #1
0
def check_local(scan_mode, client, name):
    """judge if found from local, only press ``s`` will go next"""
    if scan_mode:
        return False

    client.scan_all_songs()
    cache = client.is_file_exist(name)
    if cache:
        CP.G('Found from local, still want search and download???')
        CP.R('press s to skip local, and re-download, or other key to exit')
        c = helper.num_choice(
            cache, default='q', valid_keys='s',
            extra_hints='s-skip',
        )
        return c != 's'
Beispiel #2
0
def check_failure(failure_songs):
    if not failure_songs:
        return []
    scanned_songs = []
    dat = FailureHandle().load_failure_songs()
    if not dat:
        error_hint('{0}>>> no failed songs <<<{0}'.format('' * 16), bg='green')
    for i, s in enumerate(dat):
        CP.Y('{}. {}'.format(i + 1, s))
        scanned_songs.append(s)
    ch = click.confirm(ipretty.C.format('do you want continue with downloading all failure songs...'), default=True)
    if not ch:
        os._exit(0)
    return scanned_songs
def check_neteasemusic_playing():
    choice = False
    song = get_playing_netease_music()
    if not song:
        error_hint(
            '{0}>>> some error happened, contact author for help <<<{0}'.
            format('' * 16))

    song_info = '{}-{}'.format(song['author'], song['title'])
    CP.G('current playing:  {}'.format(
        helper.Y.format('{}({}M/{}bits)'.format(
            song_info, round(int(song['fileSize']) / (1024.0 * 1024.0), 2),
            song['bitrate']))))
    scanned_songs = [song_info]
    if int(song['bitrate']) >= HIGH_Q:
        # if bitrate >= 320, we will force use it
        choice = click.confirm(helper.C.format(
            'high quality song got, force use NeteaseMusic/163 Source ?'),
                               default=True)
    return choice, scanned_songs
Beispiel #4
0
def run(
    name,
    site,
    multiple,
    no_cache,
    log_level,
    scan_mode,
    timeout,
    override,
    auto_mode,
    failure_songs,
    clear_failure_songs,
    from_163_logs,
):
    """ a lovely script use sonimei search qq/netease songs """
    # if scan_mode, will be all songs local
    # else will be the name passed in
    scanned_songs = []
    timeout = timeout or cfg.get('snm.timeout')
    force_netease = False
    if clear_failure_songs:
        FailureHandle().dump_failure_songs([], action='clear')
        os._exit(0)

    if auto_mode:
        force_netease, scanned_songs = check_player(auto_mode)

    if failure_songs:
        scanned_songs = check_failure(failure_songs)

    if from_163_logs:
        force_netease = from_163_logs

    if force_netease:
        _client = NeteaseDL(not no_cache,
                            log_level=log_level * 10,
                            timeout=timeout,
                            override=override)
    else:
        _client = Sonimei(site,
                          not no_cache,
                          log_level=log_level * 10,
                          timeout=timeout,
                          override=override)

    if scan_mode:
        _client.store.scan_all_songs()
        scanned_songs = _client.store.all_songs

    if name:
        scanned_songs = [x for x in name.split('#') if x]

    if not scanned_songs:
        error_hint('{0}>>> use -h for details <<<{0}'.format('' * 16),
                   quit_out=None)

    for i, name in enumerate(scanned_songs):
        songs_store = {}
        page = 1
        is_searched_from_site = False
        CP.F((PRETTY.symbols['right'] + ' ') * 2,
             'processing/total: {}/{}'.format(i + 1, len(scanned_songs)))

        while True:
            if not is_searched_from_site and check_local(
                    scan_mode, _client.store, name):
                CP.G(PRETTY.symbols['end'], 'quit')
                break

            status, song_pth = _client.store.is_file_id3_ok(name)
            if status:
                CP.G(PRETTY.symbols['music'],
                     '[{}] is found and updated'.format(song_pth))
                if not override:
                    error_hint('>>> you can do force download with -o <<<',
                               empty_line=False,
                               bg='black',
                               fg='yellow')
                    break

            songs = songs_store.get(page)
            if not songs:
                zlog.info('from sonimei({}) try: {}/{}'.format(
                    ipretty.G.format(site), name, page))
                songs = _client.search_it(name, page=page)
                if not isinstance(songs, list):
                    songs = [songs]
                songs_store[page] = songs

            is_searched_from_site = True
            song_info = [x['author'] + '-' + x['title'] for x in songs]

            c = helper.num_choice(
                song_info,
                valid_keys='p,n,s',
                depth=page,
                extra_hints='n-next,p-pre,s-skip',
                clear_previous=True,
            )
            if isinstance(c, str):
                if c in 'qQ':
                    return
                if c in 'bp':
                    if page > 1:
                        page -= 1
                    continue
                if c == 'n':
                    page += 1
                    continue
                if c == 's':  # skip current song
                    break
            _client.save_song(songs[c])

            # multiple mode is only worked in none scanned mode
            if not multiple:
                break
def check_spotify_playing():
    st = SpotifyTrack()
    CP.G('current playing  : [{}]'.format(
        helper.Y.format('{artist} - {name}'.format(**st.track))))
    if st.track:
        return False, ['{artist} - {name}'.format(**st.track)]