Ejemplo n.º 1
0
	def updateAllTagList(self):
		root = eServiceReference("2:0:1:0:0:0:0:0:0:0:" + resolveFilename(SCOPE_HDD))
		ml = MovieList(root)
		ml.load(root,None)
		xtmp = []
		xtmp.extend(ml.tags)
		self.usedTags = xtmp

		e = []+self.pretags
		for i in ml.tags:
			try:
				self.pretags.index(i)
			except ValueError:
				e.append(i)

		taglist = []
		for i in e:
				res = [ i ]
				res.append(MultiContentEntryText(pos=(5, 0), size=(500, 25), font=0, text=i))
				if self.isUsedTag(i):
					res.append(MultiContentEntryText(pos=(220, 0),size=(61, 86), font=1,text="X",color=0x00FFFF00))
				if self.isUserTag(i) :
					res.append(MultiContentEntryText(pos=(240, 0),size=(61, 86), font=1,text="X",color=0x00FF0000))#red
				if self.isPreTag(i):
					res.append(MultiContentEntryText(pos=(260, 0),size=(61, 86), font=1,text="X",color=0x000000FF))#blue

				taglist.append(res)

		taglist.sort()
		self["aTaglist"].l.setList(taglist)
Ejemplo n.º 2
0
	def updateAllTagList(self):
		root = eServiceReference("2:0:1:0:0:0:0:0:0:0:" + resolveFilename(SCOPE_HDD))
		ml = MovieList(root)
		ml.load(root, None)
		xtmp = []
		xtmp.extend(ml.tags)
		self.usedTags = xtmp

		e = [] + self.pretags
		for i in ml.tags:
			try:
				self.pretags.index(i)
			except ValueError:
				e.append(i)

		taglist = []
		for i in e:
			res = [i]
			res.append(MultiContentEntryText(pos=(5, 0), size=(500, 25), font=0, text=i))
			if self.isUsedTag(i):
				res.append(MultiContentEntryText(pos=(220, 0), size=(20, 25), font=1, text="X", color=0x00FFFF00)) #yellow
			if self.isUserTag(i):
				res.append(MultiContentEntryText(pos=(240, 0), size=(20, 25), font=1, text="X", color=0x00FF0000)) #red
			if self.isPreTag(i):
				res.append(MultiContentEntryText(pos=(260, 0), size=(20, 25), font=1, text="X", color=0x0000FF00)) #green

			taglist.append(res)

		taglist.sort()
		self["aTaglist"].l.setList(taglist)
Ejemplo n.º 3
0
	def updateAllTagList(self):
		root = eServiceReference("2:0:1:0:0:0:0:0:0:0:" + resolveFilename(SCOPE_HDD))
		ml = MovieList(root)
		ml.load(root,None)
		xtmp = []
		xtmp.extend(ml.tags)
		self.usedTags = xtmp

		e = self.pretags + [ x for x in ml.tags if x not in self.pretags ]
		
		taglist = []
		for i in e:
			taglist.append(self.getFlags(i))
		taglist.sort()
		self["aTaglist"].setList(taglist)
Ejemplo n.º 4
0
def getMovieList(directory=None, tag=None, rargs=None):
    movieliste = []

    if directory == None:
        directory = config.usage.default_path.value

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

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

    bookmarklist = [
        x for x in walk(directory).next()[1]
        if (x[0] != '.' and not islink(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)

    #??? tagfilter = []

    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

            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 ""

            filename = '/'.join(serviceref.toString().split("/")[1:])
            servicename = ServiceReference(
                serviceref).getServiceName().replace('\xc2\x86', '').replace(
                    '\xc2\x87', '')
            movie = {}
            filename = '/' + filename
            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

            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"}
Ejemplo n.º 5
0
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}
Ejemplo n.º 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)

	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
Ejemplo n.º 7
0
def getMovieSearchList(rargs=None, locations=None):
    movieliste = []
    tag = None
    directory = None
    fields = None
    short = None
    extended = None
    searchstr = None

    if rargs:
        searchstr = getUrlArg2(rargs, "find")
        short = getUrlArg2(rargs, "short")
        extended = getUrlArg2(rargs, "extended")

    s = {'title': str(searchstr)}
    if short is not None:
        s['shortDesc'] = str(searchstr)
    if extended is not None:
        s['extDesc'] = str(searchstr)

    movielist = MovieList(None)
    vdir_list = []
    for x in moviedb.searchContent(s, 'ref', query_type="OR",
                                   exactmatch=False):
        vdir_list.append(eServiceReference(x[0]))
    root = eServiceReference("2:0:1:0:0:0:0:0:0:0:" + "/")
    movielist.load(root, None)
    movielist.reload(root=None, vdir=5, vdir_list=vdir_list)

    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:
            movie['begintime'] = FuzzyTime2(rtime)

        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 = six.ensure_str(b''.join(handle.readlines()))

            event = info.getEvent(serviceref)
            extended_description = event and event.getExtendedDescription(
            ) or ""
            if extended_description == '' and txtdesc != '':
                extended_description = txtdesc
            movie['descriptionExtended'] = ConvertDesc(extended_description)
            desc = info.getInfoString(serviceref,
                                      iServiceInformation.sDescription)
            movie['description'] = ConvertDesc(desc)

        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)

    return {"movies": movieliste, "locations": []}
Ejemplo n.º 8
0
def getMovieList(rargs=None, locations=None):
    movieliste = []
    tag = None
    directory = None
    fields = None
    bookmarklist = []

    if rargs:
        tag = getUrlArg2(rargs, "tag")
        directory = getUrlArg2(rargs, "dirname")
        fields = getUrlArg2(rargs, "fields")

    if directory is None:
        directory = defaultMoviePath()
    else:
        if not PY3:
            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]
    brecursive = False
    if rargs and b"recursive" in list(rargs.keys()):
        brecursive = True
        dirs = []
        locations = []
        if PY3:
            from glob import glob
            for subdirpath in glob(directory + "**/", recursive=True):
                locations.append(subdirpath)
                subdirpath = subdirpath[len(directory):]
                dirs.append(subdirpath)
        else:
            # FIXME SLOW!!!
            for subdirpath in [x[0] for x in os.walk(directory)]:
                locations.append(subdirpath)
                subdirpath = subdirpath[len(directory):]
                dirs.append(subdirpath)

        for f in sorted(dirs):
            if f != '':
                if f[-1] != "/":
                    f += "/"
                ff = eServiceReference(MOVIE_LIST_SREF_ROOT + directory + f)
                folders.append(ff)
    else:
        # 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

                # BAD fix
                _serviceref = serviceref.toString().replace('%25', '%')
                length_minutes = 0
                txtdesc = ""
                filename = '/'.join(_serviceref.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,
                    '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,
                }

                if rtime > 0:
                    movie['begintime'] = FuzzyTime2(rtime)

                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 = six.ensure_str(b''.join(
                                handle.readlines()))

                    event = info.getEvent(serviceref)
                    extended_description = event and event.getExtendedDescription(
                    ) or ""
                    if extended_description == '' and txtdesc != '':
                        extended_description = txtdesc
                    movie['descriptionExtended'] = ConvertDesc(
                        extended_description)

                    desc = info.getInfoString(serviceref,
                                              iServiceInformation.sDescription)
                    movie['description'] = ConvertDesc(desc)

                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,
            "recursive": brecursive
        }

    if brecursive:
        return {
            "movies": movieliste,
            "locations": locations,
            "directory": directory,
            "bookmarks": bookmarklist,
            "recursive": brecursive
        }
    else:
        return {
            "movies": movieliste,
            "locations": locations,
            "recursive": brecursive
        }
Ejemplo n.º 9
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
Ejemplo n.º 10
0
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
Ejemplo n.º 11
0
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
Ejemplo n.º 12
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
Ejemplo n.º 13
0
def getMovieList(directory=None, tag=None, rargs=None):
	movieliste = []
	
	if directory == None:
		directory = config.usage.default_path.value
	
	if directory[-1] != "/":
		directory += "/"
		
	root = eServiceReference("2:0:1:0:0:0:0:0:0:0:" + directory)

	bookmarklist=[x for x in walk(directory).next()[1] if (x[0] != '.' and not islink(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)

	#??? tagfilter = []
	
	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

			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 ""

			filename = '/'.join(serviceref.toString().split("/")[1:])
			servicename = ServiceReference(serviceref).getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')
			movie = {}
			filename = '/'+filename
			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
		
			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"
		}
Ejemplo n.º 14
0
def getMovieList(directory=None, tag=None):
	movieliste = []
	
	if directory == None:
		directory = config.usage.default_path.value
	
	if directory[-1] != "/":
		directory += "/"
		
	root = eServiceReference("2:0:1:0:0:0:0:0:0:0:" + directory)

	bookmarklist=[x for x in walk(directory).next()[1] if (x[0] != '.' and not islink(directory+'/'+x))]
	bookmarklist.sort()
	
	tagfilter = []
	
	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

		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 ""

		filename = '/'.join(serviceref.toString().split("/")[1:])
		servicename = ServiceReference(serviceref).getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')
		movie = {}
		filename = '/'+filename
		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
		
		movieliste.append(movie)
		
	
	return { "movies": movieliste, "bookmarks": bookmarklist, "directory": directory }
Ejemplo n.º 15
0
def getMovieList(directory=None, tag=None):
    movieliste = []

    if directory == None:
        directory = config.usage.default_path.value

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

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

    bookmarklist = [
        x for x in walk(directory).next()[1]
        if (x[0] != '.' and not islink(directory + '/' + x))
    ]
    bookmarklist.sort()

    tagfilter = []

    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

        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 ""

        filename = '/'.join(serviceref.toString().split("/")[1:])
        servicename = ServiceReference(serviceref).getServiceName().replace(
            '\xc2\x86', '').replace('\xc2\x87', '')
        movie = {}
        filename = '/' + filename
        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

        movieliste.append(movie)

    return {
        "movies": movieliste,
        "bookmarks": bookmarklist,
        "directory": directory
    }
Ejemplo n.º 16
0
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
	}