News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

BBC Magnet Link

Started by dodos26, May 08, 2022, 02:27:36 PM

Previous topic - Next topic

dodos26

Link to the mod

BBC magnet link

Thanks for installing BBC Magnet Link!
Mod create by Dominik.

Version 1.0.6 for SMF 2.0.* & 2.1.*

With this mod you will get bbc for magnet links, making it possible for users to open them.
That's not all, because the modification will read the name of the torrent and display it instead of the link and in front of the name, he will add a nice information icon.
That's not all, because the modification will connect to trackers to get torrent data from them and then display the number of leech seeds and download next to the name.

The modification scans all trackers one by one, until it receives information from one of them or the list is over. Remember to set up good and proven trackers above. Prioritize http (s) trackers at the top of the list.
Also note that many service providers will not let you connect using the udp protocol. You will need to ask your service provider to allow it or run your own web server.

I decided to add this as a new mod because it's not hook only. Add one line of code in "subs.php". And it has a lot of key news.

1.0.7:
- Fixed "undefined array" bug causing infinite loading. Error in advanced bug reporting settings.
- New / Change: If trackers are not responding and the click counter is enabled, their number is shown.

1.0.6:
- Code optimizations.
- Added counting of clicks on a magnetic link. Assigned to the link hash.
- New settings section. And improved settings and their default values.
- Minor bug and security fixes.
- Small change css style.
- Changes in javascript, optimizations and when there were a lot of links in one post or own page, the page could get stuck due to the excessive number of queries from the user and the limitations of these queries. Now the problem is solved and the function can be used on your own ranking lists. (abortActiveRequests)
- The new click counter has connections in which message the link was clicked on, so you can create analytical data and your own rankings.

1.0.5:
- Several optimizations to the runtime code.
- More efficient regular expressions 5000 steps less.
- The display of magnet links is now nicer and responsive.

1.0.4:
- Fixed: Issue with warnings in php logs not working in forum logs.

1.0.3:
- The mod gains in this version an advanced settings system to personalize the settings for yourself.
- From now on, messages load at normal speed because jquery is used and the download of statistics is performed after loading the post.
- An update button has also been added.
- The add-on will also scan attachments in a post with a magnet link and will display the number of downloads next to the magnet link.
- Added the ability to indicate where the attachment data is to be downloaded from "[magnet=LINK TO MESSAGE]MAGNET LINK[/magnet]


Work on 2.0.* perfect! Work also on 2.1.* perfect!







stefanop039

Hello, I would like to know if it is possible to remove (when the magnet link is displayed) the seeds, leeches and downloads, leaving only the name of the magnet link visible. See attached image.

thank


dodos26

#2
Quote from: stefanop039 on December 20, 2022, 11:05:47 AMHello, I would like to know if it is possible to remove (when the magnet link is displayed) the seeds, leeches and downloads, leaving only the name of the magnet link visible. See attached image.

thank



Yea, go to Soucres folder and find Subs-Magnet_Link.php and open it:

Next find:
function BBC_Magnet_Format
Replace the entire function with:
function BBC_Magnet_Format(&$input_magnet)
{
    global $txt, $modSettings;

    loadLanguage('bbc_magnet_link');
    if (!empty($input_magnet)) {
        if (preg_match("(^magnet)", $input_magnet)) {

            $input_magnet = html_entity_decode($input_magnet, ENT_QUOTES, "UTF-8");
            $input_magnet = urldecode($input_magnet);

            $input_magnet = str_replace(
                    array("á","é","í","ó","ú","ñ","Á","É","Í","Ó","Ú","Ñ"),
                        array("á","é","í","ó","ú","ń","Á","É","Í","Ó","Ú","Ń"), $input_magnet);

            preg_match('#magnet:\?xt=urn:btih:(?<hash>.*?)&dn=(?<filename>.*?)&tr=(?<trackers>.*?)$#', $input_magnet, $magnet_parts);

            if (!empty($magnet_parts['trackers'])) {

                $magnet_parts['trackers'] = explode('&', str_replace('tr=','', $magnet_parts['trackers']));

                $magnet_parts['trackers'] = array_values($magnet_parts['trackers']);

                if (!empty($magnet_parts['trackers'][0])) {

                    if (!empty($magnet_parts['hash']) && !empty($magnet_parts['filename'])) {

                        $data = '<img class="magnet_link" title="'. $magnet_parts['filename'] .'">
                            <strong>
                                <a href="'. $input_magnet .'" title="'. $magnet_parts['filename'] .'" target="_self">'. $magnet_parts['filename'] .'</a>
                            </strong><br>';
                       
                    } else    $data = '<img class="magnet_link" title="'. $txt['magnet_link_error_bad_magnet_link'] .'"> <strong>'. $txt['magnet_link_error_bad_magnet_link'] .'.</strong><br>';
                } else    $data = '<img class="magnet_link" title="'. $txt['magnet_link_error_no_http_trackers'] .'"> <strong>'. $txt['magnet_link_error_no_http_trackers'] .'.</strong><br>';
            } else $data = '<img class="magnet_link" title="'. $txt['magnet_link_error_lack_trackers'] .'"> <strong>'. $txt['magnet_link_error_lack_trackers'] .'.</strong><br>';
        } else $data = '<img class="magnet_link" title="'. $txt['magnet_link_error_not_magnet_link'] .'"> <strong>'. $txt['magnet_link_error_not_magnet_link'] .'.</strong><br>';
    } else $data = '<img class="magnet_link" title="'. $txt['magnet_link_error_no_input_data'] .'"> <strong>'. $txt['magnet_link_error_no_input_data'] .'.</strong><br>';

    return $data;
}

Or download attach and replace the file. This will not negatively affect the ability to uninstall from the package manager.


It should work on a quick launch and I didn't notice any problems. I will add this as an option to the official release as soon as I manage to solve a problem with a new feature I want to add.


stefanop039

Thanks a lot, everything perfect, I downloaded and replaced the attachment

dodos26

1.0.3:
- The mod gains in this version an advanced settings system to personalize the settings for yourself.
- From now on, messages load at normal speed because jquery is used and the download of statistics is performed after loading the post.
- An update button has also been added.
- The add-on will also scan attachments in a post with a magnet link and will display the number of downloads next to the magnet link.
- Added the ability to indicate where the attachment data is to be downloaded from "[magnet=LINK TO POST]MAGNET LINK[/magnet]

dodos26

1.0.4:
- Fixed: Issue with warnings in php logs (bug fixed) not appearing in forum logs.

dodos26

1.0.5:
- Several optimizations to the runtime code.
- More efficient regular expressions 5000 steps less.
- The display of magnet links is now nicer and responsive.


dodos26

1.0.6:
- Code optimizations.
- Added counting of clicks on a magnetic link. Assigned to the link hash.
- New settings section. And improved settings and their default values.
- Minor bug and security fixes.
- Small change css style.
- Changes in javascript, optimizations and when there were a lot of links in one post or own page, the page could get stuck due to the excessive number of queries from the user and the limitations of these queries. Now the problem is solved and the function can be used on your own ranking lists. (abortActiveRequests)
- The new click counter has connections in which message the link was clicked on, so you can create analytical data and your own rankings.

couchtripper

This seemed to work (though the link did not show info - it was just a standard looking link), but it removed the drop down menu which would allow me to delete or move the topic. I did the subs.php edit and it had no effect.

When I uninstalled the mod, that ability came back.

I'm using the Potato theme on 2.1.4. if that's relevant.

dodos26

#9
If you are using a webhost, udp may be restricted. Use a torrent with http tracker first on the list and try again. This may not work well if you have it running locally on your private machine (private ip and forwarded ports..)
Try also enable:
"Polling / Scraping via announce:
Use announce to polling / scrape trackers instead of scrape."
And if work, try disable and check result.

My modification does not affect the post / topic menu.
Maybe the css style conflicts with your theme. The bbcode in version 2.1 is bugged, I don't know what causes it but often new bbcodes don't appear immediately. I prefer 2.0.19 :P

dodos26

#10
I tested the disappearing menu issue in your theme. I confirm the issue, the culprit is the use of an older version of jquery by your theme. My modification loads a newer version if possible, inform the author of the theme about the update.

Temporarily you can remove jquery loading by my modification. Open "Subs-Magnet_Link.php" in "Soucres" folder, find "function Magnet_bbc_theme()" and remove line "<script ... jquery ...</script>

Thanks to you I found a micro bug that could cause errors in certain circumstances when the server returns an undefined array error in php echo. I will add an update right away and the solution I gave above will solve your error with the menu.

1.0.7:
- Fixed "undefined array" bug causing infinite loading. Error in advanced bug reporting settings.
- New / Change: If trackers are not responding and the click counter is enabled, their number is shown.

Advertisement: