Documentos de Académico
Documentos de Profesional
Documentos de Cultura
#################0000666#0000000#0000000#00000000064#13407400542#0014511#g#########
###################################################################################
########ustar#00root############################root############################000
0000#0000000#######################################################################
###################################################################################
##############52 comment=9ab728f7cabd2d2a3708d758d4f7c209b7722a29
###################################################################################
###################################################################################
###################################################################################
###################################################################################
###################################################################################
#############################################scribd-downloader-
1.1.1/############################################################################0
000775#0000000#0000000#00000000000#13407400542#0015113#5###########################
#########################################################################ustar#00ro
ot############################root############################0000000#0000000######
###################################################################################
###############################################################################scri
bd-downloader-
1.1.1/.gitignore##################################################################0
000664#0000000#0000000#00000000170#13407400542#0017101#0###########################
#########################################################################ustar#00ro
ot############################root############################0000000#0000000######
###################################################################################
###############################################################################/*.t
xt
/*.pdf
/*.jpg
/*.jpeg
/*.png
*.pyc
__pycache__/
.cache/
scribd_downloader.egg-info/
build/
dist/
.pytest_cache/
###################################################################################
###################################################################################
###################################################################################
###################################################################################
############################################################scribd-downloader-
1.1.1/.travis.yml#################################################################0
000664#0000000#0000000#00000000225#13407400542#0017223#0###########################
#########################################################################ustar#00ro
ot############################root############################0000000#0000000######
###################################################################################
###############################################################################dist
: xenial
language: python
sudo: required
python:
- "3.4"
- "3.5"
- "3.6"
- "3.7"
install: pip install -e .
script: python -m pytest test
###################################################################################
###################################################################################
###################################################################################
###################################################################################
###############################scribd-downloader-
1.1.1/LICENSE#####################################################################0
000664#0000000#0000000#00000002060#13407400542#0016116#0###########################
#########################################################################ustar#00ro
ot############################root############################0000000#0000000######
###################################################################################
###############################################################################MIT
License
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
###################################################################################
###################################################################################
###################################################################################
###################################################################################
###################################################################################
#################################################scribd-downloader-
1.1.1/README.rst##################################################################0
000664#0000000#0000000#00000006137#13407400542#0016611#0###########################
#########################################################################ustar#00ro
ot############################root############################0000000#0000000######
###################################################################################
###############################################################################Scri
bd-Downloader
=================
This python script allows downloading of Scribd documents. It does not matter if
the pages
are blurred or require authentication, this script will still do its job.
- Actual documents where the text can be selected are hard to tackle.
If we feed such a document to this tool, only the text present in
document will be downloaded. Scribd seems to use javascript to somehow
combine text and images. So far, I haven't been able to combine them
with Python in a way they look like the original document.
Installation
------------
Make sure you're using Python 3 (Python 2 is not supported by a few dependencies).
Then run these commands:
::
::
Usage
-----
::
positional arguments:
URL scribd url to download
optional arguments:
-h, --help show this help message and exit
-i, --images download url made up of images
-p, --pdf convert to pdf (*Nix: imagemagick)
Examples
--------
It can now also download complete books by mimicking itself as a premium user!
This will generate an ``.md`` file in the current working directory:
::
$ scribdl https://www.scribd.com/read/189087235/Confessions-of-a-Casting-
Director-Help-Actors-Land-Any-Role-with-Secrets-from-Inside-the-Audition-Room
Disclaimer
----------
Downloading books from Scribd for free maybe prohibited. This tool is
meant for educational purposes only. Please support the authors by buying
their titles.
License
-------
@six.add_metaclass(ABCMeta)
class ScribdBase:
"""
An Abstract Base Class for Scribd books and documents.
"""
@abstractmethod
def get_content(self):
"""
An abstract method for fetching content off Scribd book or document.
"""
pass
###################################################################################
###################################################################################
##########scribd-downloader-
1.1.1/scribdl/book.py#############################################################0
000664#0000000#0000000#00000013106#13407400542#0020042#0###########################
#########################################################################ustar#00ro
ot############################root############################0000000#0000000######
###################################################################################
###############################################################################impo
rt requests
import json
import os
import shutil
class ScribdBook(ScribdBase):
"""
A class for downloading books off Scribd.
Parameters
----------
url : `str`
A string containing Scribd book URL.
"""
def get_content(self):
"""
Processing text and image extraction.
"""
token = self._get_token()
while True:
response = self.fetch_response(chapter, token)
if response.status_code == 403:
token = self._get_token()
response = self.fetch_response(chapter, token)
if response.status_code == 403:
print("No more content being exposed by Scribd!")
break
try:
json_response = json.loads(response.text)
except ValueError:
print("Completed downloading book!")
break
chapter += 1
return filename
def get_id(self):
"""
Extracts the book ID.
"""
splits = self.url.split("/")
for split in splits:
try:
book_id = int(split)
except ValueError:
continue
return book_id
def _get_token(self):
"""
Fetches a uniquely generated token for the current
session.
"""
headers = {
"X-CSRF-Token":
"jfHAQ/LjqJAexQtAkCgWi0hif/sWHi5pXVAHCNsC3GkZocGcHcfETUhZ/Wd+YyY0tEH/zV/hRCOZhyq7Ze
wiMQ=="
}
cookies = {
"_scribd_session":
"eyJzZXNzaW9uX2lkIjoiNTg3N2VjOTAwMGNmOTM5M2IwMGEwY2ExZmI2YTRiOTQiLCJfY3NyZl90b2tlbi
I6ImxGQUIzKzhrYk4xV25QWW43a3N3di93amdEWkovMnBLeE5jdHM3N3UvbGc9IiwiciI6IjE1NDM2Mjk1O
DAiLCJ3b3JkX2lkIjoyNjMzNjM2MzIsInAiOjE1NDI5MzQ4NDMsImxhc3RfcmVhdXRoIjoxNTQzNjI5NTgw
fQ%3D%3D--4f34750fb7295b3b6f26754547c2e1e568da3e86",
"_scribd_expire": "1543629580",
}
data = "data"
token_url = "https://www.scribd.com/read2/
{}/access_token".format(self.book_id)
token = requests.post(token_url, headers=headers, cookies=cookies,
data=data)
return json.loads(token.text)["response"]
def get_arguments():
"""
Parses arguments off the command-line.
"""
parser = argparse.ArgumentParser(
description="Download documents and books from scribd.com"
)
return parser.parse_args()
def _command_line():
"""
This function that gets executed when called via command-line.
"""
args = get_arguments()
url = args.url
pdf = args.pdf
images = args.images
scribd_link = Downloader(url)
downloaded_content = scribd_link.download(is_image_document=images)
if pdf:
print("\nConverting to {}..".format(downloaded_content.pdf_path))
downloaded_content.to_pdf()
if __name__ == "__main__":
_command_line()
###################################################################################
###################################################################################
###################################################################################
###################################################################################
######################################scribd-downloader-
1.1.1/scribdl/document.py#########################################################0
000664#0000000#0000000#00000014102#13407400542#0020723#0###########################
#########################################################################ustar#00ro
ot############################root############################0000000#0000000######
###################################################################################
###############################################################################from
bs4 import BeautifulSoup
import requests
import shutil
import os
from abc import abstractmethod
from .base import ScribdBase
from . import internals
class ScribdDocument(ScribdBase):
"""
A base class for downloading documents off Scribd.
Parameters
----------
url : `str`
A string containing Scribd document URL.
"""
def get_title(self):
"""
Scrapes the title of the Scribd document.
"""
title = self.soup.find("title").get_text()
return internals.sanitize_title(title)
def _extract_all_jsonp_urls(self):
"""
Extracts all URLs ending with '.jsonp' by parsing the
HTML code.
"""
js_text = self.soup.find_all("script", type="text/javascript")
jsonp_urls = []
for opening in js_text:
for inner_opening in opening:
jsonp = self._extract_jsonp_url(inner_opening)
if jsonp:
jsonp_urls.append(jsonp)
return jsonp_urls
if portion1 == -1:
jsonp = None
else:
portion2 = inner_opening.find(".jsonp")
jsonp = inner_opening[portion1 : portion2 + 6]
return jsonp
@abstractmethod
def get_content(self):
"""
An abstract method which will fetch the actual content
found in the '.jsonp' URLs.
"""
pass
class ScribdTextualDocument(ScribdDocument):
"""
A class for downloading textual documents off Scribd.
"""
def get_content(self):
"""
Generates the filename and processes the text extraction
to this file.
"""
title = self.get_title()
jsonp_urls = self._extract_all_jsonp_urls()
def get_title(self):
"""
Scrapes the title of the Scribd document.
"""
title = self.soup.find("title").get_text()
return internals.sanitize_title(title)
response_head = (
(response)
.replace("window.page" + page_no + '_callback(["', "")
.replace("\\n", "")
.replace("\\", "")
.replace('"]);', "")
)
soup_content = BeautifulSoup(response_head, "html.parser")
class ScribdImageDocument(ScribdDocument):
"""
A class for downloading image documents off Scribd.
"""
def get_content(self):
"""
Processes the image extraction.
"""
title = self.get_title()
jsonp_urls = self._extract_all_jsonp_urls()
def get_title(self):
"""
Scrapes the title of the Scribd document.
"""
title = self.soup.find("title").get_text()
return internals.sanitize_title(title)
return replacement
class Downloader:
"""
A helper class for downloading books and documents off Scribd.
Parameters
----------
url : `str`
A string containing path to a Scribd URL
"""
return content
def _download_book(self):
"""
Downloads books off Scribd.
Returns an object of `ConvertToPDF` class.
"""
book = ScribdBook(self.url)
md_path = book.get_content()
pdf_path = "{}.pdf".format(book.get_id())
return ConvertToPDF(md_path, pdf_path)
content_path = document.get_content()
pdf_path = "{}.pdf".format(document.get_title())
return ConvertToPDF(content_path, pdf_path)
def is_book(self):
"""
Checks whether the passed URL points to a Scribd book
or a Scribd document
"""
response = requests.get(self.url)
soup = BeautifulSoup(response.text, "html.parser")
content_class = soup.find("body")["class"]
matches_with_book = content_class[0] ==
"autogen_class_views_layouts_book_web"
return matches_with_book
###################################################################################
###################################################################################
#####################################scribd-downloader-
1.1.1/scribdl/internals.py########################################################0
000664#0000000#0000000#00000001105#13407400542#0021103#0###########################
#########################################################################ustar#00ro
ot############################root############################0000000#0000000######
###################################################################################
###############################################################################impo
rt sys
def fix_encoding(query):
"""
Encoding fixes for Python 2 and Python 3 cross-compatibilty.
"""
if sys.version_info > (3, 0):
return query
else:
return query.encode("utf-8")
def sanitize_title(title):
"""
Remove forbidden characters from title that will prevent Windows
from creating directory.
for ch in forbidden_chars:
title = title.replace(ch, replace_char)
return title
###################################################################################
###################################################################################
###################################################################################
###################################################################################
###################################################################################
############################scribd-downloader-
1.1.1/scribdl/pdf_converter.py####################################################0
000664#0000000#0000000#00000002434#13407400542#0021752#0###########################
#########################################################################ustar#00ro
ot############################root############################0000000#0000000######
###################################################################################
###############################################################################from
md2pdf.core import md2pdf
import img2pdf
import os
class ConvertToPDF:
"""
A class for converting downloading books and documents to PDF.
Parameters
----------
input_content : `str`, `list`
A string containing path to a single markdown file
or a list containing paths to many images.
output_content : `str`
Output path of the generated PDF.
"""
def to_pdf(self):
"""
Converts to PDF depending upon the type of content,
i.e. images or markdown.
"""
if isinstance(self.input_content, list):
self._images_to_pdf()
else:
self._markdown_to_pdf()
def _markdown_to_pdf(self):
"""
Converts markdown to PDF.
"""
md2pdf(self.pdf_path,
md_file_path=self.input_content,
base_url=os.getcwd())
def _images_to_pdf(self):
"""
Converts images to PDF.
"""
with open(self.pdf_path, "wb") as f:
open_images = [open(img, "rb") for img in self.input_content]
pdf_images = img2pdf.convert(open_images)
f.write(pdf_images)
###################################################################################
###################################################################################
##############################################################scribd-downloader-
1.1.1/scribdl/version.py##########################################################0
000664#0000000#0000000#00000000026#13407400542#0020572#0###########################
#########################################################################ustar#00ro
ot############################root############################0000000#0000000######
###################################################################################
###############################################################################__ve
rsion__ = "1.1.1"
###################################################################################
###################################################################################
###################################################################################
###################################################################################
###################################################################################
###########################################################################scribd-
downloader-
1.1.1/setup.py####################################################################0
000664#0000000#0000000#00000002151#13407400542#0016624#0###########################
#########################################################################ustar#00ro
ot############################root############################0000000#0000000######
###################################################################################
################################################################################!/u
sr/bin/env python
setup(name='scribd-downloader',
version=__version__,
description='Download documents/text from scribd.com',
long_description=long_description,
author='Ritiek Malhotra',
author_email='ritiekmalhotra123@gmail.com',
packages = find_packages(),
entry_points={
'console_scripts': [
'scribdl = scribdl.command_line:_command_line',
]
},
url='https://www.github.com/ritiek/scribd-downloader',
keywords=['scribd-downloader', 'documents', 'command-line', 'python'],
license='MIT',
download_url='https://github.com/ritiek/scribd-downloader/archive/v' +
__version__ + '.tar.gz',
classifiers=[],
install_requires=[
'requests',
'BeautifulSoup4',
'img2pdf',
'md2pdf'
]
)
###################################################################################
###################################################################################
###################################################################################
###################################################################################
###########################################################################scribd-
downloader-
1.1.1/test/#######################################################################0
000775#0000000#0000000#00000000000#13407400542#0016072#5###########################
#########################################################################ustar#00ro
ot############################root############################0000000#0000000######
###################################################################################
###############################################################################scri
bd-downloader-
1.1.1/test/test_base.py###########################################################0
000664#0000000#0000000#00000000337#13407400542#0020420#0###########################
#########################################################################ustar#00ro
ot############################root############################0000000#0000000######
###################################################################################
###############################################################################from
scribdl.base import ScribdBase
import pytest
class TestOverrideScribdBase(ScribdBase):
def get_content(self):
pass
def test_abstract_class():
with pytest.raises(TypeError):
x = ScribdBase()
###################################################################################
###################################################################################
###################################################################################
########################################scribd-downloader-
1.1.1/test/test_download.py#######################################################0
000664#0000000#0000000#00000002651#13407400542#0021316#0###########################
#########################################################################ustar#00ro
ot############################root############################0000000#0000000######
###################################################################################
###############################################################################from
scribdl.downloader import Downloader
import os
import pytest
@pytest.fixture
def cwd_to_tmpdir(tmpdir):
os.chdir(str(tmpdir))
def test_text_document_download(cwd_to_tmpdir):
text_doc_url = "https://www.scribd.com/document/96882378/Trademark-License-
Agreement"
text_downloader = Downloader(text_doc_url)
md_doc = text_downloader.download(is_image_document=False)
assert os.path.getsize(md_doc.input_content) in range(1000, 2000)
md_doc.to_pdf()
assert os.path.getsize(md_doc.pdf_path) in range(20000, 31000)
def test_img_document_download(cwd_to_tmpdir):
img_doc_url = "https://www.scribd.com/doc/136711944/Signature-Scanning-and-
Verification-in-Finacle"
img_downloader = Downloader(img_doc_url)
imgs = img_downloader.download(is_image_document=True)
assert len(imgs.input_content) == 2
imgs.to_pdf()
assert os.path.getsize(imgs.pdf_path) in range(140000, 150000)
###################################################################################
####scribd-downloader-
1.1.1/test/test_internals.py######################################################0
000664#0000000#0000000#00000000764#13407400542#0021511#0###########################
#########################################################################ustar#00ro
ot############################root############################0000000#0000000######
###################################################################################
###############################################################################from
scribdl.internals import sanitize_title
from scribdl import internals
import pytest
SANITIZE_TITLE_TEST_TABLE = [
("good_title", "good_title"),
("*bla", "_bla"),
("**free_as_in_<freedom>**", "__free_as_in__freedom___"),
("troller*\"/\<>:|(haha)jojo", "troller_________haha_jojo"),
]