Results 1 to 5 of 5

Thread: Displaying torrent metainfos help...

  1. #1
    Join Date
    Jul 2008
    Location
    Newton City, Terminus
    Beans
    60
    Distro
    Ubuntu 8.04 Hardy Heron

    Displaying torrent metainfos help...

    How to read a *.torrent meta infos? I tried gedit and it cannot recognize the encodings and even nano give something incomprehensible. Afterwards, I made a simple C code to read the first 1000 characters and it works only for the first few characters. Here's the output:
    Code:
    d8:announce43:http://tracker.datorrents.com:6969/announce7:comment19:http://aerosubs.net10:created by13:uTorrent/180013:creation datei1224165828e8:encoding5:UTF-84:infod6:lengthi173765965e4:name38:Toradora_-_03[h264][848x480][Aero].mkv12:piece lengthi262144e6:pieces13260:C�Q����W|���ԫ��ظ{pkn@od��W�a��B���fb|�����A�*��0:���C�9	}�+�}D��C��u?���ߧp��>�!����f9H�7�Q8H��
                                           ��c��EU��bx��;�ڋ��~%u@)� �b�k';H���x���v��v������I��_�|N(����T{4���TH8�M��A`��{K�&�y���52C!�k�K���	�����&v[������
                                                             ���c·ÀKå;³¬A<5ÄÝò7�ûÿ␊␍©␌Ùì[„³Ñ£ùäÑÔç�Ÿ\À�├à⎻Å!ï@(Œ¡ï⎼ì¼Ç�Êç¹ôôºM¾┌Ë≥‡├…]œ«Å¦0W“ž¼Û«
                                                  G“] ¨ë│¢€!å␉æGÞ«	ñ•,ý®èÚ?씑≥çÒáí-	NW𜼅·DÕŒÔ�ºπ⎼
    
    ˯ÏÉ®þ│TLÝ6žÈ0AŸPYT´P��.F»êöMá‘ø.†9îÔ’ÁT⎺$=KBHÕ?ôá_≥�E0¸\MLAÒ─±ìˆŒ␊┌²žõQ”œ5øú‰ÊËI⎽û°¦ù4‹⎽’8ƒ├┐
                                                                                                            3á®ðñÎÈ�7·Qù	©*│ŒúÍ·…¿ôÝ÷��
    +µ�¸8F‡J>–á4™Hµ•KÇ. %%“L
    And the codes used to read it is this one.

    Code:
    #include <stdio.h>
    
    int main(int argc, char *argv[])
    {
    	int k;
    	char data;
    	FILE *torrentfiles;
    	torrentfiles=fopen(argv[1],"r");
    	//printf("%d\n",argc);
    	for (k=0;k<1000;k++)
    	{
    		fscanf(torrentfiles,"%c",&data);
    		printf("%c",data);
    	}
    	printf("\n");
    	fclose(torrentfiles);
    		
    	return 0;
    }
    I know that the metainfos are bencoded, but my objective is only to display everything, so how should I do that? Thanks for any advice.

  2. #2
    Join Date
    Feb 2006
    Location
    Vancouver, BC, Canada
    Beans
    318

    Re: Displaying torrent metainfos help...

    Perhaps this utility will provide all you need.
    It's in the package libbtutil-utils.

    Code:
    bob@cob:~$ bt_showmetainfo Nobody_Knows__[Japan_2004].3320213.TPB.torrent
    bt_showmetainfo 0.0.19 - decode BitTorrent metainfo files
    
    metainfo file.: Nobody_Knows__[Japan_2004].3320213.TPB.torrent
    info hash.....: 010192a1287a027a6e47c18ae9893d19895abdfa
    directory name: [2004] Nobody Knows
    files.........:
       tlf-nk.cd1.avi (733976576)
       tlf-nk.cd1.idx (128112)
       tlf-nk.cd1.rar (1162981)
       tlf-nk.cd2.avi (734343168)
       tlf-nk.cd2.idx (47356)
       tlf-nk.cd2.rar (422366)
    archive size..: 1470080559 (1401 * 1048576 + 1025583)
    announce url..: http://tracker.thepirtebay.org/announce
    Otherwise, you should refer to BEP-003 and its extensions for information on writing code to unpack a torrent file. See the links at the end of the wikipedia article:
    http://en.wikipedia.org/wiki/Torrent_file

  3. #3
    Join Date
    Jul 2008
    Location
    Newton City, Terminus
    Beans
    60
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Displaying torrent metainfos help...

    Thanks for the info... I will try looking at it. I'm still wondering why I couldn't read the file since it is supposed to be utf8 and everything. But if you see the output, I already found the file name, amount of pieces, size, announce and most of the stuff given by the utility. The rest of it might be the hash information. Maybe I should look into reading hash instead.

  4. #4
    Join Date
    Feb 2006
    Location
    Vancouver, BC, Canada
    Beans
    318

    Re: Displaying torrent metainfos help...

    You are misunderstanding the format. A torrent file is not supposed to be UTF-8. Strings within the file are supposed to be UTF-8 encoded, but there is a lot of other stuff in the file besides strings.

    Because the file is bencoded, it is guaranteed to be ascii, but not all ascii characters are printable, so many of them will still show up as gibberish in a text editor. This is what you're seeing.

    Things seem to go nuts after the first few hundred bytes of this file because you run into the "pieces" field. It happens here, right after the "piece length" field is shown:

    Code:
    piece lengthi262144e6:pieces13260:C�Q����W
    Remember that the file is laid out as a dictionary, so it is just a bunch of key-value pairs being defined.

    In the snippet above, we see the "piece length" field named, and then it's value (i262144e6, which means the integer value 262144e6.)
    Next is the "pieces" field, which is a byte string type. After the "pieces" field name, we see 13260, which is the field length, followed by a series of ascii characters.

    The pieces field is explained as follows in the Wikipedia article on the torrent file format:
    Code:
    pieces - the concatenation of the SHA-1's of each piece. As SHA-1 returns a 160-bit hash, 
    pieces will be a string whose length is a multiple of 160-bits.
    The main point is, that's binary data, so it's not meaningful to print it in a terminal, so that's why the bt_showmetainfo doesn't show it.

    So what you should do depends on what you want to do with the SHA-1 hashes. They're just not very human-readable data.

  5. #5
    Join Date
    Jul 2008
    Location
    Newton City, Terminus
    Beans
    60
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Displaying torrent metainfos help...

    lol.. no wonder. I will study hashes instead. Thanks for the help.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •