Friday, October 13, 2017

i haven't posted in a while, here's a nifty script

there are lots of queries everywhere about how to script PRAW and youtube-dl to download videos off Reddit subs (i use this to load my Plex server with relevant music videos). here it is (it'll take a CLI of the sub you want to scrape and get the "Hot" 10 links:


#!python2.7
import praw
import youtube_dl
import sys      
#import urllib
 
r = praw.Reddit(client_id='insert your info here',
                     client_secret='insert your info here',
                     password='insert your info here',
                     user_agent='insert your info here',
                     username='insert your info here')
        
        
urls = []
 
def yt() :
        for submission in r.subreddit(sys.argv[1]).hot(limit=10):
                urls.append(str(submission.url))
        return urls
 
yt_urls = yt()
ydl_opts = {'ignoreerrors': 'False'}
ydl = youtube_dl.YoutubeDL(ydl_opts)
 
for item in yt_urls:
        #print([item, ])
        ydl.download([item, ])


No comments:

Post a Comment