(http://www.midnight-commander.org/), Python 2.4+ (http://www.python.org/),
module eff_bdecode.py (http://effbot.org/zone/bencode.htm).
(http://www.midnight-commander.org/), Python 2.4+ (http://www.python.org/),
module eff_bdecode.py (http://effbot.org/zone/bencode.htm).
For older versions put it in /usr/[local/][lib|share]/mc/extfs
and add a line "torrent" to the /usr/[local/][lib|share]/mc/extfs/extfs.ini.
Make the script executable.
For older versions put it in /usr/[local/][lib|share]/mc/extfs
and add a line "torrent" to the /usr/[local/][lib|share]/mc/extfs/extfs.ini.
Make the script executable.
-Run this "cd" command in the Midnight Commander (in the "bindings" file the
-command is "%cd"): cd file#torrent, where "file" is the name of your torrent
-metafile. The VFS lists all files and directories from the torrent metafile;
-all files appear empty, of course, but the sizes are shown. Filenames are
-reencoded from the metafile's encoding/codepage to the current locale.
+For mc 4.7+ run this "cd" command in the Midnight Commander (in the "bindings"
+file the command is "%cd"): cd file/torrent://; In older versions it is
+cd file#torrent, where "file" is the name of your torrent metafile.
+
+See detailed installation instructions at
+https://phdru.name/Software/mc/torrent_INSTALL.html.
+
+The VFS lists all files and directories from the torrent metafile; all files
+appear empty, of course, but the sizes are shown. Filenames are reencoded from
+the metafile's encoding/codepage to the current locale.
Along with the files/directories in the torrent metafile the VFS also presents
meta information - in the form of files in .META directory. The size and
Along with the files/directories in the torrent metafile the VFS also presents
meta information - in the form of files in .META directory. The size and
metafile. The script doesn't check if the torrent consists of a .META file or
directory (quite unlikely).
metafile. The script doesn't check if the torrent consists of a .META file or
directory (quite unlikely).
-Date/time for all files is set to midnight of the 1st January of the current
-year. The filesystem is, naturally, read-only.
+Date/time for all directories/files is set to the value of 'creation date'
+field, if it exists; if not date/time is set to the last modification time of
+the torrent file itself.
+
+The filesystem is, naturally, read-only.
- # Get the default charset.
- try:
- lcAll = locale.getdefaultlocale()
- except locale.Error, err:
- print >>sys.stderr, "WARNING:", err
- lcAll = []
-
- if len(lcAll) == 2:
- default_encoding = lcAll[1]
- else:
- try:
- default_encoding = locale.getpreferredencoding()
- except locale.Error, err:
- print >>sys.stderr, "WARNING:", err
- default_encoding = sys.getdefaultencoding()
+ # Get the default charset.
+ try:
+ lcAll = locale.getdefaultlocale()
+ except locale.Error, err:
+ print >>sys.stderr, "WARNING:", err
+ lcAll = []
+
+ if len(lcAll) == 2:
+ default_encoding = lcAll[1]
+ else:
+ try:
+ default_encoding = locale.getpreferredencoding()
+ except locale.Error, err:
+ print >>sys.stderr, "WARNING:", err
+ default_encoding = sys.getdefaultencoding()
- path = path.decode('utf-8', 'replace').encode(default_encoding, 'replace')
+ path = path.decode('utf-8', 'replace').encode(
+ default_encoding, 'replace')
- _name_utf8 = _name_utf8.decode(encoding, 'replace').encode('utf-8', 'replace')
+ _name_utf8 = _name_utf8.decode(
+ encoding, 'replace').encode('utf-8', 'replace')
- path = path.decode('utf-8', 'replace').encode(default_encoding, 'replace')
+ path = path.decode('utf-8', 'replace').encode(
+ default_encoding, 'replace')
- path = path.decode('utf-8', 'replace').encode(default_encoding, 'replace')
+ path = path.decode('utf-8', 'replace').encode(
+ default_encoding, 'replace')
- path = path.decode(encoding, 'replace').encode(default_encoding, 'replace')
+ path = path.decode(encoding, 'replace').encode(
+ default_encoding, 'replace')
- name = name_utf8.decode('utf-8', 'replace').encode(default_encoding, 'replace')
+ name = name_utf8.decode('utf-8', 'replace').encode(
+ default_encoding, 'replace')
- name = name.decode(encoding, 'replace').encode(default_encoding, 'replace')
+ name = name.decode(encoding, 'replace').encode(
+ default_encoding, 'replace')
'created by', 'creation date', 'encoding', \
'nodes', 'publisher', 'publisher-url':
if name == 'comment' and 'comment.utf-8' in torrent:
'created by', 'creation date', 'encoding', \
'nodes', 'publisher', 'publisher-url':
if name == 'comment' and 'comment.utf-8' in torrent:
meta.append(('.META/' + name, len(data)))
elif name in torrent:
if name == 'announce-list':
meta.append(('.META/' + name, len(data)))
elif name in torrent:
if name == 'announce-list':
if 'piece length' in info:
meta.append(('.META/piece length', len(str(info['piece length']))))
if 'piece length' in info:
meta.append(('.META/piece length', len(str(info['piece length']))))
- for name, size in paths + meta:
- print "-r--r--r-- 1 user group %d Jan 1 00:00 %s" % (size, name)
+ paths += meta
+ dirs = set()
+ for name, size in paths:
+ if '/' in name:
+ dirs.add(dirname(name))
+
+ if not dt:
+ dt = decode_datetime(getmtime(sys.argv[2]))
+
+ for name in sorted(dirs):
+ print "dr-xr-xr-x 1 user group 0 %s %s" % (dt, name)
+
+ for name, size in sorted(paths):
+ print "-r--r--r-- 1 user group %d %s %s" % (size, dt, name)
'created by', 'creation date', 'encoding', \
'nodes', 'publisher', 'publisher-url':
if name == 'comment' and 'comment.utf-8' in torrent:
'created by', 'creation date', 'encoding', \
'nodes', 'publisher', 'publisher-url':
if name == 'comment' and 'comment.utf-8' in torrent:
- data = torrent['comment.utf-8'].decode('utf-8').encode(default_encoding, 'replace')
- meta.append(('.META/' + name, len(data)))
+ data = torrent['comment.utf-8'].decode('utf-8').encode(
+ default_encoding, 'replace')
- data = ['%s:%s' % (host, port) for host, port in torrent[name]]
+ data = ['%s:%s' % (host, port)
+ for host, port in torrent[name]]
"""Put a file to the VFS"""
sys.exit("Torrent VFS doesn't support adding files (read-only filesystem)")
"""Put a file to the VFS"""
sys.exit("Torrent VFS doesn't support adding files (read-only filesystem)")
def torrent_error(error_str):
logger.critical("Error parsing the torrent metafile: %s", error_str)
sys.exit(1)
def torrent_error(error_str):
logger.critical("Error parsing the torrent metafile: %s", error_str)
sys.exit(1)
- from time import localtime, asctime
- the_time = float(dt)
- l_now = localtime(the_time)
- return asctime(l_now)
+ try:
+ Y, m, d, H, M = localtime(float(dt))[0:5]
+ except ValueError:
+ return datetime.max.ctime()
+ else:
+ return "%02d-%02d-%d %02d:%02d" % (m, d, Y, H, M)
+