Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could you make parseTorrent available? #1457

Closed
jimmywarting opened this issue Aug 3, 2018 · 8 comments
Closed

Could you make parseTorrent available? #1457

jimmywarting opened this issue Aug 3, 2018 · 8 comments
Labels

Comments

@jimmywarting
Copy link
Contributor

@jimmywarting jimmywarting commented Aug 3, 2018

What browser and version? (if using WebTorrent in the browser)
0.100.0

Hi, I was wondering if the parseTorrent could be publicly available throught webtorrent
I'm looking for a way to identify if what the client are adding is a torrent or not. would be useful to have something like .isTorrent(x)

// index.js
WebTorrent.parseTorrent = parseTorrent
@DiegoRBaquero

This comment has been minimized.

Copy link
Member

@DiegoRBaquero DiegoRBaquero commented Aug 3, 2018

Ummmm, but if you add an invalid torrent, you get an error, isn't that enough?

@jimmywarting

This comment has been minimized.

Copy link
Contributor Author

@jimmywarting jimmywarting commented Aug 3, 2018

I would prefer if it was syncron, I have a input where they can add two different things.
Could be a torrent or just regular chitchat text.

Atm i have ripped out the thing I'm most interested from that package which is
this 3 regex:

if (
  /^(stream-)?magnet:/.test(str) || 
  /^[a-f0-9]{40}$/i.test(str) ||
  /^[a-z2-7]{32}$/i.test(str) {
) {
  // Do something torrent related
} else {
  // Do something completely different 
}

Which i just combined into one regex: /(^(stream-)?magnet:|^[a-f0-9]{40}$|^[a-z2-7]{32}$)/
It might be just enough, So I will not be disappointed if parseTorrent don't become available, but still wonder if there is some public intrest in having something like .isTorrent(x)


Edit: And I don't want url's to be tested by client.add(str) therefore i don't want to try to add everything i get from the input

@KayleePop

This comment has been minimized.

Copy link
Contributor

@KayleePop KayleePop commented Aug 4, 2018

Can't you just require it separately and use browserify?

const WebTorrent = require('webtorrent')
const parseTorrent = require('parse-torrent')

const client = new WebTorrent()

function isTorrent (id) {
  try {
    parseTorrent(id)
    return true
  } catch (e) {
    return false
  }
}

if (isTorrent(x)) {
  client.add(x)
}
@jimmywarting

This comment has been minimized.

Copy link
Contributor Author

@jimmywarting jimmywarting commented Aug 4, 2018

Rather use my one regex

@DiegoRBaquero

This comment has been minimized.

Copy link
Member

@DiegoRBaquero DiegoRBaquero commented Aug 6, 2018

Are you using the hosted minified version? Trying to understand the use case

@jimmywarting

This comment has been minimized.

Copy link
Contributor Author

@jimmywarting jimmywarting commented Aug 6, 2018

Yes

@DiegoRBaquero

This comment has been minimized.

Copy link
Member

@DiegoRBaquero DiegoRBaquero commented Aug 24, 2018

I don't see no harm, I'll take a PR

@stale

This comment has been minimized.

Copy link

@stale stale bot commented Nov 22, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the stale label Nov 22, 2018
@stale stale bot closed this Nov 29, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Feb 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.