def create_torrent(file, port, try_vod = True): ''' Creates a torrent for the given file. Returns a string representing the path to the torrent file. If try_vod is True try to add the playtime to the torrent making it "streamable". ''' # generate torrent tdef = TorrentDef() url = "http://localhost:%s/announce/" % port tdef.set_tracker(url) #tdef.set_create_merkle_torrent(True) #tdef.set_piece_length(self._pieceSize) if try_vod: torrent_name = FileUtils.get_relative_filename(file) + constants.TORRENT_VOD_EXT # set playtime playtime = videostats_via_ffmpeg(file)['playtime'] print "playtime", playtime else: torrent_name = FileUtils.get_relative_filename(file) + constants.TORRENT_DOWNLOAD_EXT playtime = None print "Create a non-streamable torrent" tdef.add_content(file, playtime=playtime) tdef.finalize() torrent_dir = os.getcwd() torrent = os.path.join(torrent_dir, torrent_name) tdef.save(torrent) print "created torrent file: %s" % torrent print "Tracker uses the announce URL: %s" % tdef.get_tracker() return tdef
def create_torrent(self, file): """ Creates a torrent for the given file. Returns a string representing the path to the torrent file. """ tdef = TorrentDef() tdef.set_tracker(self._session.get_internal_tracker_url()) tdef.set_create_merkle_torrent(False) tdef.set_piece_length(self._pieceSize) if self._vod: torrent_ext = constants.TORRENT_VOD_EXT # set playtime try: playtime = videostats_via_ffmpeg(file)["playtime"] except: self._logger.warn("Cannot create streaming torrent for file %s" % file) return self._logger.debug("playtime %s" % playtime) else: torrent_ext = constants.TORRENT_DOWNLOAD_EXT playtime = None self._logger.warning("Create a non-streamable torrent") tdef.add_content(file, playtime=playtime) tdef.finalize() torrent = os.path.join(self._directory, FileUtils.get_relative_filename(file) + torrent_ext) tdef.save(torrent) self._logger.info("created torrent file: %s" % torrent) self._logger.info("Tracker uses the announce URL: %s" % tdef.get_tracker()) return tdef
def create_torrent(file, port, try_vod=True): ''' Creates a torrent for the given file. Returns a string representing the path to the torrent file. If try_vod is True try to add the playtime to the torrent making it "streamable". ''' # generate torrent tdef = TorrentDef() url = "http://localhost:%s/announce/" % port tdef.set_tracker(url) #tdef.set_create_merkle_torrent(True) #tdef.set_piece_length(self._pieceSize) if try_vod: torrent_name = FileUtils.get_relative_filename( file) + constants.TORRENT_VOD_EXT # set playtime playtime = videostats_via_ffmpeg(file)['playtime'] print "playtime", playtime else: torrent_name = FileUtils.get_relative_filename( file) + constants.TORRENT_DOWNLOAD_EXT playtime = None print "Create a non-streamable torrent" tdef.add_content(file, playtime=playtime) tdef.finalize() torrent_dir = os.getcwd() torrent = os.path.join(torrent_dir, torrent_name) tdef.save(torrent) print "created torrent file: %s" % torrent print "Tracker uses the announce URL: %s" % tdef.get_tracker() return tdef