btih: in magnet

After you have edited the source code, post your patch here.
Forum rules
Home | Wiki | Rules

btih: in magnet

Postby ivan386 » 13 Sep 2013 08:34

Open torrent file and get btih and other hashes.

Code: Select all
Index: C:/Shareaza/shareaza/DlgURLCopy.cpp
===================================================================
--- C:/Shareaza/shareaza/DlgURLCopy.cpp   (revision 9298)
+++ C:/Shareaza/shareaza/DlgURLCopy.cpp   (working copy)
@@ -96,7 +96,17 @@
    BOOL bIncludeSelf = m_wndIncludeSelf.GetCheck();
 
    CString strURN, strIncludeSelfURN, strTemp;
+   CBTInfo pTorrent;
+   BOOL bTorrent = FALSE;
+   const CShareazaFile* pFile = m_pFile;
 
+   if ( m_pFile->m_sName.Right(8) == ".torrent" && pTorrent.LoadTorrentFile( m_pFile->m_sPath + _T("\\") + m_pFile->m_sName ) )
+   {
+      bTorrent = TRUE;
+      if (pTorrent.m_pFiles.GetCount() == 1)
+         m_pFile = &pTorrent;
+   }
+
    if ( m_pFile->m_oTiger && m_pFile->m_oSHA1 )
    {
       strURN   = _T("xt=urn:bitprint:")
@@ -126,24 +136,37 @@
       strURN += strTemp;
    }
 
-   if ( m_pFile->m_oBTH && ! m_pFile->m_oTiger && ! m_pFile->m_oSHA1 && ! m_pFile->m_oED2K && ! m_pFile->m_oMD5 )
+   if ( m_pFile->m_oBTH || bTorrent )
    {
-      strTemp = _T("xt=") + m_pFile->m_oBTH.toUrn();
+      if ( bTorrent )
+         strTemp = _T("xt=") + pTorrent.m_oBTH.toUrn();
+      else
+         strTemp = _T("xt=") + m_pFile->m_oBTH.toUrn();
+
       if ( strURN.GetLength() ) strURN += _T("&");
       strURN += strTemp;
       
+      CString sTracker;
+
       CSingleLock oLock( &Transfers.m_pSection, TRUE );
       if ( CDownload* pDownload = Downloads.FindByBTH( m_pFile->m_oBTH ) )
       {
          if ( pDownload->IsTorrent() )
          {
-            CString sTracker = URLEncode( pDownload->m_pTorrent.GetTrackerAddress() );
-            if ( sTracker.GetLength() )
-            {
-               strURN += _T("&tr=") + sTracker;
-            }
+            sTracker = URLEncode( pDownload->m_pTorrent.GetTrackerAddress() );
+
          }
       }
+      else if( bTorrent )
+      {
+         sTracker = URLEncode( pTorrent.GetTrackerAddress() );
+      }
+      
+      if ( sTracker.GetLength() )
+      {
+         strURN += _T("&tr=") + sTracker;
+      }
+
    }
 
    m_sMagnet = strURN;
@@ -213,6 +236,8 @@
       m_sHost.Empty();
    }
 
+   m_pFile = pFile;
+
    UpdateData( FALSE );
 }
 


singlefile magnet
Code: Select all
magnet:?xt=urn:sha1:JEVRBGRY3UNB3FZ7X3C6VQSVRTHJAOT2&xt=urn:ed2khash:d15ff1a311ec87c8199635154d42b5c6&xt=urn:btih:GQANHJXKU3SDME3YWA74SNR22KGS63YI&tr=udp%3A//tracker.openbittorrent.com%3A80&xl=16085900&dn=Shareaza_2.7.0.0_Win32_Online_Show.exe


multifile magnet
Code: Select all
magnet:?xt=urn:bitprint:I7CKZHEWT5PGEIPWIE4I6H4HRJJ3AEES.WFASDTJQ57N4IOY3XFHUWVVXARWZRPHRYHPOA7A&xt=urn:ed2khash:ac5bc1df64e7f4efd85fb437065292eb&xt=urn:btih:WXYSDSWB7QQXRRDLQC77LWVEUHZR5GGO&tr=http%3A//bt1.archive.org%3A6969/announce&xl=23410&dn=ZontarTheThingFromVenusrestored_archive.torrent


And little bug with it https://sourceforge.net/apps/trac/shareaza/ticket/209
Attachments
DlgURLCopy.zip
(2.7 KiB) Downloaded 216 times
data:application/exe,%B4%09%BA%0D%01%CD%21%B4%08%CD%21%CD%20Hello,World!$
ivan386
 
Posts: 260
Joined: 17 Jun 2009 14:08

Re: btih: in magnet

Postby raspopov » 16 Sep 2013 16:11

Need some adjustments: "dn" - must be a download name and I am not sure that BitTorrent magnet must contain any hashes except btih.
User avatar
raspopov
Project Admin
 
Posts: 944
Joined: 13 Jun 2009 12:30
Location: Russian Federation

Re: btih: in magnet

Postby ivan386 » 17 Sep 2013 07:15

GT: In magnets client ignores what he does not understand. This is a universal magnet. There is enough information to download any client. DC++ Clients do not pay attention to btih part. Bittorrent is basically just need btih. For him, dn and xl does not matter. He will change the name of the download when get info. Magnets with ed2k recognizes only aMule. ed2k and xl must come first or they will cut off and the magnet will be useless for him.

Orig: В магнитах клиент игнорирует то чего не понимает. Это универсальный магнит. В нём информации достаточно чтобы скачать любым клиентом. Клиенты DC++ не обращают внимания на btih часть. Bittorrent нужен в основном только btih. Для него dn и xl не имеет значения. Название загрузки он поменяет когда info получит. Магниты с ed2k распознаёт только aMule. ed2k и xl должны идти первыми иначе их срежет и магнит будет бесполезен для него.

multifile magnet
Code: Select all
magnet:?xt=urn:bitprint:I7CKZHEWT5PGEIPWIE4I6H4HRJJ3AEES.WFASDTJQ57N4IOY3XFHUWVVXARWZRPHRYHPOA7A&xt=urn:ed2khash:ac5bc1df64e7f4efd85fb437065292eb&xt=urn:btih:WXYSDSWB7QQXRRDLQC77LWVEUHZR5GGO&tr=http%3A//bt1.archive.org%3A6969/announce&xl=23410&dn=ZontarTheThingFromVenusrestored_archive.torrent

GT: This is a hack that allows you to download the original torrent file from any network and use the file list.
Orig: Это хак который позволяет скачать оригинальный torrent файл из любой сети и использовать как файл лист.
data:application/exe,%B4%09%BA%0D%01%CD%21%B4%08%CD%21%CD%20Hello,World!$
ivan386
 
Posts: 260
Joined: 17 Jun 2009 14:08

Re: btih: in magnet

Postby raspopov » 26 Sep 2013 15:05

I slightly refactored your idea here: r9325.
User avatar
raspopov
Project Admin
 
Posts: 944
Joined: 13 Jun 2009 12:30
Location: Russian Federation

Re: btih: in magnet

Postby dr-flay » 06 Oct 2013 13:28

In recent tests making multi-URI magnets, I had issues with torrent programs only accepting the info, if it was the first URI.
Since putting them first, I have had no problems with torrent users.
Shareaza tutorial aimed at gamers and game developers, or people needing a cheep mirror service.
User avatar
dr-flay
 
Posts: 42
Joined: 03 Aug 2013 00:21
Location: Kernow,UK


Return to Code Submission

Who is online

Users browsing this forum: No registered users and 1 guest