Drommer

Peerflix pull requests patch

Oct 13th, 2022
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | Software | 0 0
  1. #Fix unresponsive keyboard input when is used with an -l flag (by tryzniak)
  2. #Show downloaded percentage on prompt file selection (by haodemon)
  3. #Add some extra features and fixed somes bugs (by meteor314)
  4.  
  5. diff -up a/app.js b/app.js
  6. --- a/app.js
  7. +++ b/app.js
  8. @@ -17,2 +17,3 @@
  9. var path = require('path')
  10. +var fs = require('fs')
  11.  
  12. @@ -47,2 +48,3 @@
  13. .alias('d', 'not-on-top').describe('d', 'do not float video on top').boolean('d')
  14. + .describe('exit', 'exit peerflix on download').boolean('n')
  15. .describe('on-downloaded', 'script to call when file is 100% downloaded')
  16. @@ -155,2 +157,11 @@
  17. if (interactive) {
  18. + var getDownloadedSize = function (file) {
  19. + var p = path.join(engine.path, file.path)
  20. + if (fs.existsSync(p)) {
  21. + var size = fs.statSync(p).size
  22. + return Math.round(size / file.length) * 100 // percentage
  23. + }
  24. + return 0
  25. + }
  26. +
  27. var filenamesInOriginalOrder = engine.files.map(file => file.path)
  28. @@ -164,3 +175,3 @@
  29. return {
  30. - name: file.name + ' : ' + bytes(file.length),
  31. + name: file.name + ' : ' + bytes(file.length) + ' (' + getDownloadedSize(file) + '%)',
  32. value: filenamesInOriginalOrder.indexOf(file.path)
  33. @@ -214,2 +225,8 @@
  34.  
  35. + if (argv['exit']) {
  36. + engine.on('uninterested', function () {
  37. + process.exit(0)
  38. + })
  39. + }
  40. +
  41. engine.server.on('listening', function () {
  42. @@ -345,5 +362,5 @@
  43.  
  44. - var interactive = !player && process.stdin.isTTY && !!process.stdin.setRawMode
  45. + var interactive = process.stdin.isTTY && !!process.stdin.setRawMode
  46.  
  47. - if (interactive) {
  48. + if (!interactive) {
  49. keypress(process.stdin)
  50. @@ -389,2 +406,3 @@
  51. process.stdin.setRawMode(true)
  52. + process.stdin.resume()
  53. }
  54. @@ -410,4 +428,13 @@
  55. clivas.line('{yellow:info} {green:streaming} {bold:' + filename + ' (' + bytes(filelength) + ')} {green:-} {bold:' + bytes(swarm.downloadSpeed()) + '/s} {green:from} {bold:' + unchoked.length + '/' + wires.length + '} {green:peers} ')
  56. - clivas.line('{yellow:info} {green:path} {cyan:' + engine.path + '}')
  57. clivas.line('{yellow:info} {green:downloaded} {bold:' + bytes(swarm.downloaded) + '} (' + downloadedPercentage + '%) {green:and uploaded }{bold:' + bytes(swarm.uploaded) + '} {green:in }{bold:' + runtime + 's} {green:with} {bold:' + hotswaps + '} {green:hotswaps} ')
  58. + // calculate estimated time from remaining bytes for the whole torrent and current download speed
  59. + var estimatedTime = (swarm.downloaded > 0) ? Math.floor(((engine.torrent.length) - swarm.downloaded) / swarm.downloadSpeed()) : 0;
  60. + var estimatedTimeString = ''
  61. + var estimatedHour = Math.floor(estimatedTime /(60*60))
  62. + // calculate estimated minutes romainig
  63. + var estimatedMinute = Math.floor((estimatedTime - estimatedHour*60*60)/60)
  64. + if (estimatedTime > 0) {
  65. + estimatedTimeString = '{yellow:info} {green: estimated time remaining for the complete download of this torrent} {bold:' + estimatedHour + 'h ' + estimatedMinute + 'm ' + Math.floor(estimatedTime % 60) + 's}'
  66. + clivas.line(estimatedTimeString)
  67. + }
  68. clivas.line('{yellow:info} {green:verified} {bold:' + verified + '} {green:pieces and received} {bold:' + invalid + '} {green:invalid pieces}')
  69. @@ -415,9 +442,3 @@
  70. clivas.line('{80:}')
  71. -
  72. - if (interactive) {
  73. - var openLoc = ' or CTRL+L to open download location}'
  74. - if (paused) clivas.line('{yellow:PAUSED} {green:Press SPACE to continue download' + openLoc)
  75. - else clivas.line('{50+green:Press SPACE to pause download' + openLoc)
  76. - }
  77. -
  78. + clivas.line('{yellow:info} {green:path} {cyan:' + engine.path + '}')
  79. clivas.line('')
  80.  
Add Comment
Please, Sign In to add comment