• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript parse-torrent类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中parse-torrent的典型用法代码示例。如果您正苦于以下问题:TypeScript parse-torrent类的具体用法?TypeScript parse-torrent怎么用?TypeScript parse-torrent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了parse-torrent类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: Buffer

import * as parseTorrent from 'parse-torrent';
import * as fs from 'fs';

// info hash (as a hex string)
parseTorrent('d2474e86c95b19b8bcfdb92bc12c9d44667cfa36');
// { infoHash: 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36' }

// info hash (as a Buffer)
parseTorrent(new Buffer('d2474e86c95b19b8bcfdb92bc12c9d44667cfa36', 'hex'));
// { infoHash: 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36' }

// magnet uri (as a utf8 string)
parseTorrent('magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36');
// { xt: 'urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36',
//   infoHash: 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36' }

// magnet uri with torrent name
parseTorrent('magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36&dn=Leaves%20of%20Grass%20by%20Walt%20Whitman.epub');
// { xt: 'urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36',
//   dn: 'Leaves of Grass by Walt Whitman.epub',
//   infoHash: 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36',
//   name: 'Leaves of Grass by Walt Whitman.epub' }

// magnet uri with trackers
parseTorrent('magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36&tr=http%3A%2F%2Ftracker.example.com%2Fannounce');
// { xt: 'urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36',
//   tr: 'http://tracker.example.com/announce',
//   infoHash: 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36',
//   announce: [ 'http://tracker.example.com/announce' ] }

// .torrent file (as a Buffer)
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:31,代码来源:parse-torrent-tests.ts


示例2: ParseTorrent

const tabUpdated = (tabId: number, url: string, state: TorrentsState) => {
  const { torrentStateMap, torrentObjMap } = state
  const origTorrentState: TorrentState = torrentStateMap[tabId]
  const origInfoHash = origTorrentState ? origTorrentState.infoHash : undefined
  let newTorrentState: TorrentState | undefined
  let newInfoHash: string | undefined

  // create new torrent state
  const parsedURL = new window.URL(url)
  const torrentId = parsedURL.href
  if (parsedURL.protocol === 'magnet:') { // parse torrent
    try {
      const { name, infoHash, ix } = ParseTorrent(torrentId)
      newInfoHash = infoHash
      newTorrentState = { tabId, torrentId, name, infoHash, ix }
    } catch (error) {
      newTorrentState = { tabId, torrentId, errorMsg: error.message }
    }
  } else if (parsedURL.protocol === 'https:' || parsedURL.protocol === 'http:') {
    const name = parsedURL.pathname.substr(parsedURL.pathname.lastIndexOf('/') + 1)
    // for .torrent case, ix (index of file) for selecting a specific file in
    // the file list is given in url like #ix=5
    let ix: number | undefined = Number(parse(parsedURL.hash.slice(1)).ix)
    ix = Number.isNaN(ix) ? undefined : ix

    // Use an existing infoHash if it's the same torrentId
    const torrentUrl = parsedURL.origin + parsedURL.pathname
    const key = Object.keys(torrentStateMap).find(
      key => torrentStateMap[key].infoHash &&
        torrentStateMap[key].torrentId === torrentUrl)
    newInfoHash = key
      ? torrentStateMap[key].infoHash
      : undefined

    newTorrentState = { tabId, torrentId, name, ix, infoHash: newInfoHash }
  }

  // delete old torrent state
  delete torrentStateMap[tabId]

  // unsubscribe old torrent if not the same
  const isSameTorrent = newInfoHash && origInfoHash === newInfoHash
  if (origInfoHash && torrentObjMap[origInfoHash] && !isSameTorrent) {
    torrentObjMap[origInfoHash].tabClients.delete(tabId)
    if (!torrentObjMap[origInfoHash].tabClients.size) {
      delete torrentObjMap[origInfoHash]
      delTorrent(origInfoHash)
    }
  }

  // save new torrent state and subscribe directly if torrent already existed
  if (newTorrentState) {
    torrentStateMap[tabId] = newTorrentState
    if (newInfoHash && torrentObjMap[newInfoHash]) {
      torrentObjMap[newInfoHash].tabClients.add(tabId)
    }
  }

  return { ...state, torrentStateMap, torrentObjMap }
}
开发者ID:Snuupy,项目名称:brave-core,代码行数:60,代码来源:webtorrent_reducer.ts


示例3: createTorrentAndSetInfoHash

  async createTorrentAndSetInfoHash (videoFile: VideoFileModel) {
    const options = {
      // Keep the extname, it's used by the client to stream the file inside a web browser
      name: `${this.name} ${videoFile.resolution}p${videoFile.extname}`,
      createdBy: 'PeerTube',
      announceList: [
        [ CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT + '/tracker/socket' ],
        [ CONFIG.WEBSERVER.URL + '/tracker/announce' ]
      ],
      urlList: [
        CONFIG.WEBSERVER.URL + STATIC_PATHS.WEBSEED + this.getVideoFilename(videoFile)
      ]
    }

    const torrent = await createTorrentPromise(this.getVideoFilePath(videoFile), options)

    const filePath = join(CONFIG.STORAGE.TORRENTS_DIR, this.getTorrentFileName(videoFile))
    logger.info('Creating torrent %s.', filePath)

    await writeFilePromise(filePath, torrent)

    const parsedTorrent = parseTorrent(torrent)
    videoFile.infoHash = parsedTorrent.infoHash
  }
开发者ID:jiang263,项目名称:PeerTube,代码行数:24,代码来源:video.ts


示例4: res

    readFile(torrentPath, (err, data) => {
      if (err) return rej(err)

      return res(parseTorrent(data))
    })
开发者ID:jiang263,项目名称:PeerTube,代码行数:5,代码来源:videos.ts



注:本文中的parse-torrent类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript path-to-regexp类代码示例发布时间:2022-05-28
下一篇:
TypeScript pad类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap