コード例 #1
0
ファイル: Scheduler.py プロジェクト: dimarr/vidscan
	def get_status_list(self, filter = None):
		status_relpath_dict = {}
		for file in os.listdir(self.destpath):
			match = re.match('^_status\.([^\.]+)\.json$', file)
			if match:
				log.debug('Checking ' + file)
				instance_name = match.group(1)
				instance_status_list = []

				status_json = open(os.path.join(self.destpath, file)).read().decode('utf-8')
				if status_json != '':
					try:
						instance_status_list = json.loads(status_json)
					except ValueError as e:
						raise AppError('Error loading status list. Check that it is a valid json file or remove it. Error = ' + str(e))	
						#log.warn('Error reading status file (' + file + ') so we will skip it. Error = ' + str(e))
						#log.debug('Contents of ' + file + ': ' + status_json)

				for status in instance_status_list:
					videofile = VideoFile()
					videofile.update(status['videofile'])

					destinationfile = DestinationFile()
					destinationfile.update(status['destinationfile'])

	
					destrelpath = destinationfile.relpath

					if destrelpath in status_relpath_dict:
						status_tupl = status_relpath_dict[destrelpath]
						if destinationfile.timestamp_start > status_tupl[2].timestamp_start:
							del status_relpath_dict[destrelpath]

					if destrelpath not in status_relpath_dict:
						status_relpath_dict[destrelpath] = (instance_name, videofile, destinationfile)
			
		if filter is not None:
			result = []
			for tupl in status_relpath_dict.values():
				if filter(*tupl):
					result.append(tupl)
			return result

		return status_relpath_dict.values()
コード例 #2
0
def get_file_type(path):
    patterns = {
        'img':
        re.compile(r'.(png|jpg|jpeg|gif|tiff|raw|psd|eps|ai|indd)'),
        'archive':
        re.compile(r'.(tar|bz2|gz|7z|arc|ark|jar|rar|tar.gz|tgz|'
                   r'tar.Z|tar.bz2|tbz2|tar.lz|tlz.tar.xz|txz|zip|zipx)'),
        'vid':
        re.compile(r'.(mkv|avi|mp4)')
    }

    for key, pattern in patterns.items():
        if pattern.search(path) and key == 'img':
            return ImageFile(path)
        elif pattern.search(path) and key == 'archive':
            return ArchiveFile(path)
        elif pattern.search(path) and key == 'vid':
            return VideoFile(path)
        else:
            return MainWindow(path)
コード例 #3
0
    def __init__(self, opts, name, root, vidlist, harvesters):
        self.name = name
        self.title = name
        self.opts = opts.copy()
        self.count = 0
        self.root = root
        self.videoDir = VideoDir(opts, "", "", root, name)

        tree = myWalk(root)

        sharedirs = {"": self.videoDir}
        shareopts = {"": self.opts}

        for path, dirs, files in tree:
            rpath = path[len(root) :]
            if rpath.startswith(os.path.sep):
                rpath = rpath[1:]
            if rpath not in sharedirs:
                continue
            vl = sharedirs[rpath]
            lopts = shareopts[rpath]
            Config.addLocalOpts(lopts, root, rpath)
            vl.setOpts(lopts)

            for name in dirs:
                if name.startswith("."):
                    continue
                meta = metadata.from_text(
                    os.path.join(path, name, "folder"),
                    lopts["metamergefiles"],
                    lopts["metamergelines"],
                    lopts["metamergeparent"],
                )
                d = VideoDir(lopts, name, rpath, path, self.name)
                d.setMeta(meta)
                vl.addDir(d)
                sharedirs[os.path.join(rpath, name)] = d
                shareopts[os.path.join(rpath, name)] = lopts.copy()

            for name in files:
                if name.startswith("."):
                    continue
                if os.path.splitext(name)[1].lower() in lopts["goodexts"]:
                    fid = fileId(os.path.join(path, name))
                    if fid != None:
                        vf = vidlist.findVideo(fid)
                    else:
                        vf = None

                    if vf == None:
                        vf = VideoFile(lopts, path, name, fid)
                        vidlist.addVideo(vf)

                        meta = metadata.from_text(
                            os.path.join(path, name),
                            lopts["metamergefiles"],
                            lopts["metamergelines"],
                            lopts["metamergeparent"],
                        )
                        if not "title" in meta:
                            meta = metadata.basic(os.path.join(path, name))
                        vf.setMeta(meta)

                        vl.addVideo(vf)
                        self.count += 1

                        for h in harvesters:
                            h.harvest(vf)

                    else:
                        vl.addVideo(vf, path=path, fn=name)
                        self.count += 1

            vl.sort()
コード例 #4
0
    def __init__(self, opts, name, root, vidlist, harvesters):
        self.name = name
        self.title = name
        self.opts = opts.copy()
        self.count = 0
        self.root = root

        self.videoDir = VideoDir(self.opts, "", "", root, name)

        shareopts = {"": self.opts}
        sharedirs = {"": self.videoDir}

        tree = os.walk(root)

        for path, dirs, files in tree:
            rpath = path[len(root):]
            if rpath.startswith(os.path.sep): rpath = rpath[1:]

            if rpath not in sharedirs: continue
            vdir = sharedirs[rpath]
            lopts = shareopts[rpath]
            Config.addLocalOpts(lopts, root, rpath)
            vdir.setOpts(lopts)

            if self.isDvdDir(path):
                p, deftitle = os.path.split(path)
                meta, titles = self.loadDvdMeta(path, lopts, "default",
                                                deftitle, False)
                fid = fileId(os.path.join(path, "default.txt"))
                for (title, fn, tn) in titles:
                    if fid != None:
                        vf = vidlist.findVideo((fid, tn))
                    else:
                        vf = None

                    if vf == None:
                        vf = VideoFile(lopts, path, fn, (fid, tn))
                        vidlist.addVideo(vf)

                        meta, t = self.loadDvdMeta(path, lopts, fn, title,
                                                   True)
                        meta['title'] = title
                        meta['titleNumber'] = tn
                        vf.setMeta(meta)

                        vdir.addVideo(vf)
                        self.count += 1

                        for h in harvesters:
                            h.harvest(vf)

                    else:
                        vdir.addVideo(vf, path=path, fn=fn)
                        self.count += 1
            else:
                for dn in dirs:
                    if dn.startswith("."): continue

                    cdir = os.path.join(path, dn)
                    if self.isDvdDir(cdir):
                        meta, tnames = self.loadDvdMeta(
                            cdir, lopts, "default", dn, False)

                        d = DVDDir(lopts, dn, rpath, path, self.name)
                    else:
                        meta = metadata.from_text(
                            os.path.join(path, dn, "folder"),
                            lopts['metamergefiles'], lopts['metamergelines'])

                        d = VideoDir(lopts, dn, rpath, path, self.name)

                    d.setMeta(meta)
                    vdir.addDir(d)
                    sharedirs[os.path.join(rpath, dn)] = d
                    shareopts[os.path.join(rpath, dn)] = lopts.copy()
            vdir.sort()
コード例 #5
0
    def __init__(self, opts, name, root, vidlist, harvesters):
        self.name = name
        self.title = name
        self.opts = opts.copy()
        self.count = 0
        self.root = root
        self.videoDir = VideoDir(opts, "", "", root, name)

        tree = myWalk(root)

        sharedirs = {"": self.videoDir}
        shareopts = {"": self.opts}

        for path, dirs, files in tree:
            rpath = path[len(root):]
            if rpath.startswith(os.path.sep): rpath = rpath[1:]
            if rpath not in sharedirs: continue
            vl = sharedirs[rpath]
            lopts = shareopts[rpath]
            Config.addLocalOpts(lopts, root, rpath)
            vl.setOpts(lopts)

            for name in dirs:
                if name.startswith("."): continue
                meta = metadata.from_text(os.path.join(path, name, "folder"),
                                          lopts['metamergefiles'],
                                          lopts['metamergelines'])
                d = VideoDir(lopts, name, rpath, path, self.name)
                d.setMeta(meta)
                vl.addDir(d)
                sharedirs[os.path.join(rpath, name)] = d
                shareopts[os.path.join(rpath, name)] = lopts.copy()

            for name in files:
                if name.startswith("."): continue
                if os.path.splitext(name)[1].lower() in lopts['goodexts']:
                    fid = fileId(os.path.join(path, name))
                    if fid != None:
                        vf = vidlist.findVideo(fid)
                    else:
                        vf = None

                    if vf == None:
                        vf = VideoFile(lopts, path, name, fid)
                        vidlist.addVideo(vf)

                        meta = metadata.from_text(os.path.join(path, name),
                                                  lopts['metamergefiles'],
                                                  lopts['metamergelines'])
                        if not 'title' in meta:
                            meta = metadata.basic(os.path.join(path, name))
                        vf.setMeta(meta)

                        vl.addVideo(vf)
                        self.count += 1

                        for h in harvesters:
                            h.harvest(vf)

                    else:
                        vl.addVideo(vf, path=path, fn=name)
                        self.count += 1

            vl.sort()
コード例 #6
0
	def __init__(self, opts, name, root, vidlist, harvesters):
		self.name = name
		self.title = name
		self.opts = opts.copy()
		self.count = 0
		self.root = root

		self.videoDir = VideoDir(self.opts, "", "", root, name)
		
		shareopts = {"": self.opts}
		sharedirs = {"": self.videoDir}

		tree = os.walk(root)

		for path, dirs, files in tree:
			rpath = path[len(root):]
			if rpath.startswith(os.path.sep): rpath = rpath[1:]

			if rpath not in sharedirs: continue
			vdir = sharedirs[rpath]
			lopts = shareopts[rpath]
			Config.addLocalOpts(lopts, root, rpath)
			vdir.setOpts(lopts)

			if self.isDvdDir(path):
				p, deftitle = os.path.split(path)
				meta, titles = self.loadDvdMeta(path, lopts, "default", deftitle, False)
				fid = fileId(os.path.join(path, "default.txt"))
				for (title, fn, tn) in titles:
					if fid != None:		
						vf = vidlist.findVideo((fid, tn))
					else:
						vf = None
						
					if vf == None:
						vf = VideoFile(lopts, path, fn, (fid, tn))
						vidlist.addVideo(vf)

						meta, t = self.loadDvdMeta(path, lopts, fn, title, True)
						meta['title'] = title
						meta['titleNumber'] = tn
						vf.setMeta(meta)
						
						vdir.addVideo(vf)
						self.count += 1

						for h in harvesters:
							h.harvest(vf)

					else:
						vdir.addVideo(vf, path=path, fn=fn)
						self.count += 1
			else:
				for dn in dirs:
					if dn.startswith("."): continue

					cdir = os.path.join(path, dn)
					if self.isDvdDir(cdir):
						meta, tnames = self.loadDvdMeta(cdir,
							lopts,
							"default",
							dn,
							False)
					
						d = DVDDir(lopts, dn, rpath, path, self.name)
					else:
						meta = metadata.from_text(
							os.path.join(path, dn, "folder"),
							lopts['metamergefiles'],
							lopts['metamergelines'])

						d = VideoDir(lopts, dn, rpath, path, self.name)
						
					d.setMeta(meta)
					vdir.addDir(d)
					sharedirs[os.path.join(rpath, dn)] = d
					shareopts[os.path.join(rpath, dn)] = lopts.copy()
			vdir.sort()
コード例 #7
0
ファイル: Scanner.py プロジェクト: dimarr/vidscan
	def processFile(self, fullpath, lines): 
		vf = VideoFile(fullpath, os.path.relpath(fullpath, self.path).replace('\\', '/'))		
		# loop through lines of ffmpeg output
		for line in lines:
			# Extract video file info
			# Duration: 01:37:58.08, start: 0.000000, bitrate: 997 kb/s"
			match = re.search('Duration: (\d\d:\d\d:\d\d\.\d\d),[^,]+, bitrate: (\d+ [a-z\/]+)', line)
			if match:
				if vf.duration or vf.bitrate:
					raise AppError("Video file data already exists. Check regex")
				else:
					vf.duration = match.group(1)
					vf.bitrate = match.group(2)
			# Extract video stream info
			# Stream #0:0: Video: mpeg4 (Advanced Simple Profile) (XVID / 0x44495658), yuv420p, 640x352 [SAR 1:1 DAR 20:11], 23.98 tbr, 23.98 tbn, 23.98 tbc
			match = re.search('Stream #\d+:\d+[^:]*: Video: ([^,]+), [^,]+, ([^,]+)', line)
			if match:
				if vf.v_codec or vf.v_resolution:
					raise AppError('Video stream already exists. Check regex')
				else:
					vf.v_codec = match.group(1)
					vf.v_resolution = match.group(2)
			# Exract audio stream info
			# Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, stereo, s16p, 126 kb/s
			# Stream #0:1(eng): Audio: aac, 48000 Hz, stereo, fltp (default)
			match = re.search('Stream #\d+:\d+[^:]*: Audio: ([^,]+), [^,]+, ([^,]+), [^,]+(?:, (\d+ [a-z\/]+))?', line)
			if match:
				if vf.a_codec or vf.a_channel or vf.a_bitrate:
					raise AppError('Audio stream already exists. Check regex')
				else:
					vf.a_codec = match.group(1)
					vf.a_channel = match.group(2)
					if match.group(3) is not None:
						vf.a_bitrate = match.group(3)
		# Determine if file requires video transcoding
		# These video codecs do not need transcoding:
		# 1) h264 (High)
		# 2) h264 (Main) OR h264 (Main) (avc1 / 0x31637661) 
		if not (vf.v_codec == '' or re.search('h264 \(High\)', vf.v_codec) or re.match('^h264 \(Main\)(\s\(avc1 .*)?$', vf.v_codec)):
			vf.op_flag = vf.op_flag | VideoFileOp.TRANSCODE_VIDEO
		
		# Determine if file requires audio transcoding
		if not (vf.a_codec == '' or re.search('aac|mp3|dts', vf.a_codec, re.IGNORECASE)):
		   vf.op_flag = vf.op_flag | VideoFileOp.TRANSCODE_AUDIO
		vf.size = os.path.getsize(fullpath)
		   
		return vf