Page 1 of 1
Re: Question on YouTube Podcast
Posted: Sat May 07, 2011 6:53 pm
by S@gittarius
dan.crouthamel wrote:When I download a podcast, so for a youtube user, the create date in the table shows the time at which I downloaded the podcast. How can I update it to show the date which the video was uploaded?
Thanks.
Hi,
Put this piece of code into "The script read additional properties RSS" settings section of the podcast:
Code: Select all
var
sYoutube, sVideoID: string;
xYoutube: TXMLDocument;
function GetYoutubeDate(const sValue: string): variant;
begin
if trim(sValue) <> '' then Result := Copy(sValue, 9, 2) + '.' + Copy(sValue, 6, 2) + '.' + Copy(sValue, 1, 4) + ' ' + Copy(sValue, 12, 5)
else Result := Now;
end;
begin
if WmsRegExMatch('watch\?v=(.*)&', mpFilePath, sVideoID) and (sVideoID <> '') then begin
sYoutube := WmsDownloadURL('http://gdata.youtube.com/feeds/api/videos/' + sVideoID + '?fields=published');
xYoutube := TXMLDocument.Create;
try
xYoutube.LoadFromString(sYoutube);
PodcastItem.Properties(mpiCreateDate) := GetYoutubeDate(xYoutube.root.childvalues('published'));
finally
xYoutube.free
end
end
end.
Regards
Re: Question on YouTube Podcast
Posted: Sun May 08, 2011 10:24 am
by S@gittarius
Hi,
Glad to help you.
Yes, it's all about regional settings that I missed to comment on.
The code could be optimized in order not to depend on them.
Bear in mind that it makes an API request to Youtube for every single podcast item. So if the podcast consist of the maxim number of 50 items per page (it's a Youtube constraint) the update will take considerably longer than usual.
Regards
Re: Question on YouTube Podcast
Posted: Fri May 13, 2011 8:25 am
by S@gittarius
dan.crouthamel wrote:
I do have max-results set to 50 in the podcast link, but it doesn't take too long to update.
Yes, but in the end it takes at least 50 times longer than without this extra.
dan.crouthamel wrote:I also ended up using the EncodeDate and EncodeTime functions to eliminate the assumption of a regional setting.
I wrote this code for myself and didn't think to make it universal. But these are the functions to circumvent regional settings. Well done.
dan.crouthamel wrote: However, I'm wondering if there is a function that simply takes a timestamp string, e.g., 2011-02-13T19:24:26.000Z, and returns a TDateTime object.
As far as I know WMS does not export such a function. Recently I had a discussion with Eugene about Unix epoch timestamp to TDateTime conversion and he implemented a pair of functions: TimeStamp1970ToDateTime <-> DateTimeToTimeStamp1970. Maybe he could help again though this particular conversion is service dependent. For instance Vimeo does use a little bit different time format:
Youtube timestamp -> 2010-05-30T23:23:59.000Z
Vimeo timestamp -> 2011-02-21 19:00:02
I think it's not a good idea WMS to contain functions which are content bound. So we have to be creative.
Regards