Example #1
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
Example #2
0
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
Example #3
0
 def save_song(self, song):
     extension = self._parse_song(song)
     title = song['author'] + '-' + song['title']
     song_pth = os.path.join(self._media_dst_dir,
                             '{}.{}'.format(title, extension))
     pic_pth = os.path.join(self._media_cache_dir, title + '.jpg')
     try:
         if not song.get('url'):
             zlog.warning('song has no url: {}'.format(song))
             return
         song_pth = self._download(song['url'], song_pth)
         if song_pth == '':
             error_hint('failed download song: {}'.format(song_pth),
                        quit_out=None)
             return '', '', ''
         pic_pth = self._download(song['pic'], pic_pth)
         return song, song_pth, pic_pth
     except Exception:
         zlog.error('failed {}'.format(song))
         error_hint('maybe cache expired, use -nc to skip the cache',
                    quit_out=None)
         traceback.print_exc()
         return '', '', ''
Example #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