本文整理汇总了Python中classes.query.File.data["media_type"]方法的典型用法代码示例。如果您正苦于以下问题:Python File.data["media_type"]方法的具体用法?Python File.data["media_type"]怎么用?Python File.data["media_type"]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类classes.query.File
的用法示例。
在下文中一共展示了File.data["media_type"]方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_add_file
# 需要导入模块: from classes.query import File [as 别名]
# 或者: from classes.query.File import data["media_type"] [as 别名]
def test_add_file(self):
""" Test the File.save method by adding multiple files """
# Import additional classes that need the app defined first
from classes.query import File
# Find number of files in project
num_files = len(File.filter())
# Create file
r = openshot.DummyReader(openshot.Fraction(24, 1), 640, 480, 44100, 2, 30.0)
# Parse JSON
file_data = json.loads(r.Json())
# Insert into project data
query_file = File()
query_file.data = file_data
query_file.data["path"] = os.path.join(PATH, "images", "openshot.png")
query_file.data["media_type"] = "image"
query_file.save()
self.assertTrue(query_file)
self.assertEqual(len(File.filter()), num_files + 1)
# Save the file again (which should not change the total # of files)
query_file.save()
self.assertEqual(len(File.filter()), num_files + 1)
示例2: setUpClass
# 需要导入模块: from classes.query import File [as 别名]
# 或者: from classes.query.File import data["media_type"] [as 别名]
def setUpClass(TestQueryClass):
""" Init unit test data """
# Create Qt application
TestQueryClass.app = OpenShotApp(sys.argv, mode="unittest")
TestQueryClass.clip_ids = []
TestQueryClass.file_ids = []
TestQueryClass.transition_ids = []
# Import additional classes that need the app defined first
from classes.query import Clip, File, Transition
# Insert some clips into the project data
for num in range(5):
# Create clip
c = openshot.Clip(os.path.join(info.IMAGES_PATH, "AboutLogo.png"))
# Parse JSON
clip_data = json.loads(c.Json())
# Insert into project data
query_clip = Clip()
query_clip.data = clip_data
query_clip.save()
# Keep track of the ids
TestQueryClass.clip_ids.append(query_clip.id)
# Insert some files into the project data
for num in range(5):
# Create file
r = openshot.DummyReader(openshot.Fraction(24, 1), 640, 480, 44100, 2, 30.0)
# Parse JSON
file_data = json.loads(r.Json())
# Insert into project data
query_file = File()
query_file.data = file_data
query_file.data["path"] = os.path.join(info.IMAGES_PATH, "AboutLogo.png")
query_file.data["media_type"] = "image"
query_file.save()
# Keep track of the ids
TestQueryClass.file_ids.append(query_file.id)
# Insert some transitions into the project data
for num in range(5):
# Create mask object
transition_object = openshot.Mask()
transitions_data = json.loads(transition_object.Json())
# Insert into project data
query_transition = Transition()
query_transition.data = transitions_data
query_transition.save()
# Keep track of the ids
TestQueryClass.transition_ids.append(query_transition.id)
示例3: add_file
# 需要导入模块: from classes.query import File [as 别名]
# 或者: from classes.query.File import data["media_type"] [as 别名]
def add_file(self, filepath):
path, filename = os.path.split(filepath)
# Add file into project
app = get_app()
_ = get_app()._tr
# Check for this path in our existing project data
file = File.get(path=filepath)
# If this file is already found, exit
if file:
return
# Load filepath in libopenshot clip object (which will try multiple readers to open it)
clip = openshot.Clip(filepath)
# Get the JSON for the clip's internal reader
try:
reader = clip.Reader()
file_data = json.loads(reader.Json())
# Determine media type
if file_data["has_video"] and not self.is_image(file_data):
file_data["media_type"] = "video"
elif file_data["has_video"] and self.is_image(file_data):
file_data["media_type"] = "image"
elif file_data["has_audio"] and not file_data["has_video"]:
file_data["media_type"] = "audio"
# Save new file to the project data
file = File()
file.data = file_data
# Is this file an image sequence / animation?
image_seq_details = self.get_image_sequence_details(filepath)
if image_seq_details:
# Update file with correct path
folder_path = image_seq_details["folder_path"]
file_name = image_seq_details["file_path"]
base_name = image_seq_details["base_name"]
fixlen = image_seq_details["fixlen"]
digits = image_seq_details["digits"]
extension = image_seq_details["extension"]
if not fixlen:
zero_pattern = "%d"
else:
zero_pattern = "%%0%sd" % digits
# Generate the regex pattern for this image sequence
pattern = "%s%s.%s" % (base_name, zero_pattern, extension)
# Split folder name
(parentPath, folderName) = os.path.split(folder_path)
if not base_name:
# Give alternate name
file.data["name"] = "%s (%s)" % (folderName, pattern)
# Load image sequence (to determine duration and video_length)
image_seq = openshot.Clip(os.path.join(folder_path, pattern))
# Update file details
file.data["path"] = os.path.join(folder_path, pattern)
file.data["media_type"] = "video"
file.data["duration"] = image_seq.Reader().info.duration
file.data["video_length"] = image_seq.Reader().info.video_length
# Save file
file.save()
return True
except:
# Handle exception
msg = QMessageBox()
msg.setText(_("{} is not a valid video, audio, or image file.".format(filename)))
msg.exec_()
return False