startDate=datenum('1854-10-09','yyyy-mm-dd');
endDate=datenum('1924-04-20','yyyy-mm-dd');
newspaperNumber=83045462;
titleString=(strcat(num2str(newspaperNumber),'_',datestr(startDate),'_',datestr(endDate)));
outHeight=500;
frameCount=0;
outputVideo=VideoWriter(strcat(titleString,'.avi'));
open(outputVideo)
pickDate=startDate;
while pickDate<=endDate
    datestr(pickDate,'yyyy-mm-dd')
    firstPage=strcat('https://chroniclingamerica.loc.gov/lccn/sn',num2str(newspaperNumber),'/',datestr(pickDate,'yyyy-mm-dd'),'/ed-1/seq-1/thumbnail.jpg');
    try
        img=imread(firstPage);  
        imgresizedtemp=imresize(img,[outHeight NaN]);
        padding=(round(outHeight*(4/3))-size(imgresizedtemp,2))/2;
        imgresized=padarray(imgresizedtemp,[0,ceil(padding)]);
        if((size(imgresized,2)/2)~=round(size(imgresized,2)/2))
            imgresized=imgresized(:,1:end-1,:);
        end
        writeVideo(outputVideo,imgresized);
        frameCount=frameCount+1;
        frameDate(frameCount)=pickDate;
        frameWidth(frameCount)=size(imgresizedtemp,2);
    catch
        try
            urlread(strcat('https://chroniclingamerica.loc.gov/lccn/sn',num2str(newspaperNumber),'/'),'Timeout',1);
        catch
            pickDate=pickDate-1;
        end
    end
    pickDate=pickDate+1;
end
close(outputVideo)
save(strcat(titleString),'frameDate','frameWidth');