Reputation: 1796
I am trying to use youtube-dl embedded in a script. I would like it to only download videos from a playlist after a certain date. But, none of the options I have tried work. I have tried dateafter and daterange.
Here is what I currently have:
from __future__ import unicode_literals
import youtube_dl
from youtube_dl.utils import DateRange
import os
def prog_hook(d):
if d['status'] == 'finished':
path='/home/pi/.temp/Commute/'
for filename in os.listdir(path):
if os.path.isdir(os.path.join(path,filename)):
mvcmd = 'rsync -a --remove-source-files /home/pi/.temp/Commute/{}/ /home/pi/Commute/{}/'.format(filename, filename)
os.system(mvcmd)
delcmd = 'rm -r {}'.format(filename)
os.system(delcmd)
daterange = DateRange('20180601')
ydl_opts = {
'format' :'bestaudio/best',
'format' : 'mp4',
'outtmpl' : '/home/pi/.temp/Commute/%(playlist)s/00%(playlist_index)s-%(title)s.%(ext)s',
'download_archive' : '/home/pi/.temp/Commute/downloadedShows.txt',
'ignoreerrors' : 'True',
'restrictfilenames' : 'True',
'daterange' : daterange,
'progress_hooks' : [prog_hook],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
try:
link = ["https://www.youtube.com/playlist?list=PLBZb_61EqeJlvaIUzRne-vxEFhNDLvmga"]
ydl.download(link)
except:
pass
Upvotes: 0
Views: 2092
Reputation: 11
Probably I'm late, but here's what worked for me for anyone who's still looking:
YDL_OPTIONS = {'daterange':DateRange('20000101', '20180101')}
This gets me the videos between 1st January 2000 and 1st January 2018.
Upvotes: 1
Reputation: 1796
The reason the script was not reporting that videos were outside of the date range was because they were in the download archive. On videos that had not yet been downloaded everything worked as it should.
Upvotes: 0