Last active
August 7, 2018 21:51
-
-
Save zahhar/88eb6a8e496113659060e315fb45ad5d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import json | |
import shutil | |
import unicodedata | |
import re | |
import os | |
from six.moves import urllib | |
target = "Downloads" | |
if len(sys.argv) != 2: | |
print("USAGE: sh-downloader.py file.json") | |
sys.exit() | |
try: | |
print("Reading %s file..." % sys.argv[1]) | |
with open(sys.argv[1], 'r') as fp: | |
slideshows = json.load(fp) | |
n = len(slideshows['slideshows_uploaded']) | |
print("Success! %i entries found." % n) | |
if not os.path.exists(target): | |
os.makedirs(target) | |
print("Downloading into new folder '%s'" % target) | |
else: | |
print("Downloading into existing folder '%s'" % target) | |
for i, s in enumerate(slideshows['slideshows_uploaded']): | |
try: | |
print("Downloading entry %i of %i" % (i+1, n)) | |
match = re.search(r'.+\.([\w]+)\??', s['download_url']) | |
if match: | |
extension = match.group(1) | |
fname = unicodedata.normalize('NFKD', s['title']) | |
fname = fname+" - "+s['category']+"."+extension | |
infile = urllib.request.urlopen(s['download_url']) | |
outfile = open(target+'/'+fname, 'wb') | |
shutil.copyfileobj(infile, outfile) | |
print("%s => %s" % (s['category'], fname)) | |
else: | |
print("WARNING: Can't get extension for %s, skipping" % s['download_url']) | |
continue | |
except urllib.error.HTTPError as e: | |
print("WARNING: %s %s while reading %s, skipping" % (e.code, e.reason, s['download_url'])) | |
pass | |
except IndexError: | |
print("WARNING: Can't get extension for %s, skipping" % s['download_url']) | |
pass | |
except ValueError: | |
print("ERROR: Incorrect file format, JSON expected") | |
fp.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"slideshows_uploaded": [ | |
{ | |
"title": "Где кончается проектирование и начинается дизайн?", | |
"description": "Как можно сделать максимально правдобный пототип и при этом не заиграться в дизайн? Как обсуждать прототип с клиентом, чтобы не уйти от прототипирования в рисование? Что использовать?\r\n\r\nПрезентация была подготовлена для выступления на 2013.profsoux.ru, где мы вещали вместе с Ольгой Павловой.", | |
"tag": "", | |
"category": "presentation", | |
"language": "ru", | |
"privacy": "public", | |
"url": "https://www.slideshare.net/sobakapavlova/profsoux-zaur-giyasov-21799564", | |
"download_url": "https://s3.amazonaws.com/ppt-download/profsouxzaurgiyasov-130523204138-phpapp01.pptx?response-content-disposition=attachment&Signature=Y0lJevnQ%2FVQZg99QqgLBXd2bA9s%3D&Expires=1533631190&AWSAccessKeyId=AKIAIA5TS2BVP74IAVEQ" | |
}, | |
{ | |
"title": "Структура задач и решений при создании и эксплуатации интернет-магазина", | |
"description": "23 мая 2013, семинар «Создание и продвижение интернет-магазина» (http://www.umi-cms.ru/company/calendar/seminar_23may_spb/), СПб. Докладчик от «Собаки Павловой» — Наталья Прокофьева.", | |
"tag": "", | |
"category": "presentation", | |
"language": "ru", | |
"privacy": "public", | |
"url": "https://www.slideshare.net/sobakapavlova/ss-21834329", | |
"download_url": "https://s3.amazonaws.com/ppt-download/random-130524083256-phpapp01.pptx?response-content-disposition=attachment&Signature=NRADn5zvfhfdLeNvfJidDDa46gk%3D&Expires=1533631190&AWSAccessKeyId=AKIAIA5TS2BVP74IAVEQ" | |
}, | |
{ | |
"title": "Как начать? Боремся со страхом чистого листа в проектировании интерфейсов", | |
"description": "25 мая 2013, HackDay # 27 (http://hackday.ru/events/hackday-27), СПб. Докладчик — Ольга Павлова.", | |
"tag": "ux, ui, проектирование, prototyping, design, start, howto", | |
"category": "presentation", | |
"language": "ru", | |
"privacy": "public", | |
"url": "https://www.slideshare.net/sobakapavlova/ss-21895677", | |
"download_url": "https://s3.amazonaws.com/ppt-download/safestart-130525085423-phpapp02.ppt?response-content-disposition=attachment&Signature=XrZvFB94IRqxjjfUDFxBPmxQLv4%3D&Expires=1533631190&AWSAccessKeyId=AKIAIA5TS2BVP74IAVEQ" | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Purpose
This Python script uses SlideShare JSON export file to download everything (slideshows, videos, documents, etc.) that you have uploaded to SlideShare. Script should work with MacOS system Python (version 2.7) as well as with latest 3.x versions.
How-to
python sh-downloader.py sh-sample.json
Enjoy!
Troubleshooting
If you are using Python3, you most probably have to install six module first:
pip3 install six
or
pip install six
And if you do not have pip installed for some reason, then
sudo python -m ensurepip