def get_list(self, stype, page=1): '''获取特定榜单''' self.downalbumnow = False cache_key = 'l_' + stype + str(page) if cache_key in self.cached_list: self.songlist = copy.copy(self.cached_list[cache_key]) return if stype in listing_map_dict: p = ListParser() print u'正在获取"' + stype + u'"的歌曲列表', sys.stdout.flush() # for i in range(0, songlists[stype][1], 25): i = (page - 1) * 25 html = self.get_url_html(list_url_template % (listing_map_dict[stype], i)) p.feed(html) print '.', sys.stdout.flush() # if callback: # callback( int(i / 25) + 1, (songlists[stype][1] / 25) ) print 'done!' self.songlist = p.songlist self.cached_list[cache_key] = copy.copy(p.songlist) return self.check_if_has_more(html) else: #TODO:raise Exception print u'未知列表:"' + str(stype) + u'",仅支持以下列表: ' + u'、'.join( ['"%s"' % key for key in songlists]) log.debug('Unknow list:"' + str(stype)) return None
def get_list(self, stype, callback=None, updateTreeView=None): '''获取特定榜单''' self.downalbumnow = False if stype in self.cached_list: self.songlist = copy.copy(self.cached_list[stype]) return if stype in songlists: p = ListParser() print u'正在获取"' + stype + u'"的歌曲列表', sys.stdout.flush() for i in range(0, songlists[stype][1], 25): html = self.get_url_html(list_url_template % (songlists[stype][0], i)) p.feed(html) print '.', sys.stdout.flush() if callback: callback(int(i / 25) + 1, (songlists[stype][1] / 25)) print 'done!' self.songlist = p.songlist self.cached_list[stype] = copy.copy(p.songlist) updateTreeView(p.songlist) else: #TODO:raise Exception print u'未知列表:"' + str(stype) + u'",仅支持以下列表: ' + u'、'.join( ['"%s"' % key for key in songlists]) log.debug('Unknow list:"' + str(stype))
def search(self, key, page=1): '''搜索关键字''' self.downalbumnow = False cache_key = 's_' + key + str(page) if cache_key in self.cached_list: self.songlist = copy.copy(self.cached_list[cache_key]) return key = re.sub((r'\ '), '+', key) p = ListParser() print u'正在获取"' + key + u'"的搜索结果列表...', sys.stdout.flush() pnum = (page - 1) * 20 html = self.get_url_html(search_url_template % (key, pnum)) p.feed(html) sys.stdout.flush() print 'done!' self.songlist = p.songlist self.cached_list[cache_key] = copy.copy(p.songlist) return self.check_if_has_more(html)
def search(self, key, callback=None): '''搜索关键字''' self.downalbumnow = False if 's_' + key in self.cached_list: self.songlist = copy.copy(self.cached_list['s_' + key]) return key = re.sub((r'\ '), '+', key) p = ListParser() print u'正在获取"' + key + u'"的搜索结果列表...', sys.stdout.flush() pnum = 0 while isinstance(pnum, int): html = self.get_url_html(search_url_template % (key, pnum)) p.feed(html) pnum = self.__get_pnum_by_html(html) print '.', sys.stdout.flush() print 'done!' self.songlist = p.songlist self.cached_list['s_' + key] = copy.copy(p.songlist) if callback: callback(self.songlist)