Esempio n. 1
0
	def showOpenDialogue(self, widget=None):
		## Shows the open file dialogue.
		# Prepare the dialogue.
		dlg = dialogues.OpenFile(self.mainWindow, useful.lastFolder, allowSub=True)

		if (dlg.files):
			# If the response is OK, play the first file, then queue the others.
			# Clear the queue first though, since it is now obsolete.
			queue.clear()
			# Set the last folder, (if it exists).
			if (dlg.dir): useful.lastFolder = dlg.dir
			
			if dlg.chkSubs.get_active():
				# If the user want's subtitles, let them choose the stream.
				dlg2 = dialogues.OpenFile(self.mainWindow, useful.lastFolder, multiple=False, useFilter=False, title=_("Choose a Subtitle Stream"))
				if dlg2.files:
					player.player.set_property('suburi', useful.filenameToUri(dlg2.files[0]))
					player.player.set_property('subtitle-encoding', cfg.getStr('video/subenc'))
				else:
					# Bail if they chose add subtitles but then clicked cancel.
					return
			
			# Play the first file and append the rest to the queue.
			self.playFile(dlg.files[0])
			queue.appendMany(dlg.files[1:])
Esempio n. 2
0
	def playFile(self, file, stop=True):
		## Plays the file 'file' (Could also be a URI).
		# Stop the player if requested. (Required for playbin2 and
		# changing streams midway through another).
		if stop: player.stop()
		if (file == None):
			# If no file is to be played, set the URI to None, and the file to ""
			file = ""
		# Set the now playing label to the file to be played.
		self.nowPlyLbl.set_label(os.path.basename(urllib.url2pathname(file)))
		if (os.path.exists(file) or '://' in file):
			# If it's not already a uri, make it one.
			# Also escape any # characters in the filename
			file = useful.filenameToUri(file).replace('#', '%23')
			# Set the URI to the file's one.
			player.setURI(file)
			# Try to set the subtitle track if requested.
			if cfg.getBool('video/autosub'): subtitles.trySubs(file)
			# Add the file to recently opened files.
			gtk.recent_manager_get_default().add_item(file)
			# Start the player, if it isn't already running.
			if (not player.isPlaying()): player.play()
		
		elif (file != ""):
			# If none of the above, a bad filename was passed.
			print _("Something's stuffed up, no such file: %s") % (file)
			self.playFile(None)
Esempio n. 3
0
def trySubs(file):
	# Trys to automatically set the subtitle track for a file.
	# Get rid of the file:// at the start (if it's there).
	if ('file://' in file): file = file[7:]
	# Rip off the files extension.
	(root, x) = os.path.splitext(file)
	for ext in cfg.getStr('video/autosubexts').split(','):
		# For all the extensions in the extensions list.
		subPath = '%s.%s' % (root, ext)
		if os.path.exists(subPath):
			# If the subtitle file exists DO IT!
			player.player.set_property('suburi', useful.filenameToUri(subPath))
			player.player.set_property('subtitle-encoding', cfg.getStr('video/subenc'))
			print _("Found subtitles stream %s" % subPath)
			return True
	
	return False
Esempio n. 4
0
	def addSubs(self, widget):
		# Add subtitles to the current file from a file dialogue.
		dlg = gtk.FileChooserDialog(_("Choose a subtitle stream."), self.window,
		                  buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
		                             gtk.STOCK_OPEN, gtk.RESPONSE_OK))
		# Use the same folder as the last file opened.
		dlg.set_current_folder(useful.lastFolder)
		res = dlg.run()
		
		if (res == gtk.RESPONSE_OK) and (player.player.get_property('n-video') >= 1):
			# If the response was 'OK' and there is a video track get the filename.
			file = dlg.get_filename()
			# We need to restart the player so the subtitles work.
			#played = player.getPlayed()
			player.stop()
			# Reset everything.
			player.player.set_property('uri', player.uri)
			player.player.set_property('suburi', useful.filenameToUri(file))
			player.player.set_property('subtitle-encoding', self.txtSubsEnc.get_text())
			player.play()
			#player.seek(played)
		
		dlg.destroy()