def getMovieList(rargs=None, locations=None):
    movieliste = []
    tag = None
    directory = None
    fields = None
    bookmarklist = []

    if rargs and "tag" in rargs.keys():
        tag = rargs["tag"][0]

    if rargs and "dirname" in rargs.keys():
        directory = rargs["dirname"][0]

    if rargs and "fields" in rargs.keys():
        fields = rargs["fields"][0]

    if directory is None:
        directory = MovieSelection.defaultMoviePath()
    else:
        try:
            directory.decode('utf-8')
        except UnicodeDecodeError:
            try:
                directory = directory.decode("cp1252").encode("utf-8")
            except UnicodeDecodeError:
                directory = directory.decode("iso-8859-1").encode("utf-8")

    if not directory:
        directory = MOVIE_LIST_ROOT_FALLBACK

    if directory[-1] != "/":
        directory += "/"

    if not os.path.isdir(directory):
        return {
            "movies": [],
            "locations": [],
            "bookmarks": [],
            "directory": [],
        }

    root = eServiceReference(MOVIE_LIST_SREF_ROOT + directory)

    for item in sorted(os.listdir(directory)):
        abs_p = os.path.join(directory, item)
        if os.path.isdir(abs_p):
            bookmarklist.append(item)

    folders = [root]
    if rargs and "recursive" in rargs.keys():
        for f in bookmarklist:
            if f[-1] != "/":
                f += "/"
            ff = eServiceReference(MOVIE_LIST_SREF_ROOT + directory + f)
            folders.append(ff)

    # get all locations
    if locations is not None:
        folders = []

        for f in locations:
            if f[-1] != "/":
                f += "/"
            ff = eServiceReference(MOVIE_LIST_SREF_ROOT + f)
            folders.append(ff)

    if config.OpenWebif.parentalenabled.value:
        dir_is_protected = checkParentalProtection(directory)
    else:
        dir_is_protected = False

    if not dir_is_protected:
        for root in folders:
            movielist = MovieList(None)
            movielist.load(root, None)

            if tag is not None:
                movielist.reload(root=root, filter_tags=[tag])

            for (serviceref, info, begin, unknown) in movielist.list:
                if serviceref.flags & eServiceReference.mustDescent:
                    continue

                length_minutes = 0
                txtdesc = ""
                filename = '/'.join(serviceref.toString().split("/")[1:])
                filename = '/' + filename
                name, ext = os.path.splitext(filename)

                sourceRef = ServiceReference(
                    info.getInfoString(serviceref,
                                       iServiceInformation.sServiceref))
                rtime = info.getInfo(serviceref,
                                     iServiceInformation.sTimeCreate)

                movie = {
                    'filename':
                    filename,
                    'filename_stripped':
                    filename.split("/")[-1],
                    'serviceref':
                    serviceref.toString(),
                    'length':
                    "?:??",
                    'lastseen':
                    0,
                    'filesize_readable':
                    '',
                    'recordingtime':
                    rtime,
                    'begintime':
                    'undefined',
                    'eventname':
                    ServiceReference(serviceref).getServiceName().replace(
                        '\xc2\x86', '').replace('\xc2\x87', ''),
                    'servicename':
                    sourceRef.getServiceName().replace('\xc2\x86', '').replace(
                        '\xc2\x87', ''),
                    'tags':
                    info.getInfoString(serviceref, iServiceInformation.sTags),
                    'fullname':
                    serviceref.toString(),
                }

                if rtime > 0:
                    fuzzy_rtime = FuzzyTime(rtime)
                    movie['begintime'] = fuzzy_rtime[0] + ", " + fuzzy_rtime[1]

                try:
                    length_minutes = info.getLength(serviceref)
                except:  # noqa: E722
                    pass

                if length_minutes:
                    movie['length'] = "%d:%02d" % (length_minutes / 60,
                                                   length_minutes % 60)
                    if fields is None or 'pos' in fields:
                        movie['lastseen'] = getPosition(
                            filename + '.cuts', length_minutes)

                if fields is None or 'desc' in fields:
                    txtfile = name + '.txt'
                    if ext.lower() != '.ts' and os.path.isfile(txtfile):
                        with open(txtfile, "rb") as handle:
                            txtdesc = ''.join(handle.readlines())

                    event = info.getEvent(serviceref)
                    extended_description = event and event.getExtendedDescription(
                    ) or ""
                    if extended_description == '' and txtdesc != '':
                        extended_description = txtdesc
                    movie['descriptionExtended'] = unicode(
                        extended_description, 'utf_8',
                        errors='ignore').encode('utf_8', 'ignore')

                    desc = info.getInfoString(serviceref,
                                              iServiceInformation.sDescription)
                    movie['description'] = unicode(desc,
                                                   'utf_8',
                                                   errors='ignore').encode(
                                                       'utf_8', 'ignore')

                if fields is None or 'size' in fields:
                    size = 0
                    sz = ''

                    try:
                        size = os.stat(filename).st_size
                        if size > 1073741824:
                            sz = "%.2f %s" % ((size / 1073741824.), _("GB"))
                        elif size > 1048576:
                            sz = "%.2f %s" % ((size / 1048576.), _("MB"))
                        elif size > 1024:
                            sz = "%.2f %s" % ((size / 1024.), _("kB"))
                    except:  # noqa: E722
                        pass

                    movie['filesize'] = size
                    movie['filesize_readable'] = sz

                movieliste.append(movie)

    if locations is None:
        return {
            "movies": movieliste,
            "bookmarks": bookmarklist,
            "directory": directory
        }

    return {"movies": movieliste, "locations": locations}
Exemple #2
0
def getMovieList(directory=None, tag=None, rargs=None, locations=None):
    movieliste = []

    if directory is None:
        directory = MovieSelection.defaultMoviePath()
    if not directory:
        directory = "/media/"
    elif directory[-1] != "/":
        directory += "/"

    root = eServiceReference("2:0:1:0:0:0:0:0:0:0:" + directory)

    bookmarklist = [
        x for x in listdir(directory)
        if (x[0] != '.' and (isdir(join(directory, x)) or (
            islink(join(directory, x)) and exists(join(directory, x)))))
    ]
    bookmarklist.sort()

    folders = []
    folders.append(root)
    if rargs and "recursive" in rargs.keys():
        for f in bookmarklist:
            if f[-1] != "/":
                f += "/"
            ff = eServiceReference("2:0:1:0:0:0:0:0:0:0:" + directory + f)
            folders.append(ff)

    # get all locations
    if locations is not None:
        folders = []
        for f in locations:
            if f[-1] != "/":
                f += "/"
            ff = eServiceReference("2:0:1:0:0:0:0:0:0:0:" + f)
            folders.append(ff)

    if config.ModernWebif.parentalenabled.value:
        dir_is_protected = checkParentalProtection(directory)
    else:
        dir_is_protected = False

    import os

    if not dir_is_protected:
        for root in folders:
            movielist = MovieList(None)
            movielist.load(root, None)

            if tag != None:
                movielist.reload(root=root, filter_tags=[tag])
            #??? loadLength = True

            for (serviceref, info, begin, unknown) in movielist.list:
                if serviceref.flags & eServiceReference.mustDescent:
                    continue

                rtime = info.getInfo(serviceref,
                                     iServiceInformation.sTimeCreate)

                if rtime > 0:
                    t = FuzzyTime(rtime)
                    begin_string = t[0] + ", " + t[1]
                else:
                    begin_string = "undefined"

                try:
                    Len = info.getLength(serviceref)
                except:
                    Len = None

                filename = '/'.join(serviceref.toString().split("/")[1:])
                filename = '/' + filename
                pos = getPosition(filename + '.cuts', Len)

                # get txt
                name, ext = os.path.splitext(filename)
                ext = ext.lower()

                txtdesc = ""

                if ext != 'ts':
                    txtfile = name + '.txt'
                    if fileExists(txtfile):
                        txtlines = open(txtfile).readlines()
                        txtdesc = ""
                        for line in txtlines:
                            txtdesc += line

                if Len > 0:
                    Len = "%d:%02d" % (Len / 60, Len % 60)
                else:
                    Len = "?:??"

                sourceERef = info.getInfoString(
                    serviceref, iServiceInformation.sServiceref)
                sourceRef = ServiceReference(sourceERef)
                event = info.getEvent(serviceref)
                ext = event and event.getExtendedDescription() or ""

                if ext == '' and txtdesc != '':
                    ext = txtdesc

                servicename = ServiceReference(
                    serviceref).getServiceName().replace('\xc2\x86',
                                                         '').replace(
                                                             '\xc2\x87', '')
                movie = {}
                movie['filename'] = filename
                movie['filename_stripped'] = filename.split("/")[-1]
                movie['eventname'] = servicename
                movie['description'] = info.getInfoString(
                    serviceref, iServiceInformation.sDescription)
                movie['begintime'] = begin_string
                movie['serviceref'] = serviceref.toString()
                movie['length'] = Len
                movie['tags'] = info.getInfoString(serviceref,
                                                   iServiceInformation.sTags)
                filename = filename.replace("'", "\'").replace("%", "\%")
                try:
                    movie['filesize'] = os_stat(filename).st_size
                except:
                    movie['filesize'] = 0
                movie['fullname'] = serviceref.toString()
                movie['descriptionExtended'] = ext
                movie['servicename'] = sourceRef.getServiceName().replace(
                    '\xc2\x86', '').replace('\xc2\x87', '')
                movie['recordingtime'] = rtime
                movie['lastseen'] = pos
                movieliste.append(movie)

    if locations == None:
        ml = {
            "movies": movieliste,
            "bookmarks": bookmarklist,
            "directory": directory
        }
    else:
        ml = {"movies": movieliste, "locations": locations}
    return ml
Exemple #3
0
def getMovieList(directory=None, tag=None, rargs=None, locations=None):
	movieliste = []

	if directory is None:
		directory = MovieSelection.defaultMoviePath()
	if not directory:
		directory = "/media/"
	elif directory[-1] != "/":
		directory += "/"

	root = eServiceReference("2:0:1:0:0:0:0:0:0:0:" + directory)

	bookmarklist=[x for x in listdir(directory) if (x[0] != '.' and (isdir(join(directory, x)) or (islink(join(directory, x)) and exists(join(directory, x)))))]
	bookmarklist.sort()

	folders = []
	folders.append(root)
	if rargs and "recursive" in rargs.keys():
		for f in bookmarklist:
			if f[-1] != "/":
				f += "/"
			ff = eServiceReference("2:0:1:0:0:0:0:0:0:0:" + directory + f)
			folders.append(ff)

	# get all locations
	if locations is not None:
		folders = []
		for f in locations:
			if f[-1] != "/":
				f += "/"
			ff = eServiceReference("2:0:1:0:0:0:0:0:0:0:" + f)
			folders.append(ff)

	if config.ModernWebif.parentalenabled.value:
		dir_is_protected = checkParentalProtection(directory)
	else:
		dir_is_protected = False

	import os

	if not dir_is_protected:
		for root in folders:
			movielist = MovieList(None)
			movielist.load(root, None)

			if tag != None:
				movielist.reload(root=root, filter_tags=[tag])
			#??? loadLength = True

			for (serviceref, info, begin, unknown) in movielist.list:
				if serviceref.flags & eServiceReference.mustDescent:
					continue

				rtime = info.getInfo(serviceref, iServiceInformation.sTimeCreate)

				if rtime > 0:
					t = FuzzyTime(rtime)
					begin_string = t[0] + ", " + t[1]
				else:
					begin_string = "undefined"

				try:
					Len = info.getLength(serviceref)
				except:
					Len = None

				filename = '/'.join(serviceref.toString().split("/")[1:])
				filename = '/'+filename
				pos = getPosition(filename + '.cuts', Len)
				
				# get txt
				name, ext = os.path.splitext(filename)
				ext = ext.lower()
				
				txtdesc = ""
				
				if ext != 'ts':
					txtfile = name + '.txt'
					if fileExists(txtfile):
						txtlines = open(txtfile).readlines()
						txtdesc = ""
						for line in txtlines:
							txtdesc += line

				if Len > 0:
					Len = "%d:%02d" % (Len / 60, Len % 60)
				else:
					Len = "?:??"

				sourceERef = info.getInfoString(serviceref, iServiceInformation.sServiceref)
				sourceRef = ServiceReference(sourceERef)
				event = info.getEvent(serviceref)
				ext = event and event.getExtendedDescription() or ""

				if ext == '' and txtdesc != '':
					ext = txtdesc

				servicename = ServiceReference(serviceref).getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')
				movie = {}
				movie['filename'] = filename
				movie['filename_stripped'] = filename.split("/")[-1]
				movie['eventname'] = servicename
				movie['description'] = info.getInfoString(serviceref, iServiceInformation.sDescription)
				movie['begintime'] = begin_string
				movie['serviceref'] = serviceref.toString()
				movie['length'] = Len
				movie['tags'] = info.getInfoString(serviceref, iServiceInformation.sTags)
				filename = filename.replace("'","\'").replace("%","\%")
				try:
					movie['filesize'] = os_stat(filename).st_size
				except:
					movie['filesize'] = 0
				movie['fullname'] = serviceref.toString()
				movie['descriptionExtended'] = ext
				movie['servicename'] = sourceRef.getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')
				movie['recordingtime'] = rtime
				movie['lastseen'] = pos
				movieliste.append(movie)

	if locations == None:
		ml = { "movies": movieliste, "bookmarks": bookmarklist, "directory": directory }
	else:
		ml = { "movies": movieliste, "locations": locations}
	return ml
def getMovieList(rargs=None, locations=None):
    movieliste = []

    tag = None
    if rargs and "tag" in rargs.keys():
        tag = rargs["tag"][0]

    directory = None
    if rargs and "dirname" in rargs.keys():
        directory = rargs["dirname"][0]

    fields = None
    if rargs and "fields" in rargs.keys():
        fields = rargs["fields"][0]
    else:
        fields = 'pos,size,desc'

    if directory is None:
        directory = MovieSelection.defaultMoviePath()
    else:
        directory = unquote(directory)
        try:
            directory.decode('utf-8')
        except UnicodeDecodeError:
            try:
                directory = directory.decode("cp1252").encode("utf-8")
            except UnicodeDecodeError:
                directory = directory.decode("iso-8859-1").encode("utf-8")

    if not directory:
        directory = "/media/"
    elif directory[-1] != "/":
        directory += "/"

    root = eServiceReference("2:0:1:0:0:0:0:0:0:0:" + directory)

    bookmarklist = [
        x for x in listdir(directory)
        if (x[0] != '.' and (isdir(join(directory, x)) or (
            islink(join(directory, x)) and exists(join(directory, x)))))
    ]
    bookmarklist.sort()

    folders = []
    folders.append(root)
    if rargs and "recursive" in rargs.keys():
        for f in bookmarklist:
            if f[-1] != "/":
                f += "/"
            ff = eServiceReference("2:0:1:0:0:0:0:0:0:0:" + directory + f)
            folders.append(ff)

    # get all locations
    if locations is not None:
        folders = []
        for f in locations:
            if f[-1] != "/":
                f += "/"
            ff = eServiceReference("2:0:1:0:0:0:0:0:0:0:" + f)
            folders.append(ff)

    if config.OpenWebif.parentalenabled.value:
        dir_is_protected = checkParentalProtection(directory)
    else:
        dir_is_protected = False

    import os

    if not dir_is_protected:
        for root in folders:
            movielist = MovieList(None)
            movielist.load(root, None)

            if tag != None:
                movielist.reload(root=root, filter_tags=[tag])
            #??? loadLength = True

            for (serviceref, info, begin, unknown) in movielist.list:
                if serviceref.flags & eServiceReference.mustDescent:
                    continue

                rtime = info.getInfo(serviceref,
                                     iServiceInformation.sTimeCreate)

                if rtime > 0:
                    t = FuzzyTime(rtime)
                    begin_string = t[0] + ", " + t[1]
                else:
                    begin_string = "undefined"

                try:
                    Len = info.getLength(serviceref)
                except:
                    Len = None

                filename = '/'.join(serviceref.toString().split("/")[1:])
                filename = '/' + filename
                if 'pos' in fields:
                    pos = getPosition(filename + '.cuts', Len)

                # get txt
                name, ext = os.path.splitext(filename)
                ext = ext.lower()

                txtdesc = ""

                if 'desc' in fields and ext != 'ts':
                    txtfile = name + '.txt'
                    if fileExists(txtfile):
                        txtlines = open(txtfile).readlines()
                        txtdesc = ""
                        for line in txtlines:
                            txtdesc += line

                if Len > 0:
                    Len = "%d:%02d" % (Len / 60, Len % 60)
                else:
                    Len = "?:??"

                sourceERef = info.getInfoString(
                    serviceref, iServiceInformation.sServiceref)
                sourceRef = ServiceReference(sourceERef)
                if 'desc' in fields:
                    event = info.getEvent(serviceref)
                    ext = event and event.getExtendedDescription() or ""
                    if ext == '' and txtdesc != '':
                        ext = txtdesc

                if 'desc' in fields:
                    desc = info.getInfoString(serviceref,
                                              iServiceInformation.sDescription)
                servicename = ServiceReference(
                    serviceref).getServiceName().replace('\xc2\x86',
                                                         '').replace(
                                                             '\xc2\x87', '')
                movie = {}
                movie['filename'] = filename
                movie['filename_stripped'] = filename.split("/")[-1]
                movie['eventname'] = servicename
                if 'desc' in fields:
                    movie['description'] = unicode(desc,
                                                   'utf_8',
                                                   errors='ignore').encode(
                                                       'utf_8', 'ignore')
                movie['begintime'] = begin_string
                movie['serviceref'] = serviceref.toString()
                movie['length'] = Len
                movie['tags'] = info.getInfoString(serviceref,
                                                   iServiceInformation.sTags)
                movie['filesize_readable'] = ''
                if 'size' in fields:
                    filename = filename.replace("'", "\'").replace("%", "\%")
                    size = 0
                    try:
                        size = os_stat(filename).st_size
                        sz = ''
                        if size > 1073741824:
                            sz = "%.2f %s" % ((size / 1073741824.), _("GB"))
                        elif size > 1048576:
                            sz = "%.2f %s" % ((size / 1048576.), _("MB"))
                        elif size > 1024:
                            sz = "%.2f %s" % ((size / 1024.), _("kB"))
                    except:
                        size = 0
                    movie['filesize'] = size
                    movie['filesize_readable'] = sz
                movie['fullname'] = serviceref.toString()
                if 'desc' in fields:
                    movie['descriptionExtended'] = unicode(
                        ext, 'utf_8',
                        errors='ignore').encode('utf_8', 'ignore')
                movie['servicename'] = sourceRef.getServiceName().replace(
                    '\xc2\x86', '').replace('\xc2\x87', '')
                movie['recordingtime'] = rtime
                if 'pos' in fields:
                    movie['lastseen'] = pos
                movieliste.append(movie)

    if locations == None:
        ml = {
            "movies": movieliste,
            "bookmarks": bookmarklist,
            "directory": directory
        }
    else:
        ml = {"movies": movieliste, "locations": locations}
    return ml
def getMovieList(directory=None, tag=None, rargs=None, locations=None):
    movieliste = []

    if directory is None:
        directory = MovieSelection.defaultMoviePath()
    else:
        directory = unquote(directory)
        try:
            directory.decode("utf-8")
        except UnicodeDecodeError:
            try:
                directory = directory.decode("cp1252").encode("utf-8")
            except UnicodeDecodeError:
                directory = directory.decode("iso-8859-1").encode("utf-8")

    if not directory:
        directory = "/media/"
    elif directory[-1] != "/":
        directory += "/"

    root = eServiceReference("2:0:1:0:0:0:0:0:0:0:" + directory)

    bookmarklist = [
        x
        for x in listdir(directory)
        if (x[0] != "." and (isdir(join(directory, x)) or (islink(join(directory, x)) and exists(join(directory, x)))))
    ]
    bookmarklist.sort()

    folders = []
    folders.append(root)
    if rargs and "recursive" in rargs.keys():
        for f in bookmarklist:
            if f[-1] != "/":
                f += "/"
            ff = eServiceReference("2:0:1:0:0:0:0:0:0:0:" + directory + f)
            folders.append(ff)

            # get all locations
    if locations is not None:
        folders = []
        for f in locations:
            if f[-1] != "/":
                f += "/"
            ff = eServiceReference("2:0:1:0:0:0:0:0:0:0:" + f)
            folders.append(ff)

    if config.OpenWebif.parentalenabled.value:
        dir_is_protected = checkParentalProtection(directory)
    else:
        dir_is_protected = False

    import os

    if not dir_is_protected:
        for root in folders:
            movielist = MovieList(None)
            movielist.load(root, None)

            if tag != None:
                movielist.reload(root=root, filter_tags=[tag])
                # ??? loadLength = True

            for (serviceref, info, begin, unknown) in movielist.list:
                if serviceref.flags & eServiceReference.mustDescent:
                    continue

                rtime = info.getInfo(serviceref, iServiceInformation.sTimeCreate)

                if rtime > 0:
                    t = FuzzyTime(rtime)
                    begin_string = t[0] + ", " + t[1]
                else:
                    begin_string = "undefined"

                try:
                    Len = info.getLength(serviceref)
                except:
                    Len = None

                filename = "/".join(serviceref.toString().split("/")[1:])
                filename = "/" + filename
                pos = getPosition(filename + ".cuts", Len)

                # get txt
                name, ext = os.path.splitext(filename)
                ext = ext.lower()

                txtdesc = ""

                if ext != "ts":
                    txtfile = name + ".txt"
                    if fileExists(txtfile):
                        txtlines = open(txtfile).readlines()
                        txtdesc = ""
                        for line in txtlines:
                            txtdesc += line

                if Len > 0:
                    Len = "%d:%02d" % (Len / 60, Len % 60)
                else:
                    Len = "?:??"

                sourceERef = info.getInfoString(serviceref, iServiceInformation.sServiceref)
                sourceRef = ServiceReference(sourceERef)
                event = info.getEvent(serviceref)
                ext = event and event.getExtendedDescription() or ""

                if ext == "" and txtdesc != "":
                    ext = txtdesc

                desc = info.getInfoString(serviceref, iServiceInformation.sDescription)
                servicename = (
                    ServiceReference(serviceref).getServiceName().replace("\xc2\x86", "").replace("\xc2\x87", "")
                )
                movie = {}
                movie["filename"] = filename
                movie["filename_stripped"] = filename.split("/")[-1]
                movie["eventname"] = servicename
                movie["description"] = unicode(desc, "utf_8", errors="ignore").encode("utf_8", "ignore")
                movie["begintime"] = begin_string
                movie["serviceref"] = serviceref.toString()
                movie["length"] = Len
                movie["tags"] = info.getInfoString(serviceref, iServiceInformation.sTags)
                filename = filename.replace("'", "'").replace("%", "\%")
                try:
                    movie["filesize"] = os_stat(filename).st_size
                except:
                    movie["filesize"] = 0
                movie["fullname"] = serviceref.toString()
                movie["descriptionExtended"] = unicode(ext, "utf_8", errors="ignore").encode("utf_8", "ignore")
                movie["servicename"] = sourceRef.getServiceName().replace("\xc2\x86", "").replace("\xc2\x87", "")
                movie["recordingtime"] = rtime
                movie["lastseen"] = pos
                movieliste.append(movie)

    if locations == None:
        ml = {"movies": movieliste, "bookmarks": bookmarklist, "directory": directory}
    else:
        ml = {"movies": movieliste, "locations": locations}
    return ml
Exemple #6
0
def getMovieList(directory=None, tag=None, rargs=None, locations=None):
    movieliste = []

    if directory is None:
        directory = MovieSelection.defaultMoviePath()
    if not directory:
        directory = "/media/"
    elif directory[-1] != "/":
        directory += "/"

    root = eServiceReference("2:0:1:0:0:0:0:0:0:0:" + directory)

    bookmarklist = [
        x
        for x in listdir(directory)
        if (x[0] != "." and (isdir(join(directory, x)) or (islink(join(directory, x)) and exists(join(directory, x)))))
    ]
    bookmarklist.sort()

    folders = []
    folders.append(root)
    if rargs and "recursive" in rargs.keys():
        for f in bookmarklist:
            if f[-1] != "/":
                f += "/"
            ff = eServiceReference("2:0:1:0:0:0:0:0:0:0:" + directory + f)
            folders.append(ff)

            # get all locations
    if locations is not None:
        folders = []
        for f in locations:
            if f[-1] != "/":
                f += "/"
            ff = eServiceReference("2:0:1:0:0:0:0:0:0:0:" + f)
            folders.append(ff)

    for root in folders:
        movielist = MovieList(None)
        movielist.load(root, None)

        if tag != None:
            movielist.reload(root=root, filter_tags=[tag])
            # ??? loadLength = True

        for (serviceref, info, begin, unknown) in movielist.list:
            if serviceref.flags & eServiceReference.mustDescent:
                continue

            rtime = info.getInfo(serviceref, iServiceInformation.sTimeCreate)

            if rtime > 0:
                t = FuzzyTime(rtime)
                begin_string = t[0] + ", " + t[1]
            else:
                begin_string = "undefined"

            try:
                Len = info.getLength(serviceref)
            except:
                Len = None

            filename = "/".join(serviceref.toString().split("/")[1:])
            filename = "/" + filename
            pos = getPosition(filename + ".cuts", Len)

            if Len > 0:
                Len = "%d:%02d" % (Len / 60, Len % 60)
            else:
                Len = "?:??"

            sourceERef = info.getInfoString(serviceref, iServiceInformation.sServiceref)
            sourceRef = ServiceReference(sourceERef)
            event = info.getEvent(serviceref)
            ext = event and event.getExtendedDescription() or ""

            servicename = ServiceReference(serviceref).getServiceName().replace("\xc2\x86", "").replace("\xc2\x87", "")
            movie = {}
            movie["filename"] = filename
            movie["filename_stripped"] = filename.split("/")[-1]
            movie["eventname"] = servicename
            movie["description"] = info.getInfoString(serviceref, iServiceInformation.sDescription)
            movie["begintime"] = begin_string
            movie["serviceref"] = serviceref.toString()
            movie["length"] = Len
            movie["tags"] = info.getInfoString(serviceref, iServiceInformation.sTags)
            filename = filename.replace("'", "'").replace("%", "\%")
            try:
                movie["filesize"] = os_stat(filename).st_size
            except:
                movie["filesize"] = 0
            movie["fullname"] = serviceref.toString()
            movie["descriptionExtended"] = ext
            movie["servicename"] = sourceRef.getServiceName().replace("\xc2\x86", "").replace("\xc2\x87", "")
            movie["recordingtime"] = rtime
            movie["lastseen"] = pos
            movieliste.append(movie)

    if locations == None:
        ml = {"movies": movieliste, "bookmarks": bookmarklist, "directory": directory}
    else:
        ml = {"movies": movieliste, "locations": locations}
    return ml
Exemple #7
0
def getMovieList(directory=None, tag=None, rargs=None):
    movieliste = []

    if directory is None:
        directory = MovieSelection.defaultMoviePath()
    if not directory:
        directory = "/media/"
    elif directory[-1] != "/":
        directory += "/"

    root = eServiceReference("2:0:1:0:0:0:0:0:0:0:" + directory)

    bookmarklist = [
        x for x in listdir(directory)
        if (x[0] != '.' and (isdir(join(directory, x)) or (
            islink(join(directory, x)) and exists(join(directory, x)))))
    ]
    bookmarklist.sort()

    folders = []
    folders.append(root)
    if rargs and "recursive" in rargs.keys():
        for f in bookmarklist:
            if f[-1] != "/":
                f += "/"
            ff = eServiceReference("2:0:1:0:0:0:0:0:0:0:" + directory + f)
            folders.append(ff)

    for root in folders:
        movielist = MovieList(None)
        movielist.load(root, None)

        if tag != None:
            movielist.reload(root=root, filter_tags=[tag])
        #??? loadLength = True

        for (serviceref, info, begin, unknown) in movielist.list:
            if serviceref.flags & eServiceReference.mustDescent:
                continue

            rtime = info.getInfo(serviceref, iServiceInformation.sTimeCreate)

            if rtime > 0:
                t = FuzzyTime(rtime)
                begin_string = t[0] + ", " + t[1]
            else:
                begin_string = "undefined"

            try:
                Len = info.getLength(serviceref)
            except:
                Len = None

            filename = '/'.join(serviceref.toString().split("/")[1:])
            filename = '/' + filename
            pos = getPosition(filename + '.cuts', Len)

            if Len > 0:
                Len = "%d:%02d" % (Len / 60, Len % 60)
            else:
                Len = "?:??"

            sourceERef = info.getInfoString(serviceref,
                                            iServiceInformation.sServiceref)
            sourceRef = ServiceReference(sourceERef)
            event = info.getEvent(serviceref)
            ext = event and event.getExtendedDescription() or ""

            servicename = ServiceReference(
                serviceref).getServiceName().replace('\xc2\x86', '').replace(
                    '\xc2\x87', '')
            movie = {}
            movie['filename'] = filename
            movie['filename_stripped'] = filename.split("/")[-1]
            movie['eventname'] = servicename
            movie['description'] = info.getInfoString(
                serviceref, iServiceInformation.sDescription)
            movie['begintime'] = begin_string
            movie['serviceref'] = serviceref.toString()
            movie['length'] = Len
            movie['tags'] = info.getInfoString(serviceref,
                                               iServiceInformation.sTags)
            filename = filename.replace("'", "\'").replace("%", "\%")
            try:
                movie['filesize'] = os_stat(filename).st_size
            except:
                movie['filesize'] = 0
            movie['fullname'] = serviceref.toString()
            movie['descriptionExtended'] = ext
            movie['servicename'] = sourceRef.getServiceName().replace(
                '\xc2\x86', '').replace('\xc2\x87', '')
            movie['recordingtime'] = rtime
            movie['lastseen'] = pos
            movieliste.append(movie)

    ml = {
        "movies": movieliste,
        "bookmarks": bookmarklist,
        "directory": directory
    }

    if rargs and "zip" in rargs.keys():
        filename = rargs["zip"][0]
        import os
        if not os.path.exists(os.path.dirname(filename)):
            return {"result": False, "message": "zip file path not exist"}
        try:
            import json
            fd = open(filename, 'wb')
            #todo create zip using api
            #fd = gzip.GzipFile(filename=filename, mode='wb', compresslevel=9)
            fd.write(json.dumps(ml))
            fd.close()
            try:
                os.remove('%s.gz' % filename)
            except OSError:
                pass
            os.system('gzip %s' % filename)
        except (IOError, os.error), why:
            return {
                "result": False,
                "message": "create movielist zip error:%s" % why
            }
        return {"result": True, "message": "create movielist zip success"}
def getMovieList(rargs=None, locations=None):
	movieliste = []
	tag = None
	directory = None
	fields = None
	bookmarklist = []

	if rargs and "tag" in rargs.keys():
		tag = rargs["tag"][0]

	if rargs and "dirname" in rargs.keys():
		directory = rargs["dirname"][0]

	if rargs and "fields" in rargs.keys():
		fields = rargs["fields"][0]

	if directory is None:
		directory = MovieSelection.defaultMoviePath()
	else:
		try:
			directory.decode('utf-8')
		except UnicodeDecodeError:
			try:
				directory = directory.decode("cp1252").encode("utf-8")
			except UnicodeDecodeError:
				directory = directory.decode("iso-8859-1").encode("utf-8")

	if not directory:
		directory = MOVIE_LIST_ROOT_FALLBACK

	if directory[-1] != "/":
		directory += "/"

	if not os.path.isdir(directory):
		return {
			"movies": [],
			"locations": [],
			"bookmarks": [],
			"directory": [],
		}

	root = eServiceReference(MOVIE_LIST_SREF_ROOT + directory)

	for item in sorted(os.listdir(directory)):
		abs_p = os.path.join(directory, item)
		if os.path.isdir(abs_p):
			bookmarklist.append(item)

	folders = [root]
	if rargs and "recursive" in rargs.keys():
		for f in bookmarklist:
			if f[-1] != "/":
				f += "/"
			ff = eServiceReference(MOVIE_LIST_SREF_ROOT + directory + f)
			folders.append(ff)

	# get all locations
	if locations is not None:
		folders = []

		for f in locations:
			if f[-1] != "/":
				f += "/"
			ff = eServiceReference(MOVIE_LIST_SREF_ROOT + f)
			folders.append(ff)

	if config.OpenWebif.parentalenabled.value:
		dir_is_protected = checkParentalProtection(directory)
	else:
		dir_is_protected = False

	if not dir_is_protected:
		movielist = MovieList(None)
		for root in folders:
			if tag is not None:
				movielist.load(root=root, filter_tags=[tag])
			else:
				movielist.load(root=root, filter_tags=None)

			for (serviceref, info, begin, unknown) in movielist.list:
				if serviceref.flags & eServiceReference.mustDescent:
					continue

				length_minutes = 0
				txtdesc = ""
				filename = '/'.join(serviceref.toString().split("/")[1:])
				filename = '/' + filename
				name, ext = os.path.splitext(filename)

				sourceRef = ServiceReference(
					info.getInfoString(
						serviceref, iServiceInformation.sServiceref))
				rtime = info.getInfo(
					serviceref, iServiceInformation.sTimeCreate)

				movie = {
					'filename': filename,
					'filename_stripped': filename.split("/")[-1],
					'serviceref': serviceref.toString(),
					'length': "?:??",
					'lastseen': 0,
					'filesize_readable': '',
					'recordingtime': rtime,
					'begintime': 'undefined',
					'eventname': ServiceReference(serviceref).getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', ''),
					'servicename': sourceRef.getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', ''),
					'tags': info.getInfoString(serviceref, iServiceInformation.sTags),
					'fullname': serviceref.toString(),
				}

				if rtime > 0:
					fuzzy_rtime = FuzzyTime(rtime)
					movie['begintime'] = fuzzy_rtime[0] + ", " + fuzzy_rtime[1]

				try:
					length_minutes = info.getLength(serviceref)
				except:  # noqa: E722
					pass

				if length_minutes:
					movie['length'] = "%d:%02d" % (length_minutes / 60, length_minutes % 60)
					if fields is None or 'pos' in fields:
						movie['lastseen'] = _moviePlayState(filename + '.cuts', serviceref, length_minutes) or 0

				if fields is None or 'desc' in fields:
					txtfile = name + '.txt'
					if ext.lower() != '.ts' and os.path.isfile(txtfile):
						with open(txtfile, "rb") as handle:
							txtdesc = ''.join(handle.readlines())

					event = info.getEvent(serviceref)
					extended_description = event and event.getExtendedDescription() or ""
					if extended_description == '' and txtdesc != '':
						extended_description = txtdesc
					movie['descriptionExtended'] = unicode(extended_description, 'utf_8', errors='ignore').encode('utf_8', 'ignore')

					desc = info.getInfoString(serviceref, iServiceInformation.sDescription)
					movie['description'] = unicode(desc, 'utf_8', errors='ignore').encode('utf_8', 'ignore')

				if fields is None or 'size' in fields:
					size = 0
					sz = ''

					try:
						size = os.stat(filename).st_size
						if size > 1073741824:
							sz = "%.2f %s" % ((size / 1073741824.), _("GB"))
						elif size > 1048576:
							sz = "%.2f %s" % ((size / 1048576.), _("MB"))
						elif size > 1024:
							sz = "%.2f %s" % ((size / 1024.), _("kB"))
					except:  # noqa: E722
						pass

					movie['filesize'] = size
					movie['filesize_readable'] = sz

				movieliste.append(movie)
		del movielist

	if locations is None:
		return {
			"movies": movieliste,
			"bookmarks": bookmarklist,
			"directory": directory
		}

	return {
		"movies": movieliste,
		"locations": locations
	}