Skip to content

Instantly share code, notes, and snippets.

@zahhar zahhar/sh-downloader.py
Last active Aug 7, 2018

Embed
What would you like to do?
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()
{
"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"
}
]
}
@zahhar

This comment has been minimized.

Copy link
Owner Author

commented Jul 31, 2018

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

  1. Log into your SlideShare account
  2. Navigate to Account settings -> Export
  3. Click "Export JSON" to download file that includes a list of users that you are following, various account information and contact details, and a list of all slideshows that you have uploaded. Note, that provided download links expire after 7 days. Sample of my export file is displayed above as "sh-sample.json".
  4. Save sh-downloader.py to your computer.
  5. Execute in Terminal:

python sh-downloader.py sh-sample.json

  1. Script will create Download folder, and starts populating it with files downloaded from your Slideshare. Note, that script shows progress only after each file is downloaded. It means you do will face delays when "nothing happens" on the screen if internet connection is slow, or files to transfer are very large.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.