Beispiel #1
0
def from_url(xm_obj, url, verbose=True):
    """ parse the input string (xiami url), and do download"""

    LOG.debug('processing url: "%s"' % url)
    msg = u''
    if '/showcollect/id/' in url:
        collect = xm.Collection(xm_obj, url)
        dl_songs.extend(collect.songs)
        msgs = [
            fmt_parsing %
            (xiami_url_abbr(url), u'精选集', collect.collection_name)
        ]
        if verbose:
            for s in collect.songs:
                msgs.append(fmt_single_song % s.song_name)
            msg = u'\n    |-> '.join(msgs)
        else:
            msgs.append(fmt_has_song_nm % len(collect.songs))
            msg = u' => '.join(msgs)

    elif '/song/' in url:
        song = xm.Song(xm_obj, url=url)
        dl_songs.append(song)
        msg = fmt_parsing % (xiami_url_abbr(url), u'曲目', song.song_name)
    elif '/album/' in url:
        album = xm.Album(xm_obj, url)
        dl_songs.extend(album.songs)
        msgs = [
            fmt_parsing % (xiami_url_abbr(url), u'专辑',
                           album.artist_name + u' => ' + album.album_name)
        ]
        if verbose:
            for s in album.songs:
                msgs.append(fmt_single_song % s.song_name)
            msg = u'\n    |-> '.join(msgs)
        else:
            msgs.append(fmt_has_song_nm % len(album.songs))
            msg = u' => '.join(msgs)

    elif '/lib-song/u/' in url:
        fav = xm.Favorite(xm_obj, url)
        dl_songs.extend(fav.songs)
        msgs = [fmt_parsing % (xiami_url_abbr(url), u'用户收藏', '')]
        if verbose:
            for s in fav.songs:
                msgs.append(fmt_single_song % s.song_name)
            msg = u'\n    |-> '.join(msgs)
        else:
            msgs.append(fmt_has_song_nm % len(fav.songs))
            msg = u' => '.join(msgs)

    global total, done
    done += 1
    pre = ('[%d/%d] ' % (done, total)) if not verbose else ''
    if not msg:
        #unknown url
        LOG.error(u'%s 不能识别的url [%s].' % (pre, url))
    else:
        LOG.info(u'%s%s' % (pre, msg))
Beispiel #2
0
def from_url_xm(xm_obj, url, verbose=True):
    """ parse the input string (xiami url), and do download"""

    LOG.debug('processing xiami url: "%s"'% url)
    msg = u''
    if '/collect/' in url:
        collect = xm.Collection(xm_obj, url)
        total_songs.extend(collect.songs)
        msgs = [ fmt_parsing % (xiami_url_abbr(url), msgTxt.collection ,collect.collection_name)]
        if verbose:
            for s in collect.songs:
                msgs.append( fmt_single_song % s.song_name)
            msg = u'\n    |-> '.join(msgs)
        else:
            msgs.append(fmt_has_song_nm % len(collect.songs))
            msg= u' => '.join(msgs)

    elif '/song/' in url:
        song = xm.XiamiSong(xm_obj, url=url)
        total_songs.append(song)
        msg = fmt_parsing % (xiami_url_abbr(url),msgTxt.song,  song.song_name)
    elif '/album/' in url:
        album = xm.Album(xm_obj, url)
        total_songs.extend(album.songs)
        msgs = [fmt_parsing % (xiami_url_abbr(url),msgTxt.album,  album.artist_name+u' => '+album.album_name)]
        if verbose:
            for s in album.songs:
                msgs.append(fmt_single_song %s.song_name)
            msg = u'\n    |-> '.join(msgs)
        else:
            msgs.append(fmt_has_song_nm % len(album.songs))
            msg= u' => '.join(msgs)

    elif '/lib-song/u/' in url:
        if verbose:
            LOG.warning(msgTxt.warning_many_collections)

        fav = xm.Favorite(xm_obj, url, verbose)
        total_songs.extend(fav.songs)
        msgs = [fmt_parsing % (xiami_url_abbr(url), msgTxt.Favorite ,'')]
        if verbose:
            for s in fav.songs:
                msgs.append(fmt_single_song %s.song_name)
            msg = u'\n    |-> '.join(msgs)
        else:
            msgs.append( fmt_has_song_nm % len(fav.songs))
            msg = u' => '.join(msgs)
    elif re.search(r'/artist/', url):
        topsong=xm.TopSong(xm_obj, url)
        total_songs.extend(topsong.songs)
        msgs = [fmt_parsing % (xiami_url_abbr(url), msgTxt.artistTop,topsong.artist_name)]
        if verbose:
            for s in topsong.songs:
                msgs.append(fmt_single_song %s.song_name)
            msg = u'\n    |-> '.join(msgs)
        else:
            msgs.append( fmt_has_song_nm % len(topsong.songs))
            msg = u' => '.join(msgs)
        

    global total, done
    done +=1
    pre = ('[%d/%d] ' % (done, total)) if not verbose else ''
    if not msg:
        #unknown url
        LOG.error(msgTxt.fmt_xm_unknown_url % (pre,url))
    else:
        LOG.info(u'%s%s'% (pre,msg))