You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

user.rst 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. py3createtorrent
  2. ================
  3. *Create torrents via command line!*
  4. py3createtorrent is a comprehensive shell/commandline utility for creating
  5. torrents (Linux & Windows). It's a GPL-licensed Python v3.1 script. I tested it
  6. with Ubuntu 8.04 / rTorrent and Windows 7 / µTorrent.
  7. Some of the features:
  8. * you can create **huge torrents** for any amount of data
  9. * you can add a **comment** to the torrent file
  10. * you can create **private torrents** (disabled DHT, ...)
  11. * you can create torrents with **multiple trackers**
  12. * you can **exclude specific files/folders**
  13. * you can exclude files/folders based on **regular expressions**
  14. * you can specify **custom piece sizes**
  15. * you can specify custom creation dates
  16. Motivation
  17. ----------
  18. There already is rTorrent, but unfortunately it does not support creating torrents.
  19. Thus, it is often a pain to seed torrents from your servers directly.
  20. py3createtorrent is intended to fill this gap.
  21. Requirements
  22. ------------
  23. py3createtorrent requires at least Python 3.1 and the `py3bencode <https://bitbucket.org/rsnitsch/py3bencode>`_ module.
  24. Installation
  25. ------------
  26. Download the desired version from here:
  27. https://bitbucket.org/rsnitsch/py3createtorrent/downloads
  28. The required py3bencode module is shipped alongside py3createtorrent. As long
  29. as you extract py3bencode into the same directory as the py3createtorrent script,
  30. you should be fine. This is the easy way and should be appropriate for the
  31. majority of users.
  32. Installing the py3bencode module globally
  33. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  34. Advanced users might prefer to install the py3bencode module globally in their
  35. Python installation.
  36. You can use `pip <http://www.pip-installer.org/>`_ to install the py3bencode
  37. module in your Python installation (in the site-packages, to be precise)::
  38. pip install hg+https://bitbucket.org/rsnitsch/py3bencode
  39. Make sure to use the pip executable that belongs to the Python interpreter
  40. with which you will execute py3createtorrent.
  41. If you don't have pip around (although I strongly recommend using it) you can
  42. also try to install py3bencode manually::
  43. $ hg clone https://bitbucket.org/rsnitsch/py3bencode
  44. $ cd py3bencode
  45. $ python3 setup.py install
  46. Note that any local version of py3bencode will take precedence over the global
  47. version installed in your site-packages. Thus, you will have to delete the
  48. py3bencode module that has been shipped alongside py3createtorrent, if you want
  49. the global version to be used.
  50. .. _configuration:
  51. Configuration
  52. -------------
  53. There is a small configuration section in the script (at the top):
  54. .. literalinclude:: ../../src/py3createtorrent.py
  55. :start-after: # #############
  56. :end-before: # ##############
  57. :prepend: # #############
  58. :append: # ##############
  59. Tracker abbreviations
  60. ^^^^^^^^^^^^^^^^^^^^^
  61. Tracker abbrevations allow you to specify one or more tracker URLs with a single
  62. word, like 'openbt' in the default configuration. They add a lot of convenience,
  63. e.g. look at this neat & clear command::
  64. C:\Users\Robert\Desktop\Python\createtorrent>py3createtorrent.py example openbt publicbt
  65. Successfully created torrent:
  66. Name: example
  67. (...)
  68. Primary tracker: udp://tracker.openbittorrent.com/announce
  69. Backup trackers:
  70. udp://tracker.publicbt.com:80/announce
  71. In this case, py3createtorrent recognizes the tracker abbreviations 'openbt' and
  72. 'publicbt' and automatically inserts the according tracker announce URLs.
  73. .. note::
  74. Single abbreviations may be replaced by multiple tracker announce URLs. This
  75. way you can also create sort of "tracker groups" for different kinds of
  76. torrents.
  77. Example configuration::
  78. TRACKER_ABBR = {'mytrackergroup': ['udp://tracker.openbittorrent.com:80/announce',
  79. 'udp://tracker.publicbt.com:80/announce'],
  80. 'openbt': 'udp://tracker.openbittorrent.com:80/announce',
  81. 'publicbt': 'udp://tracker.publicbt.com:80/announce'}
  82. Just specify lists of announce URLs instead of a single announce URL to define
  83. such groups.
  84. Advertise setting
  85. ^^^^^^^^^^^^^^^^^
  86. The ``ADVERTISE`` setting defines whether py3createtorrent is allowed to advertise
  87. itself through the comment field, if the user hasn't specified a comment.
  88. If you want to disable advertising for a single torrent only, you can use the
  89. ``--comment`` option to specify an empty comment::
  90. $ py3createtorrent.py --comment "" ...
  91. or
  92. $ py3createtorrent.py -c "" ...
  93. py3createtorrent will not advertise itself in this case, because you explicitly
  94. specified the empty comment.
  95. Usage
  96. -----
  97. Syntax::
  98. Usage: py3createtorrent.py [options] <file-or-directory> <main-tracker-url> [<backup-tracker-url> ...]
  99. py3createtorrent is a comprehensive command line utility for creating
  100. torrents.
  101. Options:
  102. --version show program's version number and exit
  103. -h, --help show this help message and exit
  104. -p PIECE_LENGTH, --piece-length=PIECE_LENGTH
  105. piece size in KiB. 0 = automatic selection (default).
  106. -P, --private create private torrent
  107. -c COMMENT, --comment=COMMENT
  108. include comment
  109. -f, --force dont ask anything, just do it
  110. -v, --verbose verbose mode
  111. -q, --quiet be quiet, e.g. don't print summary
  112. -o PATH, --output=PATH
  113. custom output location (directory or complete path).
  114. default = current directory.
  115. -e PATH, --exclude=PATH
  116. exclude path (can be repeated)
  117. --exclude-pattern=REGEXP
  118. exclude paths matching the regular expression (can be
  119. repeated)
  120. --exclude-pattern-ci=REGEXP
  121. exclude paths matching the case-insensitive regular
  122. expression (can be repeated)
  123. -d TIMESTAMP, --date=TIMESTAMP
  124. set creation date (unix timestamp). -1 = now
  125. (default). -2 = disable.
  126. -n NAME, --name=NAME use this file (or directory) name instead of the real
  127. one
  128. --md5 include MD5 hashes in torrent file
  129. Piece size (``-p``)
  130. ^^^^^^^^^^^^^^^^^^^
  131. This switch allows you to specify a custom piece size. The piece size should be
  132. chosen with care, because it affects the following properties:
  133. * size of the .torrent file
  134. * network overhead
  135. * cost of fixing corrupted pieces
  136. * time it takes until peers start sharing data
  137. .. note::
  138. Unless you know what you're doing, please let py3createtorrent automatically
  139. determine the best piece size for you.
  140. Background
  141. """"""""""
  142. In general, the files for which a .torrent is created are sliced up in **pieces**.
  143. For each piece, a 20-byte checksum (based on SHA-1, the Secure Hash Algorithm 1) is
  144. calculated and stored inside the .torrent file - this, by the way, is the
  145. time-consuming part of torrent creation. Therefore, the piece size strongly
  146. correlates with the size of the created .torrent file: The larger the pieces,
  147. the smaller the number of pieces for which a checksum must be stored (and vice
  148. versa).
  149. The piece size also affects the **network overhead** involved in the peer-2-peer
  150. communication for a torrent. The peers regularly exchange information records
  151. that specify the pieces that each peer has finished downloading so that they know
  152. where they can get certain pieces from. The greater the number of pieces, the
  153. larger these information records need to be and thus the greater the overhead
  154. will tend to be.
  155. Moreover, corrupted pieces need to be redownloaded. Of course, large pieces
  156. are more expensive to redownload (both in terms of time and traffic).
  157. Finally, the piece size also affects the time it takes until peers
  158. start to share data with each other (only pieces that have been downloaded
  159. completely can be shared with other peers). Therefore, if the piece size is
  160. large, it will take longer for any peer to finish downloading a piece and to be
  161. able to share this piece with other peers.
  162. Private torrents (``-P``)
  163. ^^^^^^^^^^^^^^^^^^^^^^^^^
  164. Private torrents force the BitTorrent clients to only use the specified trackers
  165. for discovering other peers. Advanced peer discovery methods like DHT or
  166. peer list exchange are effectively disabled.
  167. Comment (``-c``)
  168. ^^^^^^^^^^^^^^^^
  169. The comment is a short text stored in the .torrent file and displayed by most
  170. BitTorrent clients in the torrent info.
  171. By default py3createtorrent uses "created by py3createtorrent <version>" as
  172. comment (to change this behavior, consult the :ref:`configuration` section).
  173. Force (``-f``)
  174. ^^^^^^^^^^^^^^
  175. Force makes py3createtorrent e.g. overwrite existing .torrent files without
  176. asking for your permission.
  177. Verbose (``-v``)
  178. ^^^^^^^^^^^^^^^^
  179. Verbose mode makes py3createtorrent report about the individual steps it is
  180. undertaking while creating the .torrent file.
  181. This is particularly useful for debugging purposes.
  182. Quiet (``-q``)
  183. ^^^^^^^^^^^^^^
  184. py3createtorrent will try to stay completely silent on the commandline.
  185. Output path (``-o``)
  186. ^^^^^^^^^^^^^^^^^^^^
  187. The output path is either the directory in which the .torrent file should be
  188. saved or the complete path to the destination .torrent file. In the former
  189. case, the name of the .torrent file is deduced from the input's name (i.e.
  190. the input directory's or file's name), unless this name is explicitly
  191. overwritten (using the ``-n`` switch). (In the latter case, the name of the
  192. .torrent file is itself specified by the output path.)
  193. By default, py3createtorrent uses the current working directory as the output
  194. directory.
  195. Exclude path (``-e``)
  196. ^^^^^^^^^^^^^^^^^^^^^
  197. This allows for the exclusion of specific files or directories.
  198. The switch may be used repeatedly to exclude multiple files/directories.
  199. On Windows, this is case-insensitive.
  200. Exclude pattern (``--exclude-pattern``, ``--exclude-pattern-ci``)
  201. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  202. This allows for the exclusion of files or directories that match a certain
  203. pattern (regular expression).
  204. The switches may be used repeatedly to specify multiple exclusion patterns.
  205. *New in version 0.9.5:* The ``--exclude-pattern-ci`` variant (case-insensitive).
  206. On Windows, the ``--exclude-pattern`` has been made case-sensitive (previously
  207. it was case-insensitive on Windows and case-sensitive on UNIX etc.).
  208. Creation date (``-d``)
  209. ^^^^^^^^^^^^^^^^^^^^^^
  210. This switch allows you to overwrite the creation date saved in the .torrent
  211. file. You can fake any creation date you like.
  212. The creation date is specified as `UNIX timestamp
  213. <https://en.wikipedia.org/wiki/Unix_time>`_.
  214. Name (``-n``)
  215. ^^^^^^^^^^^^^
  216. This setting overwrites the file or directory name stored inside the .torrent
  217. file. **Thus it affects the file or directory name that will be presented
  218. to downloaders as the real name of the data.** You can use it to avoid
  219. renaming your input data.
  220. Unless a destination .torrent file is explicitly specified (using the ``-o`` switch),
  221. this name will also be used to deduce the name of the resulting .torrent file.
  222. .. note::
  223. The name switch is an advanced feature that most users probably don't need.
  224. Therefore, please refrain from using this feature, unless you really know
  225. what you're doing.
  226. For most intents and purposes, the ``-o`` switch is probably more suitable.
  227. MD5 hashes (``--md5``)
  228. ^^^^^^^^^^^^^^^^^^^^^^
  229. As of py3createtorrent 0.9.5 the calculation of MD5 hashes must be explicitly
  230. requested, because it significantly slows down the torrent creation process (and
  231. makes the torrent file a little larger, although this is probably negligible).
  232. *New in 0.9.5.*
  233. Examples
  234. --------
  235. Assume there is a folder "example" with the following contents::
  236. example/
  237. subfolder/
  238. 10_more_minutes_please.JPG
  239. image.rar
  240. anotherimage.jpg
  241. image.zip
  242. Assume, we're currently inside the parent directory.
  243. Example 1 - from directory, no options, default behaviour
  244. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  245. **Command**::
  246. C:\Users\Robert\Desktop\Python\createtorrent>py3createtorrent.py example udp://tracker.openbittorrent.com/announce
  247. Alternative, equivalent command using a tracker abbreviation for convenience::
  248. C:\Users\Robert\Desktop\Python\createtorrent>py3createtorrent.py example openbt
  249. **Effect**:
  250. Creates example.torrent inside the current directory.
  251. In µTorrent it will look like this:
  252. .. image:: _static/example1.png
  253. .. note::
  254. Please note: If you do not specify a comment yourself using the ``-c`` / ``--comment``
  255. option, py3createtorrent will advertise itself through the comment field, as
  256. you can see in the screenshot (Torrent Contents -> Comment: *created with
  257. py3createtorrent v0.8*).
  258. To change this behavior, consult the :ref:`configuration` section.
  259. Example 2 - from directory, excluding subfolders
  260. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  261. **Command**::
  262. C:\Users\Robert\Desktop\Python\createtorrent>py3createtorrent.py -e example\subfolder example udp://tracker.openbittorrent.com/announce
  263. **Effect**:
  264. Creates example.torrent inside the current directory. example\subfolder has
  265. been excluded.
  266. .. tip::
  267. Of course you can exclude multiple subfolders, e.g.::
  268. py3createtorrent.py -e exclusion1 -e exclusion2 yourfolder tracker-url
  269. In µTorrent it will look like this:
  270. .. image:: _static/example2.png
  271. Example 3 - from directory, excluding files
  272. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  273. **Command**::
  274. C:\Users\Robert\Desktop\Python\createtorrent>py3createtorrent.py -e example\anotherimage.jpg -e example\subfolder\10_more_minutes_please.JPG example udp://tracker.openbittorrent.com/announce
  275. Alternative, equivalent command using **regular expressions** instead of
  276. specifying each jpg seperately (also using a tracker abbreviation to make it
  277. even shorter)::
  278. C:\Users\Robert\Desktop\Python\createtorrent>py3createtorrent.py --exclude-pattern "(jpg|JPG)$" example openbt
  279. **Effect**:
  280. Creates example.torrent inside the current directory. example\anotherimage.jpg
  281. and example\subfolder\10_more_minutes_please.JPG have been excluded.
  282. In µTorrent it will look like this:
  283. .. image:: _static/example3.png
  284. Creating torrents of single files
  285. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  286. It's almost the same as for creating directories, except, of course, you can't
  287. use the exclude-option anymore.