Ejemplo n.º 1
0
 def __init__(self,*args,**kwargs):
     self.logger = Helper.get_logger()
     # 初始化一个NetCloudLogin 对象
     if len(args) == 0 and len(kwargs.keys()) == 0:
         self.netcloud_login = NetCloudLogin()
     else:
         self.netcloud_login = NetCloudLogin(args,kwargs)
Ejemplo n.º 2
0
 def __init__(self):
     self.logger = Helper.get_logger()
     self.singer_name = "刘瑞琪"
     self.song_name = "离开的借口"
     self.crawler = Crawler.NetCloudCrawler(self.song_name,
                                            self.singer_name)
     self.singer_url = 'http://music.163.com/artist?id={singer_id}'.format(
         singer_id=self.crawler.singer_id)
Ejemplo n.º 3
0
 def __init__(self):
     self.logger = Helper.get_logger()
     # 无参数登录
     self.login_printer = NetCloudPrinter()
     self.netcloud_login = NetCloudLogin()
Ejemplo n.º 4
0
 def __init__(self, song_name, singer_name, song_id=None, singer_id=None):
     self.logger = Helper.get_logger()
     # 如果id缺失,则尝试登录以从name获取id
     if song_id is None or singer_id is None:
         # 从用户机器配置文件加载登录信息
         config_dict = Helper._parse_config_xml()
         phone = config_dict['phone']
         password = config_dict['password']
         email = config_dict['email']
         rememberLogin = config_dict['rememberLogin']
         try:
             netcloud_login = NetCloudLogin(phone, password, email,
                                            rememberLogin)
             if song_id is None:
                 song_id = netcloud_login.get_song_id_by_name(song_name)
                 self.logger.info(
                     "Login to get %s's song_id(=%s) succeed!" %
                     (song_name, song_id))
             if singer_id is None:
                 singer_id = netcloud_login.get_singer_id_by_name(
                     singer_name)
                 self.logger.info(
                     "Login to get %s's singer_id(=%s) succeed!" %
                     (singer_name, singer_id))
         except Exception as e:
             self.logger.error("NetCloud login failed:%s" % e)
             self.logger.error(
                 "Please fullfill singer_id and song_id parameter"
                 " or check your login info in %s!" %
                 Constants.USER_CONFIG_FILE_PATH)
             return
     self.song_name = song_name
     self.song_id = song_id
     self.singer_name = singer_name
     self.singer_id = singer_id
     self.comments_url = "http://music.163.com/weapi/v1/resource/comments/R_SO_4_{song_id}/?csrf_token=".format(
         song_id=song_id)
     self.singer_url = 'http://music.163.com/artist?id={singer_id}'.format(
         singer_id=singer_id)
     # 保存下载文件(歌曲,评论等)的地址
     self.singer_root_dir = Constants.SINGER_SAVE_DIR
     Helper.mkdir(self.singer_root_dir)
     # 同一个歌手的相关文件保存在同一文件夹下
     self.singer_path = os.path.join(self.singer_root_dir, self.singer_name)
     Helper.mkdir(self.singer_path)
     # 同一首歌的相关文件保存在同一文件夹下
     self.song_path = os.path.join(self.singer_path, self.song_name)
     Helper.mkdir(self.song_path)
     # 评论文件保存地址
     self.comments_file_path = os.path.join(
         self.song_path, self.song_name + "_all_comments.json")
     # 用户信息保存地址
     self.users_info_file_path = os.path.join(self.song_path,
                                              Constants.USER_INFO_FILENAME)
     # 歌手全部热门歌曲文件保存地址
     self.singer_all_hot_comments_file_path = os.path.join(
         self.singer_path, Constants.SINGER_ALL_HOT_COMMENTS_FILENAME)
     # 计数器
     self.no_counter = 0
     # 多线程锁,防止文件写入冲突以及计数冲突
     self.lock = Lock()
Ejemplo n.º 5
0
    def __init__(self, *args, **kwargs):
        '''
		登录初始化,有多种构造函数
		1.如果不传入任何参数,则表示,从配置文件读取参数值(用户名,密码等)
		2.否则必须一次传入:phone,password,email(可选,默认None),rememberLogin(可选,默认True)参数
		'''
        self.logger = Helper.get_logger()
        self.method = None
        self.data = {}
        self.params = {}
        self.response = Response()
        self.req = requests.Session()  # 构造一个请求session
        if (not args or len(args) <= 1) and (not kwargs
                                             and len(kwargs.keys()) <= 1):
            try:
                # 从用户机器配置文件加载登录信息
                config_dict = Helper._parse_config_xml()
                self.phone = config_dict['phone']
                self.password = config_dict['password']
                self.email = None if not config_dict['email'] else config_dict[
                    'email']
                self.rememberLogin = True if config_dict[
                    'rememberLogin'].lower() == "true" else False
                self.logger.info("Load login info from %s succeed!" %
                                 Constants.USER_CONFIG_FILE_PATH)
            except Exception as e:
                self.logger.error("NetCloud login failed:%s" % e)
                return
        else:
            # 优先选择按照名字传入的参数,再选择顺序参数
            if "phone" in kwargs.keys():
                self.phone = kwargs["phone"]
            else:
                if len(args) >= 1:
                    self.phone = args[0]
                else:
                    self.logger.error("Get 'phone' paramerter failed!")
                    return
            if "password" in kwargs.keys():
                self.password = kwargs["password"]
            else:
                if len(args) >= 2:
                    self.password = args[1]
                else:
                    self.logger.error("Get 'password' paramerter failed!")
                    return
            if "email" in kwargs.keys():
                self.email = kwargs["email"]
            else:
                if len(args) >= 3:
                    self.email = args[2]
                else:
                    self.email = None  # 默认值
            if "rememberLogin" in kwargs.keys():
                self.rememberLogin = kwargs["rememberLogin"]
            else:
                if len(args) >= 4:
                    self.rememberLogin = args[3]
                else:
                    self.rememberLogin = True  # 默认值
        # 计数器
        self.no_counter = 0
        # 多线程锁,防止文件写入冲突以及计数冲突
        self.lock = Lock()
Ejemplo n.º 6
0
 def __init__(self):
     self.logger = Helper.get_logger()
     song_name = "梦醒时分"
     singer_name = "李翊君"
     self.netcloud_analyse = NetCloudAnalyse(song_name = song_name,singer_name = singer_name)