コード例 #1
0
ファイル: jsbridge.py プロジェクト: mwarning/web-torrent
    def createTorrent(self, title, paths):
        #convert QStringList into a normal python list
        title = str(title)
        paths = [str(p) for p in paths]

        torrent_root = os.path.join(self.controller.cache_path, title)

        if os.path.exists(torrent_root):
            self.showMessage("Folder already exists: {}".format(title))
            return
        ''' Create a temp torrent file. the one in the cache folder will be written at program shutdown '''
        fd, torrent_file = tempfile.mkstemp(suffix=".torrent")
        os.close(fd)

        try:
            os.mkdir(torrent_root)
            ''' Copy all file to one location '''
            for path in paths:
                print(u"jsbridge: Copy {} to {}".format(path, torrent_root))
                shutil.copy(path, torrent_root)

            TorrentController.createTorrent(torrent_file, torrent_root,
                                            self.showProgress)
            self.controller.addTorrentFile(torrent_file)
        except:
            e = sys.exc_info()[0]
            print(e)
            self.showMessage(e)

        #some cleanup
        os.remove(torrent_file)
コード例 #2
0
ファイル: jsbridge.py プロジェクト: mwarning/web-torrent
	def createTorrent(self, title, paths):
		#convert QStringList into a normal python list
		title = str(title)
		paths = [str(p) for p in paths]

		torrent_root = os.path.join(self.controller.cache_path, title)

		if os.path.exists(torrent_root):
			self.showMessage("Folder already exists: {}".format(title))
			return

		''' Create a temp torrent file. the one in the cache folder will be written at program shutdown '''
		fd, torrent_file = tempfile.mkstemp(suffix=".torrent")
		os.close(fd)

		try:
			os.mkdir(torrent_root)

			''' Copy all file to one location '''
			for path in paths:
				print(u"jsbridge: Copy {} to {}".format(path, torrent_root))
				shutil.copy(path, torrent_root)

			TorrentController.createTorrent(torrent_file, torrent_root, self.showProgress)
			self.controller.addTorrentFile(torrent_file)
		except:
			e = sys.exc_info()[0]
			print(e)
			self.showMessage(e)

		#some cleanup
		os.remove(torrent_file)
コード例 #3
0
ファイル: main.py プロジェクト: mwarning/web-torrent
def autoAddTorrents(controller, content_folders_path):
	print("(I) Add Torrent files.")
	content_folders_path = os.path.abspath(content_folders_path)
	
	for name in os.listdir(content_folders_path):
		path = os.path.join(content_folders_path, name)
		if os.path.isfile(path) and path.endswith(".torrent"):
			print("(I) Add {}".format(path))
			controller.addTorrentFile(path)

if __name__ == "__main__":
	app = QApplication([])

	cache_path = os.path.abspath("cache/")

	controller = TorrentController(cache_path)
	main_window = MainWindow(controller)
	torrent_view = TorrentView(controller)
	dht_view = DhtView(controller)

	main_window.showDhtAction.triggered.connect(dht_view.show)
	main_window.showDownloadsAction.triggered.connect(torrent_view.show)

	#autoCreateTorrents(controller, cache_path)
	autoAddTorrents(controller, cache_path)

	controller.loadSettings("libtorrent.json")

	'''handler for the SIGINT signal'''
	def sigint_handler(*args):
		print("sigint_handler")
コード例 #4
0
    print("(I) Add Torrent files.")
    content_folders_path = os.path.abspath(content_folders_path)

    for name in os.listdir(content_folders_path):
        path = os.path.join(content_folders_path, name)
        if os.path.isfile(path) and path.endswith(".torrent"):
            print("(I) Add {}".format(path))
            controller.addTorrentFile(path)


if __name__ == "__main__":
    app = QApplication([])

    cache_path = os.path.abspath("cache/")

    controller = TorrentController(cache_path)
    main_window = MainWindow(controller)
    torrent_view = TorrentView(controller)
    dht_view = DhtView(controller)

    main_window.showDhtAction.triggered.connect(dht_view.show)
    main_window.showDownloadsAction.triggered.connect(torrent_view.show)

    #autoCreateTorrents(controller, cache_path)
    autoAddTorrents(controller, cache_path)

    controller.loadSettings("libtorrent.json")
    '''handler for the SIGINT signal'''
    def sigint_handler(*args):
        print("sigint_handler")
        QApplication.quit()