def main():
    """Startup function."""
    parser = OptionParser(usage="usage: %prog [options]")
    parser.add_option(
        "--verbose",
        action="store_true",
        default=False,
        help="enable verbose output of MythTV API")
    parser.add_option(
        '-f',
        "--force",
        action="store_true",
        default=False,
        help="non-interactive mode, answer 'yes' to all questions")
    parser.add_option(
        '-t',
        "--title",
        action="store",
        type="string",
        help="limit recordings that match title")

    opts, _ = parser.parse_args()
    MythLog._setlevel('unknown' if opts.verbose else 'err')  # pylint:disable=protected-access

    try:
        backend = MythBE()
        recs = [
            r for r in list(backend.getRecordings()) if r.recgroup == 'Deleted'
        ]
        if opts.title:
            recs = [
                r for r in recs
                if re.findall(opts.title, r.title, re.IGNORECASE)
            ]
        if len(recs) == 0:
            print('no matching recordings found')
            sys.exit(0)
        if opts.force:
            undelete_all(backend, recs)
        else:
            interactive_undelete(backend, recs)
    except MythDBError as e:
        if e.name == 'DB_CREDENTIALS':
            print("ERROR: Could not find MythDB host:port OR correct login "
                  "credentials!")
            sys.exit(-1)
        else:
            raise
    sys.exit(0)
Exemple #2
0
def main():
    """Startup function."""
    parser = OptionParser(usage="usage: %prog [options]")
    parser.add_option("--verbose",
                      action="store_true",
                      default=False,
                      help="enable verbose output of MythTV API")
    parser.add_option(
        '-f',
        "--force",
        action="store_true",
        default=False,
        help="non-interactive mode, answer 'yes' to all questions")
    parser.add_option('-t',
                      "--title",
                      action="store",
                      type="string",
                      help="limit recordings that match title")

    opts, _ = parser.parse_args()
    MythLog._setlevel('unknown' if opts.verbose else 'err')  # pylint:disable=protected-access

    try:
        backend = MythBE()
        recs = [
            r for r in list(backend.getRecordings()) if r.recgroup == 'Deleted'
        ]
        if opts.title:
            recs = [
                r for r in recs
                if re.findall(opts.title, r.title, re.IGNORECASE)
            ]
        if len(recs) == 0:
            print('no matching recordings found')
            sys.exit(0)
        if opts.force:
            undelete_all(backend, recs)
        else:
            interactive_undelete(backend, recs)
    except MythDBError as e:
        if e.name == 'DB_CREDENTIALS':
            print("ERROR: Could not find MythDB host:port OR correct login "
                  "credentials!")
            sys.exit(-1)
        else:
            raise
    sys.exit(0)
Exemple #3
0
	return a.recgroup == "Movies" and (getCommMethod(a.chanid) <> -2 or a.starttime < magic)

def getChannel(chanid):
	for c in channels:
		if c.chanid == chanid:
			return c

def getCommMethod(chanid):
	c = getChannel(chanid);
	return c.commmethod


myth = MythBE()
channels = list(Channel.getAllEntries())
pending = filter(filterPMovies, myth.getPendingRecordings())
all_movies = filter(filterPMovies, myth.getRecordings())
recorded = filter(filterRMovies, all_movies)

for r in sorted(recorded, key=lambda a: a.title):

	def r_filter(a):
		return a.title == r.title

	my_rec = filter(r_filter, all_movies)

	def p_filter(a):
		for b in my_rec:
			if a.title <> b.title:
				return False

#			print "%s %d" % (a.title, len(my_rec))
Exemple #4
0
  exit()


be = None
be = MythBE()

if be == None:
  print "Backend could not be found."
  #exit()


for x in be.getRecorderList():
  print "Tuner " + str(x) + " is recording: " + str(be.getCurrentRecording(x).title)

fs = be.getFreeSpace()
print "----------------------------------"
for x in fs:
  print "Host: " + x.host
  print "\tPath: " + x.path
  print "\t\tTotal space: " + str(x.totalspace / 1024 / 1024) + "MB"
  print "\t\tFree  space: " + str(x.freespace / 1024  / 1024) + "MB"
  print "\t\tUsed  space: " + str(x.usedspace / 1024  / 1024) + "MB"
  print "----------------------------------"


prog = be.getRecordings()
prog[0].keys()
for x in prog:
  if (x.filesize <= 0):
    print x.title + " has a zero file size"
Exemple #5
0
db = None
db = MythDB()

if db == None:
    print "Database could not be open or found"
    exit()

be = None
be = MythBE()

if be == None:
    print "Backend could not be found."
    #exit()

recordings = be.getRecordings()

for r in recordings:
    filepath = filepathFromRecording(r)
    size = -1
    try:
        size = os.path.getsize(filepath) / 1024 / 1024
    except:
        size = "NaN"

    ss_filepath = filepathFromRecording(r)
    ss_size = -1
    try:
        ss_size = os.path.getsize(filepath) / 1024 / 1024
    except:
        ss_size = "NaN"
Exemple #6
0
class Recordings( Handler ):
    def __init__(self):
        self.be = MythBE()
        self.recs = {}
        self._events = [self.handleAdd, self.handleDelete, self.handleUpdate]
        for e in self._events:
            self.be.registerevent(e)

    def add(self, rec):
        # check for duplicates
        match = (str(rec.chanid),rec.recstartts.isoformat())
        if match in self.recs:
            return

        # add attributes
        rec.attr = Attr()
        ctime = rec.lastmodified.timestamp()
        rec.attr.st_ctime = ctime
        rec.attr.st_mtime = ctime
        rec.attr.st_atime = ctime
        rec.attr.st_size = rec.filesize
        rec.attr.st_mode = stat.S_IFREG | 0444

        # process name
        rec.path = rec.formatPath(self.fmt, ' ')

        # add file
        self._addCallback(rec)
        self.recs[match] = rec.attr.st_ino

    def genAttr(self, rec):
        attr = Attr()
        ctime = rec.lastmodified.timestamp()
        attr.st_ctime = ctime
        attr.st_mtime = ctime
        attr.st_atime = ctime
        attr.st_size = rec.filesize
        attr.st_mode = stat.S_IFREG | 0444
        return attr

    def getAll(self):
        for rec in self.be.getRecordings():
            self.add(rec)

    def handleAdd(self, event=None):
        if event is None:
            self._reAdd = re.compile(
                    re.escape(static.BACKEND_SEP).\
                        join(['BACKEND_MESSAGE',
                              'RECORDING_LIST_CHANGE ADD '
                                  '(?P<chanid>[0-9]*) '
                                  '(?P<starttime>[0-9-]*T[0-9:]*)',
                              'empty']))
            return self._reAdd
        LOG(LOG.FILE, 'add event received', event)

        match = self._reAdd.match(event).groups()
        if match in self.recs:
            return

        rec = self.be.getRecording(match[0], match[1])
        self.add(rec)

    def handleDelete(self, event=None):
        if event is None:
            self._reDel = re.compile(
                    re.escape(static.BACKEND_SEP).\
                        join(['BACKEND_MESSAGE',
                              'RECORDING_LIST_CHANGE DELETE '
                                  '(?P<chanid>[0-9]*) '
                                  '(?P<starttime>[0-9-]*T[0-9:]*)',
                              'empty']))
            return self._reDel
        LOG(LOG.FILE, 'delete event received', event)

        match = self._reDel.match(event).groups()
        if match not in self.recs:
            return

        self._deleteCallback(self.recs[match])
        del self.recs[match]

    def handleUpdate(self, event=None):
        if event is None:
            self._reUp = re.compile(
                    re.escape(static.BACKEND_SEP).\
                        join(['BACKEND_MESSAGE',
                              'UPDATE_FILE_SIZE '
                                  '(?P<chanid>[0-9]*) '
                                  '(?P<starttime>[0-9-]*T[0-9:]*) '
                                  '(?P<size>[0-9]*)',
                              'empty']))
            return self._reUp
        LOG(LOG.FILE, 'update event received', event)

        match = self._reUp.match(event)
        size = match.group(3)
        match = match.group(1,2)
        if match not in self.recs:
            return

        inode = self.recs[match]
        rec = self._inodeCallback(inode)
        rec.filesize = int(size)
        rec.attr.st_size = int(size)

    def setFormat(self, fmt):
        if '%' not in fmt:
            LOG(LOG.FILE, 'pulling format from database', 'mythfs.format.%s' % fmt)
            fmt = self.be.db.settings.NULL['mythfs.format.%s' % fmt]
        LOG(LOG.FILE, 'using format', fmt)
        self.fmt = fmt
Exemple #7
0
	src = get_dir(filename)

	if not src:
		print "Can't find src for %s" % movie.title
		return

	dst = d + filename
	if not simulate:
		print "before: %s" % datetime.now()

	print "%-20.20s: moving from %s to %s" % (movie.title,src, dst)

	if not simulate:
		shutil.move(src,dst)
		print "after: %s" % datetime.now()


myth = MythBE()
input = ""
progs = filter(filterMovies, myth.getRecordings())
progs = sorted(progs,cmpFileSize)

totalSize = 0
for i,p in enumerate(progs):
	totalSize += p.filesize
	print "%2d: %-35.35s (%-5s) %s" % (i,p.title,pretty_filesize(p.filesize),get_dir(p.filename.split("/")[3]))
print "Total size: %s" % pretty_filesize(totalSize)
input = raw_input("Enter some numbers or 'q' : ")
moveMovies(getIds(input),progs)
Exemple #8
0
	"The Wild One" : 2,
	"The Postman Always Rings Twice" : 2,
	"Witness for the Prosecution" : 2
	}


def findDupes(orig):  
    seen = {} 
    result = [] 
    for item in orig:
	seen[item.title] = seen.get(item.title,0) + 1 
    return dict((title,count) for title,count in seen.iteritems() if count > allowedDupes.get(title,1))

myth = MythBE()
mythDB = MythDB()

# get all recordings
recs = myth.getRecordings()

# limit to only movies that are currently recorded
recs = filter(lambda x: x.recgroup == "Movies", recs)

# limit to only ones that are recorded multiple times
recs = findDupes(recs)

# sort by title
recs = sorted(recs.iteritems(), key=operator.itemgetter(0))

for title,count in recs:
	print "%s %d" % (title,count)
Exemple #9
0
#!/usr/bin/python

# get the files to delete
# ./files.py | cut -f 1 -d " " | grep -v lock | grep var | xargs ls -lastrh

from MythTV import MythBE
import os

myth = MythBE()
allShows = myth.getRecordings()
dirs = ["/var/lib/mythtv/recordings", "/var/lib/mythtv/recordings2", "/var/lib/mythtv/recordings3", "/var/lib/mythtv/movies-group"]

showMap = {}
badFiles = []

def handleFile(dir,file):
	parts = file.split(".")
	key = parts[0]
	bad = False
	if key not in showMap:
		badFiles.append(os.path.join(dir,file))
		bad = True

		if parts[len(parts)-1] == "mpg":
			print key, file

def handleDir(dir):
	for file in os.listdir(dir):
		path = os.path.join(dir,file)
		if os.path.isdir(path):
			handleDir(path)
Exemple #10
0
if db == None:
    print "Database could not be open or found"
    exit()

be = None
be = MythBE()

if be == None:
    print "Backend could not be found."
    #exit()

for x in be.getRecorderList():
    print "Tuner " + str(x) + " is recording: " + str(
        be.getCurrentRecording(x).title)

fs = be.getFreeSpace()
print "----------------------------------"
for x in fs:
    print "Host: " + x.host
    print "\tPath: " + x.path
    print "\t\tTotal space: " + str(x.totalspace / 1024 / 1024) + "MB"
    print "\t\tFree  space: " + str(x.freespace / 1024 / 1024) + "MB"
    print "\t\tUsed  space: " + str(x.usedspace / 1024 / 1024) + "MB"
    print "----------------------------------"

prog = be.getRecordings()
prog[0].keys()
for x in prog:
    if (x.filesize <= 0):
        print x.title + " has a zero file size"
Exemple #11
0
db = None
db = MythDB()

if db == None:
  print "Database could not be open or found"
  exit()

be = None
be = MythBE()

if be == None:
  print "Backend could not be found."
  #exit()


recordings = be.getRecordings()


for r in recordings:
  filepath = filepathFromRecording(r);
  size = -1
  try:
    size = os.path.getsize(filepath) / 1024 / 1024
  except:
    size = "NaN"

  ss_filepath = filepathFromRecording(r)
  ss_size = -1
  try:
    ss_size = os.path.getsize(filepath) / 1024 / 1024
  except:
Exemple #12
0
class Recordings(Handler):
    def __init__(self):
        self.be = MythBE()
        self.recs = {}
        self._events = [self.handleAdd, self.handleDelete, self.handleUpdate]
        for e in self._events:
            self.be.registerevent(e)

    def add(self, rec):
        # check for duplicates
        match = (str(rec.chanid), rec.recstartts.isoformat())
        if match in self.recs:
            return

        # add attributes
        rec.attr = Attr()
        ctime = rec.lastmodified.timestamp()
        rec.attr.st_ctime = ctime
        rec.attr.st_mtime = ctime
        rec.attr.st_atime = ctime
        rec.attr.st_size = rec.filesize
        rec.attr.st_mode = stat.S_IFREG | 0444

        # process name
        rec.path = rec.formatPath(self.fmt, ' ')

        # add file
        self._addCallback(rec)
        self.recs[match] = rec.attr.st_ino

    def genAttr(self, rec):
        attr = Attr()
        ctime = rec.lastmodified.timestamp()
        attr.st_ctime = ctime
        attr.st_mtime = ctime
        attr.st_atime = ctime
        attr.st_size = rec.filesize
        attr.st_mode = stat.S_IFREG | 0444
        return attr

    def getAll(self):
        for rec in self.be.getRecordings():
            self.add(rec)

    def handleAdd(self, event=None):
        if event is None:
            self._reAdd = re.compile(
                    re.escape(static.BACKEND_SEP).\
                        join(['BACKEND_MESSAGE',
                              'RECORDING_LIST_CHANGE ADD '
                                  '(?P<chanid>[0-9]*) '
                                  '(?P<starttime>[0-9-]*T[0-9:]*)',
                              'empty']))
            return self._reAdd
        LOG(LOG.FILE, 'add event received', event)

        match = self._reAdd.match(event).groups()
        if match in self.recs:
            return

        rec = self.be.getRecording(match[0], match[1])
        self.add(rec)

    def handleDelete(self, event=None):
        if event is None:
            self._reDel = re.compile(
                    re.escape(static.BACKEND_SEP).\
                        join(['BACKEND_MESSAGE',
                              'RECORDING_LIST_CHANGE DELETE '
                                  '(?P<chanid>[0-9]*) '
                                  '(?P<starttime>[0-9-]*T[0-9:]*)',
                              'empty']))
            return self._reDel
        LOG(LOG.FILE, 'delete event received', event)

        match = self._reDel.match(event).groups()
        if match not in self.recs:
            return

        self._deleteCallback(self.recs[match])
        del self.recs[match]

    def handleUpdate(self, event=None):
        if event is None:
            self._reUp = re.compile(
                    re.escape(static.BACKEND_SEP).\
                        join(['BACKEND_MESSAGE',
                              'UPDATE_FILE_SIZE '
                                  '(?P<chanid>[0-9]*) '
                                  '(?P<starttime>[0-9-]*T[0-9:]*) '
                                  '(?P<size>[0-9]*)',
                              'empty']))
            return self._reUp
        LOG(LOG.FILE, 'update event received', event)

        match = self._reUp.match(event)
        size = match.group(3)
        match = match.group(1, 2)
        if match not in self.recs:
            return

        inode = self.recs[match]
        rec = self._inodeCallback(inode)
        rec.filesize = int(size)
        rec.attr.st_size = int(size)

    def setFormat(self, fmt):
        if '%' not in fmt:
            LOG(LOG.FILE, 'pulling format from database',
                'mythfs.format.%s' % fmt)
            fmt = self.be.db.settings.NULL['mythfs.format.%s' % fmt]
        LOG(LOG.FILE, 'using format', fmt)
        self.fmt = fmt