Example #1
0
    def processurlpressed(self):
        url = self.urlBox.text()
        if not url:
            self.consolewrite("Insert a URL to continue\n")
        else:
            try:
                self.console.clear()
                self.consolewrite("Processing URL\n")
                time.sleep(0.5)
                self.yt = YouTube(url)
            except pytube.exceptions.RegexMatchError:
                traceback.print_exc()
                self.consolewrite("URL not valid\n")
        if self.fileType.currentText() == 'Video':
            try:
                self.vids = self.yt.streams.filter(adaptive=True).filter(subtype='webm').filter(only_video=True).asc().all()
                self.fileTable.setRowCount(0)
                self.fileTable.setColumnCount(5)
                self.fileTable.setHorizontalHeaderLabels(
                    ["Download?","iTag","Resolution","Frame Rate","Filesize"])
                for stream in self.vids:
                    rowPosition = self.fileTable.rowCount()
                    self.fileTable.insertRow(rowPosition)
                    chkBoxItem = QtWidgets.QTableWidgetItem()
                    chkBoxItem.setFlags(QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled)
                    chkBoxItem.setCheckState(QtCore.Qt.Unchecked)
                    self.fileTable.setItem(rowPosition, 0, chkBoxItem)
                    self.fileTable.setItem(rowPosition, 1, QtWidgets.QTableWidgetItem(stream.itag))
                    self.fileTable.setItem(rowPosition, 2, QtWidgets.QTableWidgetItem(stream.resolution))
                    self.fileTable.setItem(rowPosition, 3, QtWidgets.QTableWidgetItem(str(stream.fps)))
                    self.fileTable.setItem(rowPosition, 4, QtWidgets.QTableWidgetItem(
                        size(stream.filesize, system=verbose)))

            except:
                traceback.print_exc()

        elif self.fileType.currentText() == 'Audio':
            try:
                self.vids = self.yt.streams.filter(adaptive=True).filter(subtype='webm').filter(only_audio=True).asc().all()
                self.fileTable.setRowCount(0)
                self.fileTable.setColumnCount(4)
                self.fileTable.setHorizontalHeaderLabels(
                    ["Download?","iTag","Bit Rate", "Filesize"])
                for stream in self.vids:
                    rowPosition = self.fileTable.rowCount()
                    self.fileTable.insertRow(rowPosition)
                    chkBoxItem = QtWidgets.QTableWidgetItem()
                    chkBoxItem.setFlags(QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled)
                    chkBoxItem.setCheckState(QtCore.Qt.Unchecked)
                    self.fileTable.setItem(rowPosition, 0, chkBoxItem)
                    self.fileTable.setItem(rowPosition, 1, QtWidgets.QTableWidgetItem(stream.itag))
                    self.fileTable.setItem(rowPosition, 2, QtWidgets.QTableWidgetItem(stream.abr))
                    self.fileTable.setItem(rowPosition, 3,
                                           QtWidgets.QTableWidgetItem(size(stream.filesize, system=verbose)))

            except:
                traceback.print_exc()
Example #2
0
def sortPrint(list, fromBytes):
    items = sorted(list, key=operator.itemgetter(1), reverse=True)
    total = 0;
    for item in items:
        total += item[1]
    print 'Total: %s' % filesize.size(total)
    for item in items:
        if item[1] < fromBytes:
            continue
        print '%-5s <%s> ......... %-10s' % (filesize.size(item[1]), item[2], item[0])
    def read(self):
        self.__init()
        cw = self.cw
        if cw:
            cw._torrent_s = None
        title = self.url
        self._dn = self.get_dn(self.url)
        info = getattr(cw, 'info?', None)
        if info is not None:
            self.print_('cached info')
            self._info = info
        if self._info is None:
            try:
                self._info = torrent.get_info(self.url,
                                              cw,
                                              timeout=TIMEOUT,
                                              callback=self.callback)
                if CACHE_INFO:
                    setattr(cw, 'info?', self._info)
            except Exception as e:
                self.update_pause()
                if not cw.paused:
                    raise errors.Invalid('Faild to read metadata: {}'.format(
                        self.url),
                                         fail=True)
        if self._info is None:
            cw.paused = True
        if cw.paused:
            return
        hash_ = self._info.hash.hex()
        self.print_('v2: {}'.format(self._info.v2))
        self.print_('Hash: {}'.format(hash_))
        if not self._info.v2:
            self.url = 'magnet:?xt=urn:btih:{}'.format(hash_)  #
        date = datetime.fromtimestamp(self._info.creation_date())
        date = date.strftime('%y-%m-%d %H:%M:%S')
        self.print_('Created on: {}'.format(date))
        self.print_('Total size: {}'.format(fs.size(self._info.total_size())))
        self.print_('Pieces: {} x {}'.format(
            self._info.num_pieces(), fs.size(self._info.piece_length())))
        self.print_('Creator: {}'.format(self._info.creator()))
        self.print_('Comment: {}'.format(self._info.comment()))
        cw.setTotalFileSize(self._info.total_size())

        cw.imgs.clear()
        cw.dones.clear()

        self.urls = [self.url]
        self.title = self.name
        self.update_files()

        if not self.single and not os.path.isdir(self.dir):  #4698
            downloader.makedir_event(self.dir, cw)

        cw.pbar.show()
    def update_progress(self, h, fast):
        if self._info is None:
            return
        cw = self.cw

        if not cw.imgs:  #???
            self.print_('???')
            self.update_files()

        sizes = torrent.get_file_progress(h, self._info, fast)
        for i, (file, size) in enumerate(zip(cw.names, sizes)):
            if i > 0 and fast:
                break  #
            file = os.path.realpath(file.replace('\\\\?\\', ''))
            if file in cw.dones:
                continue
            if size[0] == size[1]:
                cw.dones.add(file)
                file = constants.compact(file).replace('\\', '/')
                files = file.split('/')
                file = ' / '.join(files[1:])
                msg = 'Completed: {} | {}'.format(file, fs.size(size[1]))
                self.print_(msg)
                if i == 0 and size[0]:
                    self._updateIcon()

        cw.setPieces(torrent.pieces(h, self._info))
    def read(self):
        cw = self.cw
        title = self.url
        if self.url.startswith('magnet:'):
            qs = utils.query_url(self.url)
            if 'dn' in qs:
                self._dn = qs['dn'][0]
        info = getattr(cw, 'info?', None)
        if info is not None:
            self.print_('cached info')
            self._info = info
        if self._info is None:
            try:
                self._info = torrent.get_info(self.url, cw, timeout=TIMEOUT, callback=self.callback)
                if CACHE_INFO:
                    setattr(cw, 'info?', self._info)
            except Exception as e:
                self.update_pause()
                if not cw.paused:
                    raise errors.Invalid('Faild to read metadata: {}'.format(self.url), fail=True)
        if self._info is None:
            cw.paused = True
        if cw.paused:
            return
        hash_ = self._info.hash.hex()
        self.print_('v2: {}'.format(self._info.v2))
        self.print_('Hash: {}'.format(hash_))
        if not self._info.v2:
            self.url = 'magnet:?xt=urn:btih:{}'.format(hash_)#
        date = datetime.fromtimestamp(self._info.creation_date())
        date = date.strftime('%y-%m-%d %H:%M:%S')
        self.print_('Created on: {}'.format(date))
        self.print_('Total size: {}'.format(fs.size(self._info.total_size())))
        self.print_('Pieces: {} x {}'.format(self._info.num_pieces(), fs.size(self._info.piece_length())))
        self.print_('Creator: {}'.format(self._info.creator()))
        self.print_('Comment: {}'.format(self._info.comment()))
        cw.setTotalFileSize(self._info.total_size())
        
        cw.imgs.clear()
        cw.dones.clear()

        self.urls = [self.url]
        self.title = self.name
        self.update_files()
        
        cw.pbar.show()
Example #6
0
 def __init__(self, filename, eligible, normalized):
     self.raw_contents = open(filename, 'r').read()
     self.raw_contents_list = open(filename, 'r').readlines()
     self.raw_contents_list = [
         r.replace('\r', '') for r in self.raw_contents_list
     ]
     self.filename = os.path.basename(filename)
     self.file_id = id(self)
     self.file_size = filesize.size(os.path.getsize(filename))
     self.date_added = datetime.now().strftime('%Y-%m-%d %H:%M')
     self.eligible = eligible
     self.activated = eligible
     self.normalized = normalized
    def listing(self):
        curr_dir = os.getcwd()
        os.chdir(self.config.downloadsDir)
        dir_dict, dir_key = self.manifest.get_dirname_dict()
        keys = dir_dict.keys()
        for ident in keys:
            dir_name = dir_dict[ident][dir_key]
            # get list of files in the directory
            list_files = get_files_in_dir(dir_name)
            print("({0}) {1}".format(ident, dir_name))
            for value in list_files:
                if value[0] != ".":
                    size_in_bytes = os.path.getsize(
                        os.path.join(dir_name, value))
                    print(u"\t \u2514\u2501 {0}\t{1}".format(
                        value, size(size_in_bytes, alternative)))
            print("")

        os.chdir(curr_dir)
        return dir_dict, dir_key
Example #8
0
 def human_size(self):
     """
     Retorna o tamanho humanizado do arquivo
     """
     return size(self.size)
	def generate_html_file(self, result_list):
		html = """
		<html>
		    <head>
		        <title>Search results for "{0}"</title>
		        <style>

		        h1 {{
		        	font-family: Georgia, serif;
		        }}

		        table.table2{{
		            font-family: Georgia, serif;
		            font-size: 18px;
		            font-style: normal;
		            font-weight: normal;
		            line-height: 1.2em;
		            border-collapse:collapse;
		            text-align:center;
		            width: 100%;
		        }}

		        .table2 thead th, .table2 tfoot td{{
		            padding:20px 10px 40px 10px;
		            color:#fff;
		            font-size: 26px;
		            background-color:#222;
		            font-weight:normal;
		            border-right:1px dotted #666;
		            border-top:3px solid #666;
		            -moz-box-shadow:0px -1px 4px #000;
		            -webkit-box-shadow:0px -1px 4px #000;
		            box-shadow:0px -1px 4px #000;
		            text-shadow:0px 0px 1px #fff;
		            text-shadow:1px 1px 1px #000;
		        }}

		        .table2 tfoot th{{
		            padding:10px;
		            font-size:18px;
		            text-transform:uppercase;
		            color:#888;
		        }}

		        .table2 tfoot td{{
		            font-size:36px;
		            color:#EF870E;
		            border-top:none;
		            border-bottom:3px solid #666;
		            -moz-box-shadow:0px 1px 4px #000;
		            -webkit-box-shadow:0px 1px 4px #000;
		            box-shadow:0px 1px 4px #000;
		        }}

		        .table2 thead th:empty{{
		            background:transparent;
		            -moz-box-shadow:none;
		            -webkit-box-shadow:none;
		            box-shadow:none;
		        }}

		        .table2 thead :nth-last-child(1){{
		            border-right:none;
		        }}

		        .table2 thead :first-child,
		        .table2 tbody :nth-last-child(1){{
		            border:none;
		        }}

		        .table2 tbody th{{
		            text-align:left;
		            padding:10px;
		            color:#333;
		            text-shadow:1px 1px 1px #ccc;
		            background-color:#f9f9f9;
		        }}

		        .table2 tbody td{{
		            padding:10px;
		            background-color:#f0f0f0;
		            border-right:1px dotted #999;
		            text-shadow:-1px 1px 1px #fff;
		            color:#333;
		        }}

		        </style>
		    </head>
		    
		    <body>
		        <h1>Search results for "{0}"</h1>
		        <table class="table2">
		            <tr>
		                <th>Name</th>
		                <th>Size</th>
		                <th>SE</th>
		                <th>LE</th>
		            </tr>
		""".format(self.term)

		for result in result_list:
			html += """
		        <tr>
		            <td>
		            	<a href="magnet:?xt=urn:btih:{1}&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80&tr=udp%3A%2F%2Ftracker.istole.it%3A6969&tr=udp%3A%2F%2Ftracker.ccc.de%3A80">
		            		{0}
		            	</a>
		            </td>
		            <td>{2}</td>
		            <td>{3}</td>
		            <td>{4}</td>
		        </tr>
		    """.format(result.name, result.magnet, filesize.size(result.size), str(result.se), str(result.le))

		html += """
		        </table>
			</body>
		</html>
		"""

		# Create temp HTML file
		f = tempfile.NamedTemporaryFile(delete=False, suffix='.html')
		f.write(html)
		name = f.name
		f.close()

		return name
Example #10
0
        #print "Fetching: %s.%s" % (str(ix+1),file_name)

        u = urllib.request.urlopen(filedownload)

        decodename = urllib.parse.unquote(file_name)
        #print decodename

        if os.path.exists(decodename):
            print('  File %s exists... skipping' % decodename)
            continue
        f = open(decodename, 'wb')
        meta = u.info()
        file_size = int(meta.get("Content-Length"))
        #print ix+1, 'of',Totalrecords, " - Downloading: %s Bytes: %s" % (decodename, file_size)
        print('  Downloading ' + str(ix + 1) + ' of ' + str(Totalrecords) +
              " - %s Bytes: %s" % (decodename, size(file_size)))
        file_size_dl = 0
        block_sz = 8192
        current_interval_size = 0
        while True:
            buffer = u.read(block_sz)
            current_interval_size += 1
            if not buffer:
                break

            file_size_dl += len(buffer)
            f.write(buffer)

            if current_interval_size == 128 * 10:
                print('   -> Downloaded %s of %s' %
                      (size(file_size_dl), size(file_size)))
    def _callback(self, h, s, alerts):
        self._h = h
        cw = self.cw
            
        if self._state != s.state_str:
            self._state = s.state_str
            self.print_('state: {}'.format(s.state_str))

##        for alert in alerts:
##            self.print_('⚠️ {}'.format(alert))

        title = (self._dn or self.url) if self._info is None else self.name

        if cw.alive and cw.valid and not cw.pause_lock:
            if self._info is not None:
                if not cw.imgs: #???
                    self.print_('???')
                    self.update_files()
            
                sizes = torrent.get_file_progress(h, self._info)
                for i, (file, size) in enumerate(zip(cw.names, sizes)):
                    file = os.path.realpath(file.replace('\\\\?\\', ''))
                    if file in cw.dones:
                        continue
                    if size[0] == size[1]:
                        cw.dones.add(file)
                        file = constants.compact(file).replace('\\', '/')
                        files = file.split('/')
                        file = ' / '.join(files[1:])
                        msg = 'Completed: {}'.format(file)
                        self.print_(msg)
                        if i == 0:
                            self._updateIcon()

                cw.setPieces(torrent.pieces(h, self._info))

            filesize = s.total_done
            upload = s.total_upload
            if s.state_str in ('downloading', ):
                # init filesize
                if not self._filesize_init:
                    self._filesize_prev = filesize
                    self._filesize_init = True
                    self.print_('init filesize: {}'.format(fs.size(filesize)))
                    
                # download
                d_size = filesize - self._filesize_prev
                self._filesize_prev = filesize
                self.size += d_size
                downloader.total_download_size_torrent += d_size
                # upload
                d_size = upload - self._upload_prev
                self._upload_prev = upload
                self.size_upload += d_size
                downloader.total_upload_size_torrent += d_size
            if self._info is not None:
                cw.pbar.setValue(s.progress * self._info.total_size())
            if s.state_str == 'queued':
                title_ = 'Waiting... {}'.format(title)
            elif s.state_str == 'checking files':
                title_ = 'Checking files... {}'.format(title)
                self._filesize_prev = filesize
            elif s.state_str == 'downloading':
                title_ = '{}    (s: {}, p: {}, a:{:.3f})'.format(title, s.num_seeds, s.num_peers, s.distributed_copies)
                cw.setFileSize(filesize)
                cw.setSpeed(self.size.speed)
                cw.setUploadSpeed(self.size_upload.speed)
            elif s.state_str == 'seeding':
                title_ = '{}'.format(title)
                cw.setFileSize(filesize)
            elif s.state_str == 'reading':
                title_ = 'Reading... {}'.format(title)
            else:
                title_ = '{}... {}'.format(s.state_str.capitalize(), title)
            cw.setTitle(title_, update_filter=False)
        else:
            return 'abort'
    def _callback(self, h, s, alerts):
        self._h = h
        cw = self.cw

        if self._state != s.state_str:
            self._state = s.state_str
            self.print_('state: {}'.format(s.state_str))

##        for alert in alerts:
##            self.print_('⚠️ {}'.format(alert))

        title = (self._dn or self.url) if self._info is None else self.name

        if cw.alive and cw.valid and not cw.pause_lock:
            cw._torrent_s = s
            fast = len(cw.imgs) > TOO_MANY
            self.update_progress(h, fast)

            filesize = s.total_done
            upload = s.total_upload
            if s.state_str in ('downloading', ):
                # init filesize
                if not self._filesize_init:
                    self._filesize_prev = filesize
                    self._filesize_init = True
                    self.print_('init filesize: {}'.format(fs.size(filesize)))

                # download
                d_size = filesize - self._filesize_prev
                self._filesize_prev = filesize
                self.size += d_size
                downloader.total_download_size_torrent += d_size
                # upload
                d_size = upload - self._upload_prev
                self._upload_prev = upload
                self.size_upload += d_size
                downloader.total_upload_size_torrent += d_size
            if self._info is not None:
                cw.pbar.setValue(s.progress * self._info.total_size())
            if s.state_str == 'queued':
                title_ = 'Waiting... {}'.format(title)
            elif s.state_str == 'checking files':
                title_ = 'Checking files... {}'.format(title)
                self._filesize_prev = filesize
            elif s.state_str == 'downloading':
                title_ = '{}'.format(title)
                cw.setFileSize(filesize)
                cw.setSpeed(self.size.speed)
                cw.setUploadSpeed(self.size_upload.speed)
            elif s.state_str == 'seeding':
                title_ = '{}'.format(title)
                cw.setFileSize(filesize)
            elif s.state_str == 'reading':
                title_ = 'Reading... {}'.format(title)
            else:
                title_ = '{}... {}'.format(s.state_str.capitalize(), title)
            cw.setTitle(title_, update_filter=False)
        else:
            self.print_('abort')
            if cw:
                cw._torrent_s = None
            return 'abort'
Example #13
0
 def getFileSize(self):
     return size(os.path.getsize(settings.MEDIA_ROOT + self.file.name))