Ejemplo n.º 1
0
def addAlbum(contentList, strm_name='', strm_type='Other', PAGINGalbums="1"):
    albumList = []
    dirList = []
    pagesDone = 0
    file = ''
    filetype = ''
    j = 100 / (len(contentList) * int(PAGINGalbums)) if len(contentList) > 0 else 1

    if len(contentList) == 0:
        return contentList

    while pagesDone < int(PAGINGalbums):
        if not contentList[0] == "palyableSingleMedia":
            artThumb = contentList[0].get('art', {})
            aThumb = urlUtils.stripUnquoteURL(artThumb.get('thumb', ''))
                 
            for index, detailInfo in enumerate(contentList):
                art = detailInfo.get('art',{})
                file = detailInfo['file'].replace("\\\\", "\\").encode('utf-8')
                filetype = detailInfo['filetype']
                label = stringUtils.cleanLabels(detailInfo['label'].strip())
                thumb = art.get('thumb','')
                fanart = art.get('fanart','')
                description = detailInfo.get('description', '')
                track = detailInfo.get('track', 0) if detailInfo.get('track', 0) > 0 else index + 1
                duration = detailInfo.get('duration', 0)
                if duration == 0:
                    duration = 200
                
                try:
                    if filetype == 'directory':
                        dirList.append(jsonUtils.requestList(file, 'music').get('files', []))
                        continue

                    if addon.getSetting('Link_Type') == '0': 
                        link = sys.argv[0] + "?url=" + urllib.quote_plus(file) + "&mode=" + str(10) + "&name=" + urllib.quote_plus(label) + "&fanart=" + urllib.quote_plus(fanart)
                    else:
                        link = file

                    try:
                        album = detailInfo['album'].strip()
                        artist = stringUtils.cleanByDictReplacements(", ".join(artist.strip() for artist in detailInfo['artist']) if isinstance(detailInfo['artist'], (list, tuple)) else detailInfo['artist'].strip())
                        artistList = []
                        #Check for Various Artists
                        for i, sArtist in enumerate(contentList):
                            artistList.append(sArtist.get('artist'))
                        if len(artistList) > 1:
                            try:
                                if artistList[0] != artistList[1] and artistList[1] != artistList[2]:
                                    artist = 'Various Artists'
                            except IndexError:
                                if artistList[0] != artistList[1]:
                                    artist = 'Various Artists'
                        title = stringUtils.cleanByDictReplacements(detailInfo['title'].strip())
                        type = stringUtils.cleanByDictReplacements(detailInfo['type'].strip())
                        filename = stringUtils.cleanByDictReplacements(label.strip())
                    except:
                        filename = stringUtils.cleanByDictReplacements(label.strip())
                        pass

                    thisDialog.dialogeBG.update(j, ADDON_NAME + ": Writing File: ",  " Title: " + label)
                    path = os.path.join(strm_type, artist, strm_name.replace('++RenamedTitle++', ''))
                    if album and artist and label and path and link and track:  
                        albumList.append([path, label, link, album, artist, track, duration, thumb])
                    j = j + 100 / (len(contentList) * int(PAGINGalbums))
                except IOError as (errno, strerror):
                    print ("I/O error({0}): {1}").format(errno, strerror)
                except ValueError:
                    print ("No valid integer in line.")
                except:
Ejemplo n.º 2
0
def addAlbum(contentList, strm_name='', strm_type='Other', PAGINGalbums="1"):
    albumList = []
    pagesDone = 0
    file = ''
    j = 100 / (len(contentList) * int(PAGINGalbums))

    while pagesDone < int(PAGINGalbums):
        if not contentList[0] == "palyableSingleMedia":
            albumThumbnails = re.search('"thumbnail" *: *"(.*?)",',
                                        str(contentList))
            if albumThumbnails:
                aThumb = urlUtils.stripUnquoteURL(albumThumbnails.group(1))

            for detailInfo in contentList:
                detailInfo = stringUtils.removeHTMLTAGS(detailInfo)
                files = re.search('"file" *: *"(.*?)",', detailInfo)
                filetypes = re.search('"filetype" *: *"(.*?)",', detailInfo)
                labels = re.search('"label" *: *"(.*?)",', detailInfo)
                thumbnails = re.search('"thumbnail" *: *"(.*?)",', detailInfo)
                fanarts = re.search('"fanart" *: *"(.*?)",', detailInfo)
                descriptions = re.search('"description" *: *"(.*?)",',
                                         detailInfo)
                tracks = re.search('"track" *: *(.*?),', detailInfo)
                durations = re.search('"duration" *: *"(.*?)",', detailInfo)

                try:
                    if filetypes and labels and files:
                        filetype = filetypes.group(1)
                        label = (stringUtils.cleanLabels(labels.group(1)))
                        file = (files.group(1).replace("\\\\", "\\"))

                        if fanarts:
                            fanart = fanarts.group(1)
                        else:
                            fanart = ''

                        if addon.getSetting('Link_Type') == '0':
                            link = sys.argv[0] + "?url=" + urllib.quote_plus(
                                file) + "&mode=" + str(
                                    10) + "&name=" + urllib.quote_plus(
                                        label
                                    ) + "&fanart=" + urllib.quote_plus(fanart)
                        else:
                            link = file
                        if thumbnails:
                            thumb = urlUtils.stripUnquoteURL(
                                thumbnails.group(1))
                        else:
                            thumb = ""
                        if label and strm_name:
                            label = str(
                                utils.multiple_reSub(label.strip(),
                                                     dictReplacements))
                        if tracks:
                            track = tracks.group(1)
                        try:
                            album = re.search('"album" *: *"(.*?)",',
                                              detailInfo).group(1).strip()
                            try:
                                artist = utils.multiple_reSub(
                                    re.search('"artist" *: *"(.*?)",',
                                              detailInfo).group(1).strip(),
                                    dictReplacements)
                            except:
                                artist = utils.multiple_reSub(
                                    re.search('"artist"*:*."(.*?)".,',
                                              detailInfo).group(1).strip(),
                                    dictReplacements)
                            pass
                            titl = utils.multiple_reSub(
                                re.search('"title" *: *(.*?),',
                                          detailInfo).group(1).strip(),
                                dictReplacements)
                            types = utils.multiple_reSub(
                                re.search('"type" *: *(.*?),',
                                          detailInfo).group(1).strip(),
                                dictReplacements)
                            filename = utils.multiple_reSub(
                                str(label).strip(), dictReplacements)
                        except:
                            filename = utils.multiple_reSub(
                                str(label).strip(), dictReplacements)
                            pass

                        thisDialog.dialogeBG.update(
                            j, ADDON_NAME + ": Writing File: ",
                            " Title: " + label)
                        path = os.path.join(strm_type, artist.strip(),
                                            album.strip())
                        if album and artist and label and path and link and track:
                            albumList.append([
                                path,
                                label.strip(), link, album, artist, track,
                                thumb
                            ])
                        j = j + 100 / (len(contentList) * int(PAGINGalbums))
                except IOError as (errno, strerror):
                    print("I/O error({0}): {1}").format(errno, strerror)
                except ValueError:
                    print("No valid integer in line.")
                except: