예제 #1
0
    def __init__(self, m163, url=None, song_json=None):
        Song.__init__(self)
        self.song_type = 2
        self.handler = m163
        # self.group_dir = None
        # self.lyric_text = ''

        if url:
            self.url = url
            self.song_id = re.search(r'(?<=/song\?id=)\d+', url).group(0)

            LOG.debug(msg.head_163 + msg.fmt_init_song % self.song_id)
            response = self.handler.read_link(url_song %
                                              (self.song_id, self.song_id))

            #print json for debug
            #LOG.debug(util.format_json(response.text))

            j = response.json()['songs'][0]

            self.init_by_json(j)
            LOG.debug(msg.head_163 + msg.fmt_init_song_ok % self.song_id)
            #set filename, abs_path etc.
            self.post_set()

        elif song_json:
            self.init_by_json(song_json)
예제 #2
0
    def __init__(self, xiami_obj, url=None, song_json=None):
        Song.__init__(self)
        # self.lyric_text = ''
        self.song_type = 1
        self.handler = xiami_obj
        # self.group_dir = None
        if url:
            self.url = url
            self.song_id = xiami_obj.get_real_id(url, r'(?<=/song/)[^?]+')
            LOG.debug(msg.head_xm + msg.fmt_init_song % self.song_id)

            #get the song json data
            try:
                jsong = self.handler.read_link(
                    url_song % self.song_id).json()['data']['trackList'][0]
            except Exception, err:
                LOG.error(msg.head_xm + msg.fmt_err_song_parse % url)
                LOG.debug(self.handler.read_link(url_song % self.song_id).text)
                raise

            self.init_by_json(jsong)
            #used only for album/collection etc. create a dir to group all songs
            self.group_dir = None

            #set filename, abs_path etc.
            self.post_set()
            LOG.debug(msg.head_xm + msg.fmt_init_song_ok % self.song_id)
예제 #3
0
파일: xiami.py 프로젝트: sk1418/zhuaxia
    def __init__(self,xiami_obj,url=None,song_json=None):
        Song.__init__(self)
        # self.lyric_text = ''
        self.song_type=1
        self.handler = xiami_obj
        # self.group_dir = None
        if url:
            self.url = url
            self.song_id = xiami_obj.get_real_id(url, r'(?<=/song/)[^?]+')
            LOG.debug(msg.head_xm + msg.fmt_init_song % self.song_id)

            #get the song json data
            try:
                jsong = self.handler.read_link(url_song % self.song_id).json()['data']['trackList'][0]
            except Exception, err:
                LOG.error(msg.head_xm + msg.fmt_err_song_parse %url) 
                LOG.debug(self.handler.read_link(url_song % self.song_id).text)
                raise
                

            self.init_by_json(jsong)
            #used only for album/collection etc. create a dir to group all songs
            self.group_dir = None

            #set filename, abs_path etc.
            self.post_set()
            LOG.debug(msg.head_xm + msg.fmt_init_song_ok % self.song_id)
예제 #4
0
    def __init__(self,m163,url=None, song_json=None):
        Song.__init__(self)
        self.song_type=2
        self.handler = m163
        # self.group_dir = None
        # self.lyric_text = ''

        if url:
            self.url = url
            self.song_id = re.search(r'(?<=/song\?id=)\d+', url).group(0)

            LOG.debug(msg.head_163 + msg.fmt_init_song % self.song_id)
            response = self.handler.read_link(url_song % (self.song_id,self.song_id))

            #print json for debug
            #LOG.debug(util.format_json(response.text))

            j = response.json()['songs'][0]


            self.init_by_json(j)
            LOG.debug(msg.head_163 + msg.fmt_init_song_ok % self.song_id)
            #set filename, abs_path etc.
            self.post_set()

        elif song_json:
            self.init_by_json(song_json)
예제 #5
0
 def init_collection(self):
     j = self.xm.read_link(url_collection % (self.collection_id) ).json()['collect']
     self.collection_name = j['name']
     for jsong in j['songs']:
         song = Song(self.xm, song_json=jsong)
         #rewrite filename, make it different
         song.group_dir = self.collection_name
         song.post_set()
         self.songs.append(song)
     if len(self.songs):
         #creating the dir
         util.create_dir(path.dirname(self.songs[-1].abs_path))