Package: reddit-media
Reddit Media File DownloaderGets media file URLs from Reddit submissions usingAsync PRAWlibrary and downloads it. Supports video and single or gallery images. Can be used both as standalone package and library for Python scripts.How to installTo use this package, you first have toinstall Python 3.7 or higher(versions below are not supported). Then open your terminal and type following command to install the latest version of the package from PyPI repository:pip install reddit-mediaReddit API requires authentication for scripts that use it, so you will have to do some configuration beforehand. Specifically, it requires app Client ID and Client Secret. You can create both very easily following next steps:Open this page:https://reddit.com/prefs/appsIf you are not logged in into your Reddit account, you will be prompted to do soYou will see 'authorized applications' pageScroll to the very bottom and press 'create another app...' buttonSelect application type 'script'Enter any name and redirect URL you want (you will be able to change it later)Press 'create app' button. You will see your new app createdCopy Client ID just under 'personal use script' text and name of the appCopy Client Secret next to 'secret' fieldNote: For details about authenticating, check out this page:Authenticating via OAuthUsing as a libraryIf your Python script needs to get URLs of some Reddit submission, but you don't want to do it yourself, you can use this package to do it for you. Once you installed the package, you can just import it and use as any other library:importasynciofromredditmediaimportget_reddit,get_media,MediaTypeasyncdefmain():asyncwithget_reddit(client_id='your-client-id',client_secret='your-client-secret')asreddit:subreddit=awaitreddit.subreddit('cute')asyncforsubmissioninsubreddit.hot(limit=10):# First 10 submissions on r/cuteformediainget_media(submission).media:ifmedia.typein[MediaType.jpg,MediaType.png]:# Print URL only if it's an imageprint(media.uri)asyncio.run(main())Using as standalone programIf you want to download bunch of media files from some reddit submissions of subreddit, you can do this by using this package as standalone CLI program. You can do that by entering this into your terminal:python -m redditmedia -c [CLIENT ID] [CLIENT SECRET] get [SUBMISSION IDS]This will download all media files from specified submissions intoreddit-media-downloadsfolder in current working directory. If you wish to change path of the folder where media should be downloaded to, you can specify it by adding-p [PATH TO FOLDER]option beforegetcommand above, or if you wish to have media files in separate folders depending on the submission they are from, you can do that by adding-sflag beforegetcommand.For more info, enter:python -m redditmedia --helpStoring credentials in a fileAs you can see, both use cases require you to explicitly provide credentials, which can be security issue and generally inconvenient. Instead you can createpraw.inifile inside your current working directory and paste this:[redditmedia]client_id=<Paste Client ID here>client_secret=<Paste Client Secret here>Now you can omit keyword arguments when callingget_redditand credentials will be automatically picked up from the file:fromredditmediaimportget_redditreddit=get_reddit()And when using CLI tool, omit-coption:python -m redditmedia get [IDS OF SUBMISSIONS SEPARATED WITH SPACE]Note: You can do more things using this file, which is outside of the topic of this page. For details aboutpraw.inifile, check out documentation:praw.ini Files