Example #1
0
    def spls(self):
        from NXSpider.bin.models import playlist_mo

        if self.param_check(['playlist'],
                            sys._getframe().f_code.co_name) is False:
            return

        download_type = self.parse_download()
        playlists = self.app.pargs.playlist.split(',')  # type: list

        for pid in playlists:
            playlist_detail = api.get_playlist_detail(pid)
            if playlist_detail:
                log.print_info(u"<{}> author:{}".format(
                    playlist_detail['name'],
                    playlist_detail['creator']['nickname'],
                ))
                playlist_mo.parse_model(
                    playlist_detail,
                    download_type=download_type,
                    file_check=Config().get_file_check(),
                    shortcuts_stack=[] if Config().get_shortcut() else None)

        log.print_info("spider complete!~")
        pass
Example #2
0
    def sur_pls(self):
        from NXSpider.bin.models import playlist_mo

        if self.param_check(['user'], sys._getframe().f_code.co_name) is False:
            return

        download_type = self.parse_download()
        user_id = self.app.pargs.user
        playlists = api.user_playlist(user_id,
                                      offset=self.app.pargs.offset or 0,
                                      limit=self.app.pargs.limit or 50)

        log.print_info("playlists bellow will be crawled")
        print_playlist(playlists)

        for pl_obj in playlists:
            playlist_detail = api.get_playlist_detail(pl_obj['id'])
            if playlist_detail:
                log.print_info(u"<{}> author:{}".format(
                    playlist_detail['name'],
                    playlist_detail['creator']['nickname'],
                ))
                playlist_mo.parse_model(
                    playlist_detail,
                    download_type=download_type,
                    file_check=Config().get_file_check(),
                    shortcuts_stack=[] if Config().get_shortcut() else None)
        log.print_info("spider complete!~")
        pass
Example #3
0
    def scls_pls(self):
        from NXSpider.bin.models import playlist_mo

        if self.param_check(['cls'], sys._getframe().f_code.co_name) is False:
            return

        download_type = self.parse_download()
        class_name = self.app.pargs.cls
        class_name = py2_decoding(class_name)

        if class_name != u"全部" and py2_encoding(
                class_name) not in api.ALL_CLASSES:
            log.print_err(
                "class name is wrong, pls check by run : nxspider sw-pl-classes"
            )
            return

        playlists = api.get_top_playlists(category=class_name,
                                          offset=self.app.pargs.offset or 0,
                                          limit=self.app.pargs.limit
                                          or 50)  # type: list

        for pl_obj in playlists:
            playlist_detail = api.get_playlist_detail(pl_obj['id'])
            if playlist_detail:
                log.print_info(u"<{}> author:{}".format(
                    playlist_detail['name'],
                    playlist_detail['creator']['nickname'],
                ))
                playlist_mo.parse_model(playlist_detail,
                                        download_type=download_type,
                                        file_check=Config().get_file_check())
        log.print_info("spider complete!~")
        pass
Example #4
0
    def sur_pls(self):
        from NXSpider.bin.models import playlist_mo

        if self.param_check(['user'], sys._getframe().f_code.co_name) is False:
            return

        download_type = self.parse_download()
        user_id = self.app.pargs.user
        playlists = api.user_playlist(user_id)

        from terminaltables import AsciiTable
        table = AsciiTable([["ID", "Name", "User", "PlayCount"]])
        table_data = [[
            str(item['id']),
            item['name'],
            item['creator']['nickname'],
            str(item['playCount']),
        ] for item in playlists]
        table.table_data.extend(table_data)
        log.print_info("playlists bellow will be crawled")
        print(table.table)

        for pl_obj in playlists:
            playlist_detail = api.get_playlist_detail(pl_obj['id'])
            if playlist_detail:
                log.print_info(u"<{}> author:{}".format(
                    playlist_detail['name'],
                    playlist_detail['creator']['nickname'],
                ))
                playlist_mo.parse_model(playlist_detail,
                                        download_type=download_type,
                                        file_check=Config().get_file_check())
        log.print_info("spider complete!~")
        pass
Example #5
0
def playlist_by_id(link,
                   download_type=all_download_type,
                   save=True,
                   file_check=True):
    playlist_detail = get_playlist_detail(link)
    with tools.ignored(Exception):
        log.print_info("%s author:%s" % (
            "<" + playlist_detail['name'] + ">",
            playlist_detail['creator']['nickname'],
        ))

    playlist_mo = Playlist()
    playlist_mo.parse_model(playlist_detail,
                            save=save,
                            download_type=download_type,
                            file_check=file_check)
    pass
Example #6
0
    def login_spls(self):
        if self.param_check(['lu', 'lp'],
                            sys._getframe().f_code.co_name) is False:
            return

        from NXSpider.bin.models import playlist_mo

        plaintext_pwd = self.app.pargs.lp or None
        if plaintext_pwd is None:
            import getpass
            plaintext_pwd = getpass.getpass("Please input your password:"******"none")))
            exit()

        user_id = res['account']['id']
        download_type = self.parse_download()
        playlists = api.user_playlist(user_id,
                                      offset=self.app.pargs.offset or 0,
                                      limit=self.app.pargs.limit or 1000)

        log.print_info("playlists bellow will be crawled")
        print_playlist(playlists)

        for pl_obj in playlists:
            playlist_detail = api.get_playlist_detail(pl_obj['id'])
            if playlist_detail:
                log.print_info(u"<{}> author:{}".format(
                    playlist_detail['name'],
                    playlist_detail['creator']['nickname'],
                ))
                playlist_mo.parse_model(
                    playlist_detail,
                    download_type=download_type,
                    file_check=Config().get_file_check(),
                    shortcuts_stack=[] if Config().get_shortcut() else None)
        log.print_info("spider complete!~")
        pass
Example #7
0
def crawl_playlist_by_page(page,
                           dtype="全部",
                           download_type=['mp3', 'mv'],
                           save=True,
                           file_check=True):
    play_url = "http://music.163.com/discover/playlist/?order=hot&cat={}&limit=35&offset={}"
    play_url = play_url.format(dtype, page * 35)
    playlist_id = []
    titles = []
    try:
        acmsk = {'class': 'msk'}
        scnb = {'class': 'nb'}
        dcu = {'class': 'u-cover u-cover-1'}
        ucm = {'class': 'm-cvrlst f-cb'}
        data = tools.curl(play_url, headers, type=RETURE_HTML)
        lst = data.find('ul', ucm)
        for play in lst.find_all('div', dcu):
            title = play.find('a', acmsk)['title']
            link = play.find('a', acmsk)['href'].replace("/playlist?id=", "")

            playlist_detail = get_playlist_detail(link)
            with tools.ignored(Exception):
                log.print_info("%s author:%s" % (
                    "<" + playlist_detail['name'] + ">",
                    tools.encode(playlist_detail['creator']['nickname']),
                ))

            playlist_mo = Playlist()
            playlist_mo.parse_model(playlist_detail,
                                    save=save,
                                    download_type=download_type,
                                    file_check=file_check)

        return titles
    except Exception as e:
        log.print_err("crawl html error:{} type:{} page:{}".format(
            e, dtype, page))
        raise
Example #8
0
#     except Exception as e:
#         log.print_err("playlist page error:{} type:{} page:{}".format(e, type, page))
#         log.print_err(e)

# def playlist_all_page():
#     cf = "全部"
#     for i in range(36):
#         playlist_by_page(i + 1, cf)

# test = get_mv_details([5322493,239037])
test = get_classify()
test = get_playlist_catelogs()
test = get_playlist_classes()
test = get_top_playlists()
test = user_playlist(48872048)
test = get_playlist_detail(92024088)
test = get_playlist_detail(2246057871)
test = get_playlist_detail(107020750)
test = get_playlist_detail_v3(107020750)

p = hashlib.md5('000'.encode('utf-8')).hexdigest()
s = requests.Session()

test = login('15302663382', p, s)
test = user_playlist(92024088, session=s)
test = get_playlist_detail(107020750)

test = search('周杰伦', stype=100)
test = top_artists()
test = get_playlist_classes()
test = get_mp3_details([412902496, 412902496, 412902496])