Example #1
0
    def init_by_json(self, js):
        #song_id
        self.song_id = js['id']
        #name
        self.song_name = util.decode_html(js['name'])

        # artist_name
        self.artist_name = js['artists'][0]['name']
        # album id, name
        self.album_name = util.decode_html(js['album']['name'])
        self.album_id = js['album']['id']
        #track no
        if js['position']:
            self.track_no = js['position']
        elif js['no']:
            self.track_no = js['no']

        # download link
        dfsId = ''
        if self.handler.is_hq and js['hMusic']:
            dfsId = js['hMusic']['dfsId']
        elif js['mMusic']:
            dfsId = js['mMusic']['dfsId']
        elif js['lMusic']:
            LOG.warning(msg.head_163 +
                        msg.fmt_quality_fallback % self.song_name)
            dfsId = js['lMusic']['dfsId']
        if dfsId:
            self.dl_link = url_mp3 % (self.handler.encrypt_dfsId(dfsId), dfsId)
        else:
            LOG.warning(msg.head_163 + msg.fmt_err_song_parse % self.song_name)

        #used only for album/collection etc. create a dir to group all songs
        #if it is needed, it should be set by the caller
        self.group_dir = None
Example #2
0
    def init_by_json(self, js):
        #name
        self.song_name = util.decode_html(js['name'])

        # artist_name
        self.artist_name = js['artists'][0]['name']
        # album id, name
        self.album_name = util.decode_html(js['album']['name'])
        self.album_id = js['album']['id']

        # download link
        dfsId = ''
        if self.handler.is_hq and js['hMusic']:
            dfsId = js['hMusic']['dfsId']
        elif js['mMusic']:
            dfsId = js['mMusic']['dfsId']
        elif js['lMusic']:
            LOG.warning(u'歌曲(%s) 无法获取128kbps资源,尝试获取低质量资源' % self.song_name)
            dfsId = js['lMusic']['dfsId']
        if dfsId:
            self.dl_link = url_mp3 % (self.handler.encrypt_dfsId(dfsId), dfsId)
        else:
            LOG.warning(u'歌曲(%s) 无法获取下载链接' % self.song_name)

        #used only for album/collection etc. create a dir to group all songs
        #if it is needed, it should be set by the caller
        self.group_dir = None
Example #3
0
    def init_by_json(self,js):
        #song_id
        self.song_id = js['id']
        #name
        self.song_name = util.decode_html(js['name'])
        

        # artist_name
        self.artist_name = js['artists'][0]['name']
        # album id, name
        self.album_name = util.decode_html(js['album']['name'])
        self.album_id = js['album']['id']
        #track no
        if js['position']:
            self.track_no = js['position']
        elif js['no']:
            self.track_no = js['no']

        # download link
        dfsId = ''
        if self.handler.is_hq and js['hMusic']:
            dfsId = js['hMusic']['dfsId']
        elif js['mMusic']:
            dfsId = js['mMusic']['dfsId']
        elif js['lMusic']:
            LOG.warning(msg.head_163 + msg.fmt_quality_fallback %self.song_name)
            dfsId = js['lMusic']['dfsId']
        if dfsId:
            self.dl_link = url_mp3 % (self.handler.encrypt_dfsId(dfsId), dfsId)
        else:
            LOG.warning(msg.head_163 + msg.fmt_err_song_parse %self.song_name)

        #used only for album/collection etc. create a dir to group all songs
        #if it is needed, it should be set by the caller
        self.group_dir = None
Example #4
0
    def init_by_json(self,js):
        #name
        self.song_name = util.decode_html(js['name'])

        # artist_name
        self.artist_name = js['artists'][0]['name']
        # album id, name
        self.album_name = util.decode_html(js['album']['name'])
        self.album_id = js['album']['id']

        # download link
        dfsId = ''
        if self.handler.is_hq and js['hMusic']:
            dfsId = js['hMusic']['dfsId']
        elif js['mMusic']:
            dfsId = js['mMusic']['dfsId']
        elif js['lMusic']:
            LOG.warning(u'歌曲(%s) 无法获取128kbps资源,尝试获取低质量资源'%self.song_name)
            dfsId = js['lMusic']['dfsId']
        if dfsId:
            self.dl_link = url_mp3 % (self.handler.encrypt_dfsId(dfsId), dfsId)
        else:
            LOG.warning(u'歌曲(%s) 无法获取下载链接'%self.song_name)

        #used only for album/collection etc. create a dir to group all songs
        #if it is needed, it should be set by the caller
        self.group_dir = None
Example #5
0
    def init_by_json(self, song_json ):
        """ 
        This method will handle HQ option too
        the group dir and abs_path should be set by the caller
        """

        self.song_id = song_json['song_id']
        self.album_id = song_json['album_id']
        title = song_json['artist'] + '_' + self.song_id
        if song_json['songName']:
            title = song_json['songName']
        elif song_json['name']:
            title = song_json['name']
        elif song_json['title']:
            title = song_json['title']

        self.song_name = util.decode_html(title)
        location = song_json['location']
        #decode download link
        self.dl_link = self.handler.decode_xiami_link(location)
        # set lyrics link if dl_lyric flag is true
        self.lyric_link = song_json['lyric_url'] if self.handler.dl_lyric else ''
        # artist_name
        self.artist_name = song_json['artist']
        # album id, name
        self.album_name = util.decode_html(song_json['album_name'])

        #if is_hq, get the hq location to overwrite the dl_link
        if self.handler.is_hq:
            try:
                hq_link = self.handler.get_hq_link(song_json)
                self.dl_link = hq_link if hq_link else self.dl_link
            except:
                #if user was not VIP, don't change the dl_link
                pass
Example #6
0
    def init_by_json(self, song_json ):
        """ 
        This method will handle HQ option too
        the group dir and abs_path should be set by the caller
        """

        self.song_id = song_json['song_id']
        self.album_id = song_json['album_id']
        title = song_json['artist'] + '_' + self.song_id
        if song_json['songName']:
            title = song_json['songName']
        elif song_json['name']:
            title = song_json['name']
        elif song_json['title']:
            title = song_json['title']

        self.song_name = util.decode_html(title)
        location = song_json['location']
        #decode download link
        self.dl_link = self.handler.decode_xiami_link(location)
        # set lyrics link if dl_lyric flag is true
        self.lyric_link = song_json['lyric_url'] if self.handler.dl_lyric else ''
        # artist_name
        self.artist_name = song_json['artist']
        # album id, name
        self.album_name = util.decode_html(song_json['album_name'])

        #if is_hq, get the hq location to overwrite the dl_link
        if self.handler.is_hq:
            try:
                hq_link = self.handler.get_hq_link(song_json)
                self.dl_link = hq_link if hq_link else self.dl_link
            except:
                #if user was not VIP, don't change the dl_link
                pass
Example #7
0
    def init_by_json(self, js):
        # song_id
        self.song_id = js["id"]
        # name
        self.song_name = util.decode_html(js["name"])

        # artist_name
        self.artist_name = js["artists"][0]["name"]
        # album id, name
        self.album_name = util.decode_html(js["album"]["name"])
        self.album_id = js["album"]["id"]

        # download link
        dfsId = ""
        if self.handler.is_hq and js["hMusic"]:
            dfsId = js["hMusic"]["dfsId"]
        elif js["mMusic"]:
            dfsId = js["mMusic"]["dfsId"]
        elif js["lMusic"]:
            LOG.warning(msg.head_163 + msg.fmt_quality_fallback % self.song_name)
            dfsId = js["lMusic"]["dfsId"]
        if dfsId:
            self.dl_link = url_mp3 % (self.handler.encrypt_dfsId(dfsId), dfsId)
        else:
            LOG.warning(msg.head_163 + msg.fmt_err_song_parse % self.song_name)

        # used only for album/collection etc. create a dir to group all songs
        # if it is needed, it should be set by the caller
        self.group_dir = None
Example #8
0
 def init_by_json(self, song_json ):
     """ the group dir and abs_path should be set by the caller"""
     self.song_id = song_json['song_id']
     self.album_id = song_json['album_id']
     self.song_name = util.decode_html(song_json['title'])
     location = song_json['location']
     #decode download link
     self.dl_link = self.handler.decode_xiami_link(location)
     # lyrics link
     self.lyrics_link = song_json['lyric_url']
     # artist_name
     self.artist_name = song_json['artist']
     # album id, name
     self.album_name = util.decode_html(song_json['album_name'])
Example #9
0
    def init_by_json(self, song_json ):
        """ the group dir and abs_path should be set by the caller"""

        self.song_id = song_json['song_id']
        self.album_id = song_json['album_id']
        self.song_name = util.decode_html(song_json['title'])
        location = song_json['location']
        #decode download link
        self.dl_link = self.handler.decode_xiami_link(location)
        # set lyrics link if dl_lyric flag is true
        self.lyric_link = song_json['lyric_url'] if self.handler.dl_lyric else ''
        # artist_name
        self.artist_name = song_json['artist']
        # album id, name
        self.album_name = util.decode_html(song_json['album_name'])
Example #10
0
def resolve(url):
    url = util.decode_html(url)
    util.info('Resolving '+url)
    resolver = _get_resolver(url)
    value = None
    if resolver == None:
        return None
    util.debug('Using resolver '+str(resolver.__name__));
    try:
        value = resolver.resolve(url)
    except:
        traceback.print_exc()
    if value == None:
        return []
    default = item()
    # fix  missing but required values 
    def fix_stream(i,url,resolver,default):
        if not 'name' in i.keys():
            i['name'] = resolver.__name__
        if not 'surl' in i.keys():
            i['surl'] = url
        for key in default.keys():
            if not key in i.keys():
                i[key] = default[key]
    [fix_stream(i,url,resolver,default) for i in value]
    return sorted(value,key=lambda i:i['quality'])
Example #11
0
    def init_album(self):
        #album json
        js = self.m163.read_link(url_album % self.album_id).json()['album']
        #name
        self.album_name = util.decode_html(js['name'])
        #album logo
        self.logo = js['picUrl']
        # artist_name
        self.artist_name = js['artists'][0]['name']
        #handle songs
        for jsong in js['songs']:
            song = NeteaseSong(self.m163, song_json=jsong)
            song.group_dir = self.artist_name + u'_' + self.album_name
            song.post_set()
            self.songs.append(song)

        d = path.dirname(self.songs[-1].abs_path)
        #creating the dir
        LOG.debug(u'创建专辑目录[%s]' % d)
        util.create_dir(d)

        #download album logo images
        LOG.debug(u'下载专辑[%s]封面' % self.album_name)
        downloader.download_by_url(
            self.logo, path.join(d, 'cover.' + self.logo.split('.')[-1]))
Example #12
0
def resolve(url):
    """
        resolves given url by asking all resolvers

        returns None if no resolver advised to be able to resolve this url
        returns False if resolver did his job, but did not return any value (thus failed)
        returns Array of resolved objects in positive usecase
    """
    url = util.decode_html(url)
    util.info('Resolving ' + url)
    resolver = _get_resolver(url)
    value = None
    if resolver is None:
        return None
    util.info('Using resolver \'%s\'' % str(resolver.__name__))
    try:
        value = resolver.resolve(url)
    except:
        traceback.print_exc()
    if value is None:
        return False
    default = item()

    def fix_stream(i, url, resolver, default):
        """ fix  missing but required values """
        if 'name' not in i.keys():
            i['name'] = resolver.__name__
        if 'surl' not in i.keys():
            i['surl'] = url
        for key in default.keys():
            if key not in i.keys():
                i[key] = default[key]

    [fix_stream(i, url, resolver, default) for i in value]
    return sorted(value, key=lambda i: i['quality'])
def resolve(url):
    """
        resolves given url by asking all resolvers

        returns None if no resolver advised to be able to resolve this url
        returns False if resolver did his job, but did not return any value (thus failed)
        returns Array of resolved objects in positive usecase
    """
    url = util.decode_html(url)
    util.info('Resolving ' + url)
    resolver = _get_resolver(url)
    value = None
    if resolver is None:
        return None
    util.info('Using resolver \'%s\'' % str(resolver.__name__));
    try:
        value = resolver.resolve(url)
    except:
        traceback.print_exc()
    if value is None:
        return False
    default = item()

    def fix_stream(i, url, resolver, default):
        """ fix  missing but required values """
        if 'name' not in i.keys():
            i['name'] = resolver.__name__
        if 'surl' not in i.keys():
            i['surl'] = url
        for key in default.keys():
            if key not in i.keys():
                i[key] = default[key]

    [fix_stream(i, url, resolver, default) for i in value]
    return sorted(value, key=lambda i: i['quality'])
Example #14
0
    def init_album(self):
        #album json
        js = self.handler.read_link(url_album % self.album_id).json()['album']
        #name
        self.album_name = util.decode_html(js['name'])
        #album logo
        self.logo = js['picUrl']
        # artist_name
        self.artist_name = js['artists'][0]['name']
        #handle songs
        for jsong in js['songs']:
            song = NeteaseSong(self.handler, song_json=jsong)
            song.group_dir = self.artist_name + u'_' + self.album_name
            song.group_dir = song.group_dir.replace('/', '_')
            song.post_set()
            self.songs.append(song)

        d = path.dirname(self.songs[-1].abs_path)
        #creating the dir
        LOG.debug(msg.head_163 + msg.fmt_create_album_dir % d)
        util.create_dir(d)

        #download album logo images
        LOG.debug(msg.head_163 + msg.fmt_dl_album_cover % self.album_name)
        downloader.download_url(self.logo, path.join(d,'cover.' +self.logo.split('.')[-1]))
Example #15
0
    def init_album(self):
        #album json
        js = self.handler.read_link(url_album % self.album_id).json()['album']
        #name
        self.album_name = util.decode_html(js['name'])
        #album logo
        self.logo = js['picUrl']
        # artist_name
        self.artist_name = js['artists'][0]['name']
        #handle songs
        for jsong in js['songs']:
            song = NeteaseSong(self.handler, song_json=jsong)
            song.group_dir = self.artist_name + u'_' + self.album_name
            song.group_dir = song.group_dir.replace('/', '_')
            song.post_set()
            self.songs.append(song)

        d = path.dirname(self.songs[-1].abs_path)
        #creating the dir
        LOG.debug(msg.head_163 + msg.fmt_create_album_dir % d)
        util.create_dir(d)

        #download album logo images
        LOG.debug(msg.head_163 + msg.fmt_dl_album_cover % self.album_name)
        downloader.download_url(
            self.logo, path.join(d, 'cover.' + self.logo.split('.')[-1]))
Example #16
0
def download(addon, filename, url, local, notifyFinishDialog=True, headers={}):
    try:
        util.info('Downloading %s to %s' % (url, local))
    except:
        util.info('Downloading ' + url)
    local = xbmc.makeLegalFilename(local)
    try:
        filename = util.replace_diacritic(util.decode_html(filename))
    except:
        filename = 'Video soubor'
    icon = os.path.join(addon.getAddonInfo('path'), 'icon.png')
    notifyEnabled = addon.getSetting('download-notify') == 'true'
    notifyEvery = addon.getSetting('download-notify-every')
    notifyPercent = 1
    if int(notifyEvery) == 0:
        notifyPercent = 10
    if int(notifyEvery) == 1:
        notifyPercent = 5

    def encode(string):
        return u' '.join(string).encode('utf-8')

    def notify(title, message, time=3000):
        try:
            xbmcgui.Dialog().notification(encode(title), encode(message), time=time, icon=icon,
                                          sound=False)
        except:
            traceback.print_exc()
            error('unable to show notification')

    def callback(percent, speed, est, filename):
        if percent == 0 and speed == 0:
            notify(xbmc.getLocalizedString(13413), filename)
            return
        if notifyEnabled:
            if percent > 0 and percent % notifyPercent == 0:
                esTime = '%ss' % est
                if est > 60:
                    esTime = '%sm' % int(est / 60)
                message = xbmc.getLocalizedString(
                    24042) % percent + ' - %s KB/s %s' % (speed, esTime)
                notify(message, filename)

    downloader = Downloader(callback)
    result = downloader.download(url, local, filename, headers)
    try:
        if result == True:
            if xbmc.Player().isPlaying():
                notify(xbmc.getLocalizedString(20177), filename)
            else:
                if notifyFinishDialog:
                    xbmcgui.Dialog().ok(xbmc.getLocalizedString(20177), filename)
                else:
                    notify(xbmc.getLocalizedString(20177), filename)
        else:
            notify(xbmc.getLocalizedString(257), filename)
            xbmcgui.Dialog().ok(filename, xbmc.getLocalizedString(257) + ' : ' + result)
    except:
        traceback.print_exc()
 def _extract_infolabels(self, item):
     infoLabels = {}
     for label in ['title', 'plot', 'year', 'genre', 'rating', 'director',
                   'votes', 'cast', 'trailer', 'tvshowtitle', 'season',
                   'episode', 'duration']:
         if label in item.keys():
             infoLabels[label] = util.decode_html(item[label])
     return infoLabels
Example #18
0
 def _extract_infolabels(self, item):
     infoLabels = {}
     for label in [
             'plot', 'year', 'genre', 'rating', 'director', 'votes', 'cast',
             'trailer', 'duration', 'videoid', 'videowidth'
     ]:
         if label in item.keys():
             infoLabels[label] = util.decode_html(item[label])
     return infoLabels
Example #19
0
    def init_by_url(self,url):
        self.song_id = re.search(r'(?<=/song/)\d+', url).group(0)
        j = self.xm.read_link(url_song % self.song_id).json()
        #name
        #self.song_name = j['song']['song_name'].replace('&#039;',"'")
        self.song_name = util.decode_html(j['song']['song_name'])
        # download link
        self.dl_link = j['song']['song_location']
        # lyrics link
        self.lyrics_link = j['song']['song_lrc']
        # artist_name
        self.artist_name = j['song']['artist_name']
        # album id, name
        self.album_name = util.decode_html(j['song']['album_name'])
        self.album_id = j['song']['album_id']

        #used only for album/collection etc. create a dir to group all songs
        self.group_dir = None
Example #20
0
    def init_album(self):
        resp_json = self.handler.read_link(url_album % self.album_id).json()
        j = resp_json['data']['trackList']

        if not j:
            LOG.error(resp_json['message'])
            return
        #description
        html = self.handler.read_link(self.url).text
        soup = BeautifulSoup(html, 'html.parser')
        if soup.find('meta', property="og:title"):
            self.album_desc = soup.find('span', property="v:summary").text
            # name
            self.album_name = soup.find('meta', property="og:title")['content']
            # album logo
            self.logo = soup.find('meta', property="og:image")['content']
            # artist_name
            self.artist_name = soup.find('meta',
                                         property="og:music:artist")['content']
        else:
            aSong = j[0]
            self.album_name = aSong['album_name']
            self.logo = aSong['album_pic']
            self.artist_name = aSong['artistVOs'][0]['artistName']
            self.album_desc = None

        #handle songs
        for jsong in j:
            song = XiamiSong(self.handler, song_json=jsong)
            song.song_name = jsong['name']  # name or songName
            song.group_dir = self.artist_name + u'_' + self.album_name
            song.group_dir = song.group_dir.replace('/', '_')
            song.post_set()
            self.songs.append(song)

        d = path.dirname(self.songs[-1].abs_path)
        #creating the dir
        LOG.debug(msg.head_xm + msg.fmt_create_album_dir % d)
        util.create_dir(d)

        #download album logo images
        LOG.debug(msg.head_xm + msg.fmt_dl_album_cover % self.album_name)
        if self.logo:
            self.logo = self.handler.add_http_prefix(self.logo)
            downloader.download_url(
                self.logo, path.join(d, 'cover.' + self.logo.split('.')[-1]))

        LOG.debug(msg.head_xm + msg.fmt_save_album_desc % self.album_name)
        if self.album_desc:
            self.album_desc = re.sub(r'&lt;\s*[bB][rR]\s*/&gt;', '\n',
                                     self.album_desc)
            self.album_desc = re.sub(r'&lt;.*?&gt;', '', self.album_desc)
            self.album_desc = util.decode_html(self.album_desc)
            import codecs
            with codecs.open(path.join(d, 'album_description.txt'), 'w',
                             'utf-8') as f:
                f.write(self.album_desc)
 def _extract_infolabels(self, item):
     infoLabels = {}
     for label in [
             'title', 'plot', 'year', 'genre', 'rating', 'director',
             'votes', 'cast', 'trailer', 'tvshowtitle', 'season', 'episode'
     ]:
         if label in item.keys():
             infoLabels[label] = util.decode_html(item[label])
     return infoLabels
Example #22
0
    def init_by_url(self,url):
        self.song_id = re.search(r'(?<=/song/)\d+', url).group(0)
        j = self.xm.read_link(url_song % self.song_id).json()
        #name
        #self.song_name = j['song']['song_name'].replace('&#039;',"'")
        self.song_name = util.decode_html(j['song']['song_name'])
        # download link
        self.dl_link = j['song']['song_location']
        # lyrics link
        self.lyrics_link = j['song']['song_lrc']
        # artist_name
        self.artist_name = j['song']['artist_name']
        # album id, name
        self.album_name = util.decode_html(j['song']['album_name'])
        self.album_id = j['song']['album_id']

        #used only for album/collection etc. create a dir to group all songs
        self.group_dir = None
Example #23
0
def add_plugin_call(name, plugin, params, logo="", infoLabels={}):
    name = util.decode_html(name)
    infoLabels["Title"] = name
    liz = xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=logo)
    try:
        liz.setInfo(type="Video", infoLabels=infoLabels)
    except:
        traceback.print_exc()
    plugurl = util._create_plugin_url(params, plugin)
    return xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=plugurl, listitem=liz, isFolder=True)
Example #24
0
    def init_album(self):
        j = self.handler.read_link(url_album %
                                   self.album_id).json()['data']['trackList']
        j_first_song = j[0]
        #name
        self.album_name = util.decode_html(j_first_song['album_name'])
        #album logo
        self.logo = j_first_song['album_pic']
        # artist_name
        self.artist_name = j_first_song['artist']

        #description
        html = self.handler.read_link(self.url).text
        soup = BeautifulSoup(html, 'html.parser')
        self.album_desc = soup.find('span', property="v:summary").text

        #handle songs
        for jsong in j:
            song = XiamiSong(self.handler, song_json=jsong)
            song.group_dir = self.artist_name + u'_' + self.album_name
            song.post_set()
            self.songs.append(song)

        d = path.dirname(self.songs[-1].abs_path)
        #creating the dir
        LOG.debug(msg.head_xm + msg.fmt_create_album_dir % d)
        util.create_dir(d)

        #download album logo images
        LOG.debug(msg.head_xm + msg.fmt_dl_album_cover % self.album_name)
        downloader.download_url(
            self.logo, path.join(d, 'cover.' + self.logo.split('.')[-1]))

        LOG.debug(msg.head_xm + msg.fmt_save_album_desc % self.album_name)
        if self.album_desc:
            self.album_desc = re.sub(r'&lt;\s*[bB][rR]\s*/&gt;', '\n',
                                     self.album_desc)
            self.album_desc = re.sub(r'&lt;.*?&gt;', '', self.album_desc)
            self.album_desc = util.decode_html(self.album_desc)
            import codecs
            with codecs.open(path.join(d, 'album_description.txt'), 'w',
                             'utf-8') as f:
                f.write(self.album_desc)
    def add_dir(self, name, params, logo='', infoLabels={}, menuItems={}):
        name = util.decode_html(name)
        if 'title' not in infoLabels:
            infoLabels['title'] = ''
        if logo is None:
            logo = ''
        liz = xbmcgui.ListItem(name,
                               iconImage='DefaultFolder.png',
                               thumbnailImage=logo)

        if 'art' in infoLabels.keys():
            liz.setArt(infoLabels['art'])

        if 'selected' in infoLabels.keys():
            wnd = xbmcgui.Window(xbmcgui.getCurrentWindowId())
            util.debug("[SC] wnd: %s [%d]" %
                       (str(wnd), xbmcgui.getCurrentWindowId()))

        try:
            liz.setInfo(type='Video',
                        infoLabels=self._extract_infolabels(infoLabels))
        except:
            sys.exc_info()
            util.debug("CHYBA")
            util.debug(infoLabels)
        items = []
        for mi in menuItems.keys():
            action = menuItems[mi]
            if not type(action) == type({}):
                items.append((mi, action))
            else:
                if 'action-type' in action:
                    action_type = action['action-type']
                    del action['action-type']
                    if action_type == 'list':
                        items.append((mi, 'Container.Update(%s)' %
                                      sctop._create_plugin_url(action)))
                    elif action_type == 'play':
                        items.append((mi, 'PlayMedia(%s)' %
                                      sctop._create_plugin_url(action)))
                    else:
                        items.append((mi, 'RunPlugin(%s)' %
                                      sctop._create_plugin_url(action)))
                else:
                    items.append(
                        (mi,
                         'RunPlugin(%s)' % sctop._create_plugin_url(action)))
        if len(items) > 0:
            liz.addContextMenuItems(items)
        return xbmcplugin.addDirectoryItem(
            handle=int(sys.argv[1]),
            url=sctop._create_plugin_url(params),
            listitem=liz,
            isFolder=True)
    def _extract_infolabels(self, item):
        infoLabels = {}
        for label in [
                'genre', 'year', 'episode', 'season', 'top250', 'tracknumber',
                'rating', 'watched', 'playcount', 'overlay', 'cast',
                'castandrole', 'director', 'mpaa', 'plot', 'plotoutline',
                'title', 'originaltitle', 'sorttitle', 'duration', 'studio',
                'tagline', 'writer', 'tvshowtitle', 'premiered', 'status',
                'aired', 'credits', 'lastplayed', 'album', 'artist', 'votes',
                'trailer', 'dateadded', 'count', 'date', 'imdbnumber',
                'mediatype'
        ]:
            if label in item.keys():
                if label == 'cast':
                    if hasattr(item['cast'], 'lower'):
                        item['cast'] = item['cast'].split(', ')
                    infoLabels[label] = item[label]
                else:
                    infoLabels[label] = util.decode_html(item[label])
        try:
            if item.get('imdb') and int(
                    item.get('imdb')) > 0 and item.get('season') is None:
                if 'tt%07d' % int(
                        item.get('imdb')) in self.getTraktLastActivity():
                    util.debug("[SC] oznacujem za videne z trakt.tv %s" %
                               str(item))
                    infoLabels['playcount'] = 1
                util.debug("[SC] item ma imdb %s" % str(item.get('imdb')))
        except:
            pass

        try:
            if item.get('tvdb') and int(item.get('tvdb')) > 0 and item.get(
                    'season') is not None and item.get('episode') is not None:
                playcount = [
                    i[2] for i in self.getTraktLastActivity('series')
                    if i[0] == item.get('tvdb')
                ]
                playcount = playcount[0] if len(playcount) > 0 else []
                playcount = [
                    i for i in playcount
                    if int(item.get('season')) == int(i[0])
                    and int(item.get('episode')) == int(i[1])
                ]
                playcount = 1 if len(playcount) > 0 else 0
                infoLabels['playcount'] = playcount
                util.debug("[SC] item ma tvdb %s %sx%s %s" %
                           (str(item.get('tvdb')), str(item.get('season')),
                            str(item.get('episode')), str(playcount)))
        except:
            pass

        #infoLabels['overlay'] = 7
        return infoLabels
Example #27
0
    def list(self,url):
        if url.find('#fm#') == 0:
            return self.list_folder(url[5:])
        url = self._url(url)
        page = util.request(url,headers={'X-Requested-With':'XMLHttpRequest','Referer':url,'Cookie':'uloz-to-id=1561277170;'}).decode('string-escape')
        script = util.substr(page,'var kn','</script>')
        keymap = None
        key = None
        k = re.search(r'({.+?})',script)
        if k:
            keymap = util.json.loads(k.group(1))
        j = re.search(r'ad.push\(\[kn, kn\["([^"]+)', script)
        if j:
            key = j.group(1)
        if not (j and k):
            self.error('error parsing page - unable to locate keys')
            return []
        burl = b64decode('I2h0dHA6Ly9kZWNyLWNlY2gucmhjbG91ZC5jb20vZGVjcnlwdC8/a2V5PSVzJnZhbHVlPSVz')
        murl = b64decode('aHR0cDovL2RlY3ItY2VjaC5yaGNsb3VkLmNvbS9kZWNyeXB0Lw==')
        result = []
        req = {'seed':keymap[key],'values':keymap}
        decr = json.loads(util.post_json(murl,req))
        for li in re.finditer('<div data-icon=\"(?P<key>[^\"]+)',page, re.IGNORECASE |  re.DOTALL):
            body = urllib.unquote(b64decode(decr[li.group('key')]))
            div_name = util.substr(body, '<div class="name"', '</div>')
            title_url_match = re.search(r'<a href="(?P<url>[^"]+)" title="(?P<title>[^"]+)', div_name)

            if not title_url_match:
                continue
            item = self.video_item()
            item['title'] = title_url_match.group('title')
            item['url'] = title_url_match.group('url')

            div_media = util.substr(body, 'div class="media"', '<div class="tools">')
            img_match = re.search(r'img src="([^"]+)', div_media)
            if img_match:
                item['img'] = "http:" + img_match.group(1)
            time_match = re.search(r'<span>Čas</span>(.+)', div_media)
            if time_match:
                item['length'] = time_match.group(1).strip()
            size_match = re.search(r'<span>Velikost</span>([^<]+)', div_media)
            if size_match:
                item['size'] = size_match.group(1).strip()
            self._filter(result,item)
        # page navigation
        data = util.substr(page,'<div class=\"paginator','</div')
        mnext = re.search('<a href=\"(?P<url>[^\"]+)\" class="next',data)
        if mnext:
            item = self.dir_item()
            item['type'] = 'next'
            item['url'] = util.decode_html(mnext.group('url'))
            result.append(item)
        return result
Example #28
0
    def init_album(self):
        resp_json = self.handler.read_link(url_album % self.album_id).json()
        j = resp_json['data']['trackList']

        if not j :
            LOG.error(resp_json['message'])
            return
        #description
        html = self.handler.read_link(self.url).text
        soup = BeautifulSoup(html,'html.parser')
        if  soup.find('meta', property="og:title"):
            self.album_desc = soup.find('span', property="v:summary").text
            # name
            self.album_name = soup.find('meta', property="og:title")['content']
            # album logo
            self.logo = soup.find('meta', property="og:image")['content']
            # artist_name
            self.artist_name = soup.find('meta', property="og:music:artist")['content']
        else:
            aSong = j[0]
            self.album_name = aSong['album_name']
            self.logo = aSong['album_pic']
            self.artist_name = aSong['artistVOs'][0]['artistName']
            self.album_desc = None

        #handle songs
        for jsong in j:
            song = XiamiSong(self.handler, song_json=jsong)
            song.song_name = jsong['name']  # name or songName
            song.group_dir = self.artist_name + u'_' + self.album_name
            song.group_dir = song.group_dir.replace('/','_')
            song.post_set()
            self.songs.append(song)

        d = path.dirname(self.songs[-1].abs_path)
        #creating the dir
        LOG.debug(msg.head_xm + msg.fmt_create_album_dir % d)
        util.create_dir(d)

        #download album logo images
        LOG.debug(msg.head_xm + msg.fmt_dl_album_cover % self.album_name)
        if self.logo:
            self.logo = self.handler.add_http_prefix(self.logo)
            downloader.download_url(self.logo, path.join(d,'cover.' +self.logo.split('.')[-1]))

        LOG.debug(msg.head_xm + msg.fmt_save_album_desc % self.album_name)
        if self.album_desc:
            self.album_desc = re.sub(r'&lt;\s*[bB][rR]\s*/&gt;','\n',self.album_desc)
            self.album_desc = re.sub(r'&lt;.*?&gt;','',self.album_desc)
            self.album_desc = util.decode_html(self.album_desc)
            import codecs
            with codecs.open(path.join(d,'album_description.txt'), 'w', 'utf-8') as f:
                f.write(self.album_desc)
Example #29
0
    def init_by_json(self,js):
        #name
        self.song_name = util.decode_html(js['name'])

        # artist_name
        self.artist_name = js['artists'][0]['name']
        # album id, name
        self.album_name = util.decode_html(js['album']['name'])
        self.album_id = js['album']['id']

        # download link
        dfsId = ''
        if self.handler.is_hq and js['hMusic']:
            dfsId = js['hMusic']['dfsId']
        else:
            dfsId = js['mMusic']['dfsId']
        self.dl_link = url_mp3 % (self.handler.encrypt_dfsId(dfsId), dfsId)

        #used only for album/collection etc. create a dir to group all songs
        #if it is needed, it should be set by the caller
        self.group_dir = None
Example #30
0
    def init_by_url(self,url):
        self.song_id = re.search(r'(?<=/song/)\d+', url).group(0)
        j = self.xm.read_link(url_song % self.song_id).json()
        #name
        #self.song_name = j['song']['song_name'].replace('&#039;',"'")
        self.song_name = util.decode_html(j['song']['song_name'])
        # download link
        self.dl_link = j['song']['song_location']
        # lyrics link
        self.lyrics_link = j['song']['song_lrc']
        # artist_name
        self.artist_name = j['song']['artist_name']
        # album id, name
        self.album_name = util.decode_html(j['song']['album_name'])
        self.album_id = j['song']['album_id']

        #used only for album/collection etc. create a dir to group all songs
        self.group_dir = None
        #filename  artistName_songName.mp3
        self.filename = (self.artist_name + u"_" if self.artist_name  else "" ) + self.song_name + u'.mp3'
        self.abs_path = path.join(config.DOWNLOAD_DIR,self.filename)
Example #31
0
    def list(self,url):
        if url.find('#fm#') == 0:
            return self.list_folder(url[5:])
        url = self._url(url)
        page = util.request(url,headers={'X-Requested-With':'XMLHttpRequest','Referer':url,'Cookie':'uloz-to-id=1561277170;'}).decode('string-escape')
        script = util.substr(page,'var kn','</script>')
        keymap = None
        key = None
        k = re.search(r'({.+?})',script)
        if k:
            keymap = util.json.loads(k.group(1))
        j = re.search(r'ad.push\(\[kn, kn\["([^"]+)', script)
        if j:
            key = j.group(1)
        if not (j and k):
            self.error('error parsing page - unable to locate keys')
            return []
        burl = b64decode('I2h0dHA6Ly9kZWNyLWNlY2gucmhjbG91ZC5jb20vZGVjcnlwdC8/a2V5PSVzJnZhbHVlPSVz')
        murl = b64decode('aHR0cDovL2RlY3ItY2VjaC5yaGNsb3VkLmNvbS9kZWNyeXB0Lw==')
        result = []
        req = {'seed':keymap[key],'values':keymap}
        decr = json.loads(util.post_json(murl,req))
        for li in re.finditer('<div data-icon=\"(?P<key>[^\"]+)',page, re.IGNORECASE |  re.DOTALL):
            body = urllib.unquote(b64decode(decr[li.group('key')]))
            div_name = util.substr(body, '<div class="name"', '</div>')
            title_url_match = re.search(r'<a href="(?P<url>[^"]+)" title="(?P<title>[^"]+)', div_name)

            if not title_url_match:
                continue
            item = self.video_item()
            item['title'] = title_url_match.group('title')
            item['url'] = title_url_match.group('url')

            div_media = util.substr(body, 'div class="media"', '<div class="tools">')
            img_match = re.search(r'img src="([^"]+)', div_media)
            if img_match:
                item['img'] = "http:" + img_match.group(1)
            time_match = re.search(r'<span>Čas</span>(.+)', div_media)
            if time_match:
                item['length'] = time_match.group(1).strip()
            size_match = re.search(r'<span>Velikost</span>([^<]+)', div_media)
            if size_match:
                item['size'] = size_match.group(1).strip()
            self._filter(result,item)
        # page navigation
        data = util.substr(page,'<div class=\"paginator','</div')
        mnext = re.search('<a href=\"(?P<url>[^\"]+)\" class="next',data)
        if mnext:
            item = self.dir_item()
            item['type'] = 'next'
            item['url'] = util.decode_html(mnext.group('url'))
            result.append(item)
        return result
Example #32
0
 def new_episodes(self,page):
     result = []
     data = util.substr(page,'<div id=\"archive-posts\"','</ul>')
     pattern='<img(.+?)src=\"(?P<img>[^\"]+)(.+?)<a href=\"(?P<url>[^\"]+)[^>]+>(?P<name>[^<]+)</a>'	
     for m in re.finditer(pattern, data, re.IGNORECASE | re.DOTALL):
         name = util.decode_html(m.group('name'))
         item = self.video_item()
         item['url'] = m.group('url')
         item['title'] = name
         item['img'] = m.group('img')
         self._filter(result,item)
     return result
Example #33
0
    def init_by_json(self, song_json ):
        """ the group dir and abs_path should be set by the caller"""

        self.song_id = song_json['song_id']
        self.album_id = song_json['album_id']
        self.song_name = util.decode_html(song_json['name'])
        self.dl_link = song_json['location']
        # lyrics link
        self.lyrics_link = song_json['lyric']
        # artist_name
        self.artist_name = song_json['artist_name']
        # album id, name
        self.album_name = song_json['title']
Example #34
0
    def init_by_json(self, song_json ):
        """ the group dir and abs_path should be set by the caller"""

        self.song_id = song_json['song_id']
        self.album_id = song_json['album_id']
        self.song_name = util.decode_html(song_json['name'])
        self.dl_link = song_json['location']
        # lyrics link
        self.lyrics_link = song_json['lyric']
        # artist_name
        self.artist_name = song_json['artist_name']
        # album id, name
        self.album_name = song_json['title']
Example #35
0
    def init_by_url(self,url):
        self.song_id = re.search(r'(?<=/song/)\d+', url).group(0)
        j = self.xm.read_link(url_song % self.song_id).json()
        #name
        #self.song_name = j['song']['song_name'].replace('&#039;',"'")
        self.song_name = util.decode_html(j['song']['song_name'])
        # download link
        self.dl_link = j['song']['song_location']
        # lyrics link
        self.lyrics_link = j['song']['song_lrc']
        # artist_name
        self.artist_name = j['song']['artist_name']
        # album id, name
        self.album_name = util.decode_html(j['song']['album_name'])
        self.album_id = j['song']['album_id']

        #used only for album/collection etc. create a dir to group all songs
        self.group_dir = None
        #filename  artistName_songName.mp3 and replace slash "/" with "_"
        self.filename = ((self.artist_name + u"_" if self.artist_name  else "" ) + self.song_name + u'.mp3').replace('/','_')
        
        self.abs_path = path.join(config.DOWNLOAD_DIR,self.filename)
Example #36
0
    def init_album(self):
        j = self.handler.read_link(url_album % self.album_id).json()['data']['trackList']
        j_first_song = j[0]
        #name
        self.album_name = util.decode_html(j_first_song['album_name'])
        #album logo
        self.logo = j_first_song['album_pic']
        # artist_name
        self.artist_name = j_first_song['artist']

        #description
        html = self.handler.read_link(self.url).text
        soup = BeautifulSoup(html,'html.parser')
        self.album_desc = soup.find('span', property="v:summary").text

        #handle songs
        for jsong in j:
            song = XiamiSong(self.handler, song_json=jsong)
            song.group_dir = self.artist_name + u'_' + self.album_name
            song.post_set()
            self.songs.append(song)

        d = path.dirname(self.songs[-1].abs_path)
        #creating the dir
        LOG.debug(msg.head_xm + msg.fmt_create_album_dir % d)
        util.create_dir(d)

        #download album logo images
        LOG.debug(msg.head_xm + msg.fmt_dl_album_cover % self.album_name)
        downloader.download_url(self.logo, path.join(d,'cover.' +self.logo.split('.')[-1]))

        LOG.debug(msg.head_xm + msg.fmt_save_album_desc % self.album_name)
        if self.album_desc:
            self.album_desc = re.sub(r'&lt;\s*[bB][rR]\s*/&gt;','\n',self.album_desc)
            self.album_desc = re.sub(r'&lt;.*?&gt;','',self.album_desc)
            self.album_desc = util.decode_html(self.album_desc)
            import codecs
            with codecs.open(path.join(d,'album_description.txt'), 'w', 'utf-8') as f:
                f.write(self.album_desc)
Example #37
0
    def init_album(self):
        j = self.xm.read_link(url_album % self.album_id).json()['album']
        # name
        self.album_name = util.decode_html(j['title'])
        # album logo
        self.logo = j['album_logo']
        # artist_name
        self.artist_name = j['artist_name']

        # description
        self.album_desc = j['description']

        # handle songs
        for jsong in j['songs']:
            song = XiamiSong(self.xm, song_json=jsong)
            song.group_dir = self.artist_name + u'_' + self.album_name
            song.post_set()
            self.songs.append(song)

        d = path.dirname(self.songs[-1].abs_path)
        # creating the dir
        LOG.debug(u'创建专辑目录[%s]' % d)
        util.create_dir(d)

        # download album logo images
        LOG.debug(u'下载专辑[%s]封面' % self.album_name)
        downloader.download_by_url(
            self.logo, path.join(d, 'cover.' + self.logo.split('.')[-1]))

        LOG.debug(u'保存专辑[%s]介绍' % self.album_name)
        if self.album_desc:
            self.album_desc = re.sub(
                r'&lt;\s*[bB][rR]\s*/&gt;', '\n', self.album_desc)
            self.album_desc = re.sub(r'&lt;.*?&gt;', '', self.album_desc)
            self.album_desc = util.decode_html(self.album_desc)
            import codecs
            with codecs.open(path.join(d, 'album_description.txt'), 'w', 'utf-8') as f:
                f.write(self.album_desc)
Example #38
0
def download(addon,filename,url,local,notifyFinishDialog=True,headers={}):
    util.info('Downloading %s to %s' % (url,local))
    local = xbmc.makeLegalFilename(local)
    try:
        filename = util.replace_diacritic(util.decode_html(filename))
    except:
        filename = 'Video soubor'
    icon = os.path.join(addon.getAddonInfo('path'),'icon.png')
    notify = addon.getSetting('download-notify') == 'true'
    notifyEvery = addon.getSetting('download-notify-every')
    notifyPercent = 1
    if int(notifyEvery) == 0:
        notifyPercent = 10
    if int(notifyEvery) == 1:
        notifyPercent = 5
    def callback(percent,speed,est,filename):
        if percent == 0 and speed == 0:
            try:
                xbmc.executebuiltin('XBMC.Notification(%s,%s,3000,%s)' % (xbmc.getLocalizedString(13413).encode('utf-8'),filename,icon))
            except:
               error('Unable to show notification') 
            return
        if notify:
            if percent > 0 and percent % notifyPercent == 0:
                esTime = '%ss' % est
                if est>60:
                    esTime = '%sm' % int(est/60)
                message = xbmc.getLocalizedString(24042) % percent + ' - %s KB/s %s' % (speed,esTime)
                try:
                    xbmc.executebuiltin('XBMC.Notification(%s,%s,3000,%s)'%(message.encode('utf-8'),filename,icon))
                except:
                    error('Unable to show notification')

    downloader = Downloader(callback)
    result = downloader.download(url,local,filename,headers)
    try:
        if result == True:
            if xbmc.Player().isPlaying():
                xbmc.executebuiltin('XBMC.Notification(%s,%s,8000,%s)' % (xbmc.getLocalizedString(20177),filename,icon))
            else:
                if notifyFinishDialog:
                    xbmcgui.Dialog().ok(xbmc.getLocalizedString(20177),filename)
                else:
                    xbmc.executebuiltin('XBMC.Notification(%s,%s,3000,%s)' % (xbmc.getLocalizedString(20177),filename,icon))
        else:
            xbmc.executebuiltin('XBMC.Notification(%s,%s,5000,%s)' % (xbmc.getLocalizedString(257),filename,icon))
            xbmcgui.Dialog().ok(filename,xbmc.getLocalizedString(257) +' : '+result)
    except:
        traceback.print_exc()
Example #39
0
    def init_album(self):
        j = self.xm.read_link(url_album % self.album_id).json()['album']
        #name
        self.album_name = util.decode_html(j['title'])
        #album logo
        self.logo = j['album_logo']
        # artist_name
        self.artist_name = j['artist_name']

        #description
        self.album_desc = j['description']

        #handle songs
        for jsong in j['songs']:
            song = XiamiSong(self.xm, song_json=jsong)
            song.group_dir = self.artist_name + u'_' + self.album_name
            song.post_set()
            self.songs.append(song)

        d = path.dirname(self.songs[-1].abs_path)
        #creating the dir
        LOG.debug(u'创建专辑目录[%s]' % d)
        util.create_dir(d)

        #download album logo images
        LOG.debug(u'下载专辑[%s]封面'% self.album_name)
        downloader.download_by_url(self.logo, path.join(d,'cover.' +self.logo.split('.')[-1]))

        LOG.debug(u'保存专辑[%s]介绍'% self.album_name)
        if self.album_desc:
            self.album_desc = re.sub(r'&lt;\s*[bB][rR]\s*/&gt;','\n',self.album_desc)
            self.album_desc = re.sub(r'&lt;.*?&gt;','',self.album_desc)
            self.album_desc = util.decode_html(self.album_desc)
            import codecs
            with codecs.open(path.join(d,'album_description.txt'), 'w', 'utf-8') as f:
                f.write(self.album_desc)
Example #40
0
 def list(self,url):
     if url.find('category/new-episode') == 0:
         return self.new_episodes(util.request(self._url(url)))
     result = []
     page = util.request(self._url(url))
     data = util.substr(page,'<div id=\"archive-posts\"','</div>')
     m = re.search('<a(.+?)href=\"(?P<url>[^\"]+)', data, re.IGNORECASE | re.DOTALL)
     if m:
         data = util.request(m.group('url'))
         for m in re.finditer('<a href=\"(?P<url>[^\"]+)(.+?)(<strong>|<b>)(?P<name>[^<]+)', util.substr(data,'<div class=\"entry-content','</div>'), re.IGNORECASE | re.DOTALL):
             item = self.video_item()
             item['title'] = util.decode_html(m.group('name'))
             item['url'] = m.group('url')
             self._filter(result,item)
     return result
Example #41
0
 def list_search(self, url):
     print 'list_search', url
     result = []
     data = util.request(url)
     search_data = util.substr(data, 'ul class="content"', '</ul>')
     for i in re.finditer(r'<li>(.+?)</li>', search_data, re.DOTALL):
         item = self.video_item()
         url_and_title_pattern = re.compile(
             r'<h4><a href="(?P<url>[^"]+)">(?P<title>[^<]+)</a></h4>')
         url_and_title_match = url_and_title_pattern.search(i.group(1))
         if not url_and_title_match:
             print 'cannot find title/video url in %s!' % (i.group(1))
             continue
         item['url'] = url_and_title_match.group('url')
         item['title'] = url_and_title_match.group('title')
         img_match = re.search(r'<img src="([^"]+)', i.group(1))
         if img_match:
             item['img'] = img_match.group(1)
         plot_match = re.search(r'</strong>(.+?)</p>', i.group(1),
                                re.DOTALL)
         if plot_match:
             item['plot'] = plot_match.group(1).strip()
         result.append(item)
     page_data = util.substr(data, '<div class="pagination">', '</div>')
     next_page_match = re.search(r'<li class="next"><a href="([^"]+)',
                                 page_data)
     if next_page_match:
         next_url = '%s/%s/search%s' % (MOVIES_BASE_URL, ISO_639_1_CZECH,
                                        util.decode_html(
                                            next_page_match.group(1)))
         page_number = 1
         page = re.search(r'\bpage=(\d+)', url)
         if page:
             page_number = int(page.group(1))
         next_page_number = 1
         page = re.search(r'\bpage=(\d+)', next_url)
         if page:
             next_page_number = int(page.group(1))
         if page_number > next_page_number:
             return result
         if page_number % 5 != 0:
             result += self.list_search(next_url)
         else:
             item = self.dir_item()
             item['type'] = 'next'
             item['url'] = next_url
             result.append(item)
     return result
Example #42
0
 def decode_plot(self, p):
     p = re.sub('<br[^>]*>', '', p)
     p = re.sub('<div[^>]+>', '', p)
     p = re.sub('<table.*', '', p)
     p = re.sub('</span>|<br[^>]*>|<ul>|</ul>|<hr[^>]*>', '', p)
     p = re.sub('<span[^>]*>|<p[^>]*>|<li[^>]*>', '', p)
     p = re.sub('<strong>|<a[^>]*>|<h[\d]+>', '[B]', p)
     p = re.sub('</strong>|</a>|</h[\d]+>', '[/B]', p)
     p = re.sub('</p>|</li>', '[CR]', p)
     p = re.sub('<em>', '[I]', p)
     p = re.sub('</em>', '[/I]', p)
     p = re.sub('<img[^>]+>', '', p)
     p = re.sub('\[B\]Edituj popis\[\/B\]', '', p)
     p = re.sub('\[B\]\[B\]', '[B]', p)
     p = re.sub('\[/B\]\[/B\]', '[/B]', p)
     p = re.sub('\[B\][ ]*\[/B\]', '', p)
     return util.decode_html(''.join(p)).encode('utf-8').strip()
Example #43
0
 def decode_plot(self, m):
     p = m.group('plot')
     p = re.sub('<br[^>]*>', '', p)
     p = re.sub('<div[^>]+>', '', p)
     p = re.sub('<table.*', '', p)
     p = re.sub('</span>|<br[^>]*>|<ul>|</ul>|<hr[^>]*>', '', p)
     p = re.sub('<span[^>]*>|<p[^>]*>|<li[^>]*>', '', p)
     p = re.sub('<strong>|<a[^>]*>|<h[\d]+>', '[B]', p)
     p = re.sub('</strong>|</a>|</h[\d]+>', '[/B]', p)
     p = re.sub('</p>|</li>', '[CR]', p)
     p = re.sub('<em>', '[I]', p)
     p = re.sub('</em>', '[/I]', p)
     p = re.sub('<img[^>]+>', '', p)
     p = re.sub('\[B\]Edituj popis\[\/B\]', '', p)
     p = re.sub('\[B\]\[B\]', '[B]', p)
     p = re.sub('\[/B\]\[/B\]', '[/B]', p)
     p = re.sub('\[B\][ ]*\[/B\]', '', p)
     return util.decode_html(''.join(p)).encode('utf-8').strip()
Example #44
0
 def _get_plot(self,data,local):
     data = util.substr(data,'<div id=\"tale_description\"','<div class=\"cleaner')
     p = data
     p = re.sub('<div[^>]+>','',p)
     p = re.sub('<table.*','',p)
     p = re.sub('</span>|<br[^>]*>|<ul>|</ul>|<hr[^>]*>','',p)
     p = re.sub('<span[^>]*>|<p[^>]*>|<li[^>]*>','',p)
     p = re.sub('<strong>|<a[^>]*>|<h[\d]+>','[B]',p)
     p = re.sub('</strong>|</a>|</h[\d]+>','[/B]',p)
     p = re.sub('</p>|</li>','[CR]',p)
     p = re.sub('<em>','[I]',p)
     p = re.sub('</em>','[/I]',p)
     p = re.sub('<img[^>]+>','',p)
     p = re.sub('\[B\]Edituj popis\[\/B\]','',p)
     p = re.sub('\[B\]\[B\]','[B]',p)
     p = re.sub('\[/B\]\[/B\]','[/B]',p)
     p = re.sub('\[B\][ ]*\[/B\]','',p)
     util.save_data_to_file(util.decode_html(''.join(p)).encode('utf-8'),local)
Example #45
0
 def _get_plot(self, data):
     data = util.substr(data, '<div id=\"tale_description\"',
                        '<div class=\"cleaner')
     p = data
     p = re.sub('<div[^>]+>', '', p)
     p = re.sub('<table.*', '', p)
     p = re.sub('</span>|<br[^>]*>|<ul>|</ul>|<hr[^>]*>', '', p)
     p = re.sub('<span[^>]*>|<p[^>]*>|<li[^>]*>', '', p)
     p = re.sub('<strong>|<a[^>]*>|<h[\d]+>', '[B]', p)
     p = re.sub('</strong>|</a>|</h[\d]+>', '[/B]', p)
     p = re.sub('</p>|</li>', '[CR]', p)
     p = re.sub('<em>', '[I]', p)
     p = re.sub('</em>', '[/I]', p)
     p = re.sub('<img[^>]+>', '', p)
     p = re.sub('\[B\]Edituj popis\[\/B\]', '', p)
     p = re.sub('\[B\]\[B\]', '[B]', p)
     p = re.sub('\[/B\]\[/B\]', '[/B]', p)
     p = re.sub('\[B\][ ]*\[/B\]', '', p)
     return util.decode_html(''.join(p)).encode('utf-8')
Example #46
0
def _plot(page):
	data = util.substr(page,'<div id=\"plots\"','</ul>')
	m = _match(re.search('<ul>([^$]+)',data))
	if m:
		p = re.sub('</li>','[CR]',m)
		p = re.sub('<br[^>]*>','[CR]',p)
		p = re.sub('<(li|div|span)[^>]*>','',p)
		p = re.sub('</div>|</span>','',p)
		p = re.sub('<a[^>]*>','[B]',p)
		p = re.sub('</a>','[/B]',p)
		p = re.sub('<em>','[I]',p)
		p = re.sub('</em>','[/I]',p)
		p = re.sub('<strong>','[B]',p)
		p = re.sub('</strong>','[/B]',p)
		p = re.sub('<img[^>]+>','',p)
		p = re.sub('[\ \t\r\n]+',' ',p)
		p = util.decode_html(p)
		return p
	return __empty_info['plot']
 def decode_plot(self, m):
 	p = m.group('plot')
     p = re.sub('<br[^>]*>', '', p)
     p = re.sub('<div[^>]+>', '', p)
     p = re.sub('<table.*', '', p)
     p = re.sub('</span>|<br[^>]*>|<ul>|</ul>|<hr[^>]*>', '', p)
     p = re.sub('<span[^>]*>|<p[^>]*>|<li[^>]*>', '', p)
     p = re.sub('<strong>|<a[^>]*>|<h[\d]+>', '[B]', p)
     p = re.sub('</strong>|</a>|</h[\d]+>', '[/B]', p)
     p = re.sub('</p>|</li>', '[CR]', p)
     p = re.sub('<em>', '[I]', p)
     p = re.sub('</em>', '[/I]', p)
     p = re.sub('<img[^>]+>', '', p)
     p = re.sub('\[B\]Edituj popis\[\/B\]', '', p)
     p = re.sub('\[B\]\[B\]', '[B]', p)
     p = re.sub('\[/B\]\[/B\]', '[/B]', p)
     p = re.sub('\[B\][ ]*\[/B\]', '', p)
     plot = util.decode_html(''.join(p)).encode('utf-8').strip()
     rating = self.format_rating(m)
     return "{0}\n{1}".format(rating, plot)
Example #48
0
    def init_album(self):
        # album json
        js = self.handler.read_link(url_album % self.album_id).json()["album"]
        # name
        self.album_name = util.decode_html(js["name"])
        # album logo
        self.logo = js["picUrl"]
        # artist_name
        self.artist_name = js["artists"][0]["name"]
        # handle songs
        for jsong in js["songs"]:
            song = NeteaseSong(self.handler, song_json=jsong)
            song.group_dir = self.artist_name + u"_" + self.album_name
            song.post_set()
            self.songs.append(song)

        d = path.dirname(self.songs[-1].abs_path)
        # creating the dir
        LOG.debug(msg.head_163 + msg.fmt_create_album_dir % d)
        util.create_dir(d)

        # download album logo images
        LOG.debug(msg.head_163 + msg.fmt_dl_album_cover % self.album_name)
        downloader.download_by_url(self.logo, path.join(d, "cover." + self.logo.split(".")[-1]))
Example #49
0
    def init_album(self):
        #album json
        js = self.m163.read_link(url_album % self.album_id).json()['album']
        #name
        self.album_name = util.decode_html(js['name'])
        #album logo
        self.logo = js['picUrl']
        # artist_name
        self.artist_name = js['artists'][0]['name']
        #handle songs
        for jsong in js['songs']:
            song = NeteaseSong(self.m163, song_json=jsong)
            song.group_dir = self.artist_name + u'_' + self.album_name
            song.post_set()
            self.songs.append(song)

        d = path.dirname(self.songs[-1].abs_path)
        #creating the dir
        LOG.debug(u'创建专辑目录[%s]' % d)
        util.create_dir(d)

        #download album logo images
        LOG.debug(u'下载专辑[%s]封面'% self.album_name)
        downloader.download_by_url(self.logo, path.join(d,'cover.' +self.logo.split('.')[-1]))
    def add_video(self, name, params={}, logo='', infoLabels={}, menuItems={}):
        util.debug("_add_video")
        #util.debug("[SC] add video info: %s" % str(infoLabels))
        _infoLabels = self._extract_infolabels(infoLabels)
        name = util.decode_html(name)
        if 'Title' not in _infoLabels:
            _infoLabels['Title'] = name
        util.debug("[SC] params: %s" % str(params))
        url = sctop._create_plugin_url(params)
        if logo == '' or logo is None:
            logo = self.noImage
        li = xbmcgui.ListItem(name,
                              path=url,
                              iconImage='DefaultVideo.png',
                              thumbnailImage=logo)
        li.setInfo(type='Video', infoLabels=_infoLabels)
        mt = sctop.getMediaType()
        util.debug("[SC] item media type: %s" % mt)

        if 'selected' in infoLabels.keys():
            wnd = xbmcgui.Window(xbmcgui.getCurrentWindowId())
            util.debug("[SC] wnd: %s [%d]" %
                       (str(wnd), xbmcgui.getCurrentWindowId()))
        if 'mvideo' in infoLabels.keys():
            li.addStreamInfo('video', infoLabels['mvideo'])
        if 'maudio' in infoLabels.keys():
            li.addStreamInfo('audio', infoLabels['maudio'])
        if 'msubtitle' in infoLabels.keys():
            li.addStreamInfo('subtitle', infoLabels['msubtitle'])
        if 'art' in infoLabels.keys():
            li.setArt(infoLabels['art'])
        li.setProperty('IsPlayable', 'true')
        if 'runtime' in infoLabels.keys() and infoLabels['runtime'] > 0:
            duration = int(infoLabels['runtime']) * 60
            li.addStreamInfo('video', {'duration': duration})
        items = [(xbmc.getLocalizedString(13347), 'Action(Queue)')]

        self.setUniq(li, infoLabels)

        for mi in menuItems.keys():
            action = menuItems[mi]
            if not type(action) == type({}):
                items.append((mi, action))
            else:
                if 'action-type' in action:
                    action_type = action['action-type']
                    del action['action-type']
                    if action_type == 'list':
                        items.append((mi, 'Container.Update(%s)' %
                                      sctop._create_plugin_url(action)))
                    elif action_type == 'play':
                        items.append((mi, 'PlayMedia(%s)' %
                                      sctop._create_plugin_url(action)))
                    elif action_type == 'trailer':
                        items.append((mi, 'PlayMedia(%s)' % action['url']))
                    else:
                        items.append((mi, 'RunPlugin(%s)' %
                                      sctop._create_plugin_url(action)))
                else:
                    items.append(
                        (mi,
                         'RunPlugin(%s)' % sctop._create_plugin_url(action)))

        if len(items) > 0:
            li.addContextMenuItems(items)
        #xbmc.executebuiltin("Container.SetViewMode(515)")
        return xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                           url=url,
                                           listitem=li,
                                           isFolder=False)
Example #51
0
 def _get_plot(self,data,local):
     data = util.substr(data,'<div class=\"entry-content\"','</p>')
     m = re.search('<(strong|b)>(?P<plot>(.+?))<', data, re.IGNORECASE | re.DOTALL)
     if not m == None:
         util.save_data_to_file(util.decode_html(m.group('plot')).encode('utf-8'),local)
Example #52
0
 def _extract_infolabels(self, item):
     infoLabels = {}
     for label in ['plot', 'year', 'genre', 'rating', 'director', 'votes', 'cast', 'trailer', 'duration', 'videoid', 'videowidth']:
         if label in item.keys():
             infoLabels[label] = util.decode_html(item[label])
     return infoLabels