Esempio n. 1
0
def makeSTRM(filepath, filename, url):
    utils.addon_log('makeSTRM')

    mtime = None
    try:
        filename = stringUtils.cleanStrmFilesys(filename.decode("utf-8"))
        filepath = stringUtils.multiRstrip(filepath.decode("utf-8"))
        filepath = completePath(os.path.join(STRM_LOC, filepath))

        if not xbmcvfs.exists(filepath):
            dirs = filepath.replace(STRM_LOC, '').split(
                "\\") if filepath.find("\\") != -1 else filepath.replace(
                    STRM_LOC, '').split("/")
            dirs = filter(None, dirs)

            filepath = STRM_LOC
            for dir in dirs:
                filepath = completePath(os.path.join(filepath, dir))
                if not xbmcvfs.exists(filepath):
                    xbmcvfs.mkdir(filepath)

        if not STRM_LOC.startswith("smb:") and not STRM_LOC.startswith('nfs:'):
            fullpath = '%s.strm' % (os.path.normpath(
                xbmc.translatePath(os.path.join(filepath, filename))))
        else:
            fullpath = '%s/%s.strm' % (filepath, filename)


#         if xbmcvfs.exists(fullpath):
#             if addon.getSetting('Clear_Strms') == 'true':
#                 x = 0 #xbmcvfs.delete(fullpath)
#             else:
#                 return fullpath

        if True:
            if fullpath.find('Audio') > 0:
                try:
                    if xbmcvfs.exists(fullpath.decode("utf-8")):
                        return fullpath, None
                except:
                    if xbmcvfs.exists(fullpath.encode("utf-8")):
                        return fullpath, None

            try:
                fullpath = fullpath.decode("utf-8")
                fle = xbmcvfs.File(fullpath, 'w')
            except:
                fullpath = fullpath.encode("utf-8")
                fle = xbmcvfs.File(fullpath, 'w')
                pass

            fle.write(bytearray(url, encoding="utf-8"))
            fle.close()
            del fle

            if fullpath.find('Audio') > 0:
                mtime = os.path.getmtime(fullpath)

    except IOError as (errno, strerror):
        print("I/O error({0}): {1}").format(errno, strerror)
Esempio n. 2
0
def getEpisode(episode_item, strm_name, strm_type, j=0, pagesDone=0):
    episode = None

    utils.addon_log("detailInfo: %s" % (episode_item))
    file = episode_item.get('file', None)
    episode = episode_item.get('episode', -1)
    season = episode_item.get('season', -1)
    strSeasonEpisode = 's%de%d' % (season, episode)
    showtitle = episode_item.get('showtitle', None)
    provider = getProvider(file)

    if showtitle is not None and showtitle != "" and strm_type != "":
        path = os.path.join(
            strm_type, stringUtils.cleanStrmFilesys(showtitle)
        ) if strm_name.find('++RenamedTitle++') == -1 else os.path.join(
            strm_type,
            stringUtils.cleanStrmFilesys(stringUtils.getStrmname(strm_name)))
        episode = {
            'path': path,
            'strSeasonEpisode': strSeasonEpisode,
            'url': file,
            'tvShowTitle': showtitle,
            'provider': provider
        } if strm_name.find('++RenamedTitle++') == -1 else {
            'path': path,
            'strSeasonEpisode': strSeasonEpisode,
            'url': file,
            'tvShowTitle': stringUtils.getStrmname(strm_name),
            'provider': provider
        }

        if addon.getSetting('Link_Type') == '0':
            episode = kodiDB.writeShow(episode)

        if episode is not None:
            strm_link = 'plugin://%s/?url=plugin&mode=10&mediaType=show&episode=%s&showid=%d|%s' % (
                addon_id, episode.get('strSeasonEpisode'),
                episode.get('showID'), episode.get('tvShowTitle')
            ) if addon.getSetting('Link_Type') == '0' else episode.get('url')
            fileSys.writeSTRM(episode.get('path'),
                              episode.get('strSeasonEpisode'), strm_link)

    return pagesDone
Esempio n. 3
0
def getEpisode(episode_item, strm_name, strm_type, j=0, pagesDone=0):
    episode = None
    try:
        utils.addon_log("detailInfo: " + str(episode_item))
        file = episode_item.get('file', None)
        episode = episode_item.get('episode', -1)
        season = episode_item.get('season', -1)
        strSeasonEpisode = 's' + str(season) + 'e' + str(episode)
        showtitle = episode_item.get('showtitle', None)
        provider = getProvider(file)

        if showtitle is not None and showtitle != "" and strm_type != "":
            path = os.path.join(strm_type, stringUtils.cleanStrmFilesys(showtitle))
            episode = {'path': path, 'strSeasonEpisode': strSeasonEpisode, 'url': file, 'tvShowTitle': showtitle, 'provider': provider}                   
    except IOError as (errno, strerror):
        print ("I/O error({0}): {1}").format(errno, strerror)
Esempio n. 4
0
def writeSong(iPathID, iAlbumID, strArtist, strTitle, iDuration, iTrack,
              tFileModTime):
    tDateAdded = datetime.datetime.fromtimestamp(
        tFileModTime) if tFileModTime else datetime.datetime.now()
    strDateAdded = tDateAdded.strftime("%Y-%m-%d %H:%M:%S")
    iYear = int(datetime.datetime.now().strftime("%Y"))
    artistCol = "strArtistDisp" if kodi_version >= 18 else "strArtists"
    strTitle = stringUtils.invCommas(strTitle)
    strFileName = stringUtils.cleanStrmFilesys(strTitle)
    strFileName += ".strm"

    selectQuery = "SELECT idSong FROM song WHERE {} LIKE '{}' AND strTitle LIKE '{}';"
    selectArgs = (artistCol, strArtist, strTitle)
    insertQuery = "INSERT INTO song (iYear, dateAdded, idAlbum, idPath, " + artistCol + ", strTitle, strFileName, iTrack, strGenres, iDuration, iTimesPlayed, iStartOffset, iEndOffset, userrating, comment, mood, votes)"
    insertQuery += " VALUES ({}, '{}', {}, {}, '{}', '{}', '{}', {}, '{}', {}, {}, {}, {}, {}, '{}', '{}', {});"
    insertArgs = (iYear, strDateAdded, iAlbumID, iPathID, strArtist, strTitle,
                  strFileName, iTrack, 'osmosis', iDuration, 0, 0, 0, 0,
                  'osmosis', 'osmosis', 0)

    return manageDbRecord(selectQuery, selectArgs, insertQuery, insertArgs)
Esempio n. 5
0
def delNotInMediaList(delList):
    for entry in delList:
        try:
            splits = entry.split('|')
            type = splits[0]
            isAudio = True if type.lower().find('audio') > -1 else False
            path = completePath(STRM_LOC) + type

            if isAudio and len(splits) > 3:
                path = completePath(
                    path) + stringUtils.cleanByDictReplacements(splits[3])

            itemPath = stringUtils.getStrmname(splits[1])
            path = completePath(
                completePath(path) + stringUtils.cleanStrmFilesys(itemPath))
            utils.addon_log("remove: %s" % path)
            xbmcvfs.rmdir(path, force=True)
            if isAudio:
                xbmc.executeJSONRPC(
                    '{"jsonrpc": "2.0", "method": "AudioLibrary.Clean", "id": 1}'
                )
        except OSError:
            print("Unable to remove: %s" % path)