From 35072541a1f528ff91a5a279d1cf9036bcddacf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Rodr=C3=ADguez?= Date: Sun, 28 Feb 2016 02:47:19 -0300 Subject: [PATCH] v0.14 - Viewer view --- 200.jade | 9 ++-- app.coffee | 81 +++++++++++++++++++++++++--------- style.sass | 4 ++ views/{main.jade => full.jade} | 0 views/stream.jade | 3 -- views/view.jade | 16 +++++++ 6 files changed, 85 insertions(+), 28 deletions(-) rename views/{main.jade => full.jade} (100%) delete mode 100644 views/stream.jade create mode 100644 views/view.jade diff --git a/200.jade b/200.jade index 9c71858..ba1e225 100644 --- a/200.jade +++ b/200.jade @@ -8,7 +8,7 @@ html(ng-app='BTorrent', lang='en') meta(name='keywords', content='βTorrent, btorrent, client, webtorrent, browser, torrent, stream, bittorrent, torrenting, sharing, filesharing') meta(name='author', content='Diego Rodríguez Baquero - DiegoRBaquero') meta(name='viewport', content='width=device-width, initial-scale=1') - script(src='https://cdn.jsdelivr.net/g/webtorrent@0.78,momentjs@2.11,angularjs@1.4(angular.min.js+angular-route.min.js+angular-sanitize.min.js),angular.ui-grid@3.1,angular.ng-notify@0.7,angular.file-upload@12') + script(src='https://cdn.jsdelivr.net/g/webtorrent@0.79,momentjs@2.11,angularjs@1.4(angular.min.js+angular-route.min.js+angular-sanitize.min.js),angular.ui-grid@3.1,angular.ng-notify@0.7,angular.file-upload@12') link(rel='stylesheet', href='https://cdn.jsdelivr.net/g/normalize@3.0,skeleton@2.0,angular.ng-notify@0.7(ng-notify.min.css)') link(rel='stylesheet', href='https://cdn.jsdelivr.net/fontawesome/4.5/css/font-awesome.min.css') link(rel='stylesheet', href='https://cdn.jsdelivr.net/angular.ui-grid/3.1/ui-grid.min.css') @@ -17,11 +17,14 @@ html(ng-app='BTorrent', lang='en') header h1 | βTorrent - span.version v0.13.1 - div.views + span.version v0.14.0 + div.views(ng-show='$root.client.torrents.length == 0') a(ng-href='/#') Full | | a(ng-href='/download') Single Download + | | + a(ng-href='/view') Stream / View + #viewer #view(ng-view) footer a.button(href="https://github.com/DiegoRBaquero/BTorrent/issues", target="_blank") diff --git a/app.coffee b/app.coffee index 9572e25..0d95e02 100644 --- a/app.coffee +++ b/app.coffee @@ -50,15 +50,15 @@ app = angular.module 'BTorrent', ['ngRoute', 'ui.grid', 'ui.grid.resizeColumns', requireBase: false ).hashPrefix '#' - $routeProvider.when '/stream', - templateUrl: 'views/stream.html' - controller: 'StreamCtrl' + $routeProvider.when '/view', + templateUrl: 'views/view.html' + controller: 'ViewCtrl' .when '/download', templateUrl: 'views/download.html' controller: 'DownloadCtrl' .otherwise - templateUrl: 'views/main.html' - controller: 'MainCtrl' + templateUrl: 'views/full.html' + controller: 'FullCtrl' ] app.controller 'BTorrentCtrl', ['$scope','$rootScope','$http','$log','$location', 'ngNotify', ($scope, $rootScope, $http, $log, $location, ngNotify) -> @@ -103,11 +103,11 @@ app.controller 'BTorrentCtrl', ['$scope','$rootScope','$http','$log','$location' ngNotify.set err, 'error' er err, torrent - $rootScope.addMagnet = (magnet) -> + $rootScope.addMagnet = (magnet, onTorrent) -> if magnet? && magnet.length > 0 dbg 'Adding magnet/hash ' + magnet $rootScope.client.processing = true - $rootScope.client.add magnet, opts, $rootScope.onTorrent + $rootScope.client.add magnet, opts, onTorrent || $rootScope.onTorrent $rootScope.destroyedTorrent = (err) -> if err @@ -129,6 +129,8 @@ app.controller 'BTorrentCtrl', ['$scope','$rootScope','$http','$log','$location' torrent.safeTorrentFileURL = torrent.torrentFileBlobURL torrent.fileName = torrent.name + '.torrent' if !isSeed + dbg 'Received metadata', torrent + ngNotify.set 'Received ' + torrent.name + ' metadata' if !($rootScope.selectedTorrent?) $rootScope.selectedTorrent = torrent $rootScope.client.processing = false @@ -145,11 +147,6 @@ app.controller 'BTorrentCtrl', ['$scope','$rootScope','$http','$log','$location' if !isSeed dbg 'Done ', file ngNotify.set '' + file.name + ' ready for download', 'success' - if !isSeed - dbg 'Received metadata', file - ngNotify.set 'Received ' + torrent.name + ' metadata' - console.info $rootScope.client - console.info $rootScope.client torrent.on 'download', (chunkSize) -> #if !isSeed # dbg 'Downloaded chunk', torrent @@ -167,17 +164,10 @@ app.controller 'BTorrentCtrl', ['$scope','$rootScope','$http','$log','$location' $rootScope.onSeed = (torrent) -> $rootScope.onTorrent torrent, true - if $location.hash() != '' - $rootScope.client.processing = true - setTimeout -> - dbg 'Adding ' + $location.hash() - $rootScope.client.add $location.hash(), $rootScope.onTorrent - , 0 - dbg 'Ready' ] -app.controller 'MainCtrl', ['$scope','$rootScope','$http','$log','$location', 'ngNotify', ($scope, $rootScope, $http, $log, $location, ngNotify) -> +app.controller 'FullCtrl', ['$scope','$rootScope','$http','$log','$location', 'ngNotify', ($scope, $rootScope, $http, $log, $location, ngNotify) -> ngNotify.config duration: 10000 html: true @@ -215,6 +205,13 @@ app.controller 'MainCtrl', ['$scope','$rootScope','$http','$log','$location', 'n $rootScope.selectedTorrent = null else $rootScope.selectedTorrent = row.entity + + if $location.hash() != '' + $rootScope.client.processing = true + setTimeout -> + dbg 'Adding ' + $location.hash() + $rootScope.client.add $location.hash(), $rootScope.onTorrent + , 0 ] app.controller 'DownloadCtrl', ['$scope','$rootScope','$http','$log','$location', 'ngNotify', ($scope, $rootScope, $http, $log, $location, ngNotify) -> @@ -225,16 +222,56 @@ app.controller 'DownloadCtrl', ['$scope','$rootScope','$http','$log','$location' $scope.addMagnet = -> $rootScope.addMagnet($scope.torrentInput) $scope.torrentInput = '' + + if $location.hash() != '' + $rootScope.client.processing = true + setTimeout -> + dbg 'Adding ' + $location.hash() + $rootScope.client.add $location.hash(), $rootScope.onTorrent + , 0 ] -app.controller 'StreamCtrl', ['$scope','$rootScope','$http','$log','$location', 'ngNotify', ($scope, $rootScope, $http, $log, $location, ngNotify) -> +app.controller 'ViewCtrl', ['$scope','$rootScope','$http','$log','$location', 'ngNotify', ($scope, $rootScope, $http, $log, $location, ngNotify) -> ngNotify.config duration: 10000 html: true + onTorrent = (torrent, isSeed) -> + dbg torrent.magnetURI + torrent.safeTorrentFileURL = torrent.torrentFileBlobURL + torrent.fileName = torrent.name + '.torrent' + $rootScope.selectedTorrent = torrent + $rootScope.client.processing = false + dbg 'Received metadata', torrent + ngNotify.set 'Received ' + torrent.name + ' metadata' + torrent.files.forEach (file) -> + file.appendTo '#viewer' + file.getBlobURL (err, url) -> + if err + throw err + file.url = url + dbg 'Done ', file + torrent.on 'download', (chunkSize) -> + # dbg 'Downloaded chunk', torrent + torrent.on 'upload', (chunkSize) -> + #dbg 'Uploaded chunk', torrent + torrent.on 'done', -> + dbg 'Done', torrent + torrent.on 'wire', (wire, addr) -> + dbg 'Wire ' + addr, torrent + torrent.on 'error', (err) -> + er err + $scope.addMagnet = -> - $rootScope.addMagnet($scope.torrentInput) + $rootScope.addMagnet $scope.torrentInput, onTorrent $scope.torrentInput = '' + + if $location.hash() != '' + $rootScope.client.processing = true + setTimeout -> + dbg 'Adding ' + $location.hash() + $rootScope.client.add $location.hash(), onTorrent + , 0 ] app.filter 'html', ['$sce', ($sce) -> diff --git a/style.sass b/style.sass index c6bdac3..f5ef325 100644 --- a/style.sass +++ b/style.sass @@ -16,6 +16,9 @@ h2, h3, h4, h5, h6, ul, li footer margin-top: 10px + +#viewer + margin-top: -20px .container width: 95% @@ -32,6 +35,7 @@ footer .views margin-top: -20px + margin-bottom: 10px .download-button margin-left: 10px diff --git a/views/main.jade b/views/full.jade similarity index 100% rename from views/main.jade rename to views/full.jade diff --git a/views/stream.jade b/views/stream.jade deleted file mode 100644 index 29c2278..0000000 --- a/views/stream.jade +++ /dev/null @@ -1,3 +0,0 @@ -.container - .row - h1 Hello \ No newline at end of file diff --git a/views/view.jade b/views/view.jade new file mode 100644 index 0000000..2d58f26 --- /dev/null +++ b/views/view.jade @@ -0,0 +1,16 @@ +.container + div(ng-hide='$root.client.torrents.length != 0', style='vertical-align: middle; text-align: center') + .row + form.no-margin(ng-submit='addMagnet()') + label Enter magnet, hash or http(s) .torrent + input(type='text', placeholder='magnet, hash or http(s) .torrent', ng-model='torrentInput', ng-disabled='$root.disabled', style='width: 50%') + //button(ng-click='addMagnet()', ng-disabled='!torrentInput.length || $root.disabled', ng-class='{"button-primary": torrentInput.length}') + i.fa.fa-download + | Download + .row + label or... + button(type='file', ngf-select='$root.openTorrentFile($file)', ng-disabled='$root.disabled', ng-class='{"button-primary": !$root.disabled}') + i.fa.fa-folder-open + | Open torrent file + .div(ng-if="selectedTorrent", style="text-align: center") + | Downloaded {{$root.selectedTorrent.downloaded | pbytes}}/{{$root.selectedTorrent.length | pbytes}} ({{$root.selectedTorrent.progress | progress}}) at {{$root.selectedTorrent.downloadSpeed | pbytes:1}} from {{$root.selectedTorrent.numPeers}} peers. ETA: {{$root.selectedTorrent.timeRemaining | humanTime}} \ No newline at end of file