Question on YouTube Podcast

Internet TV, Radio, Podcasts
Post Reply
S@gittarius
Posts: 98
Joined: Sat May 08, 2010 8:12 pm

Re: Question on YouTube Podcast

Post 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
S@gittarius
Posts: 98
Joined: Sat May 08, 2010 8:12 pm

Re: Question on YouTube Podcast

Post 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
S@gittarius
Posts: 98
Joined: Sat May 08, 2010 8:12 pm

Re: Question on YouTube Podcast

Post 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
Post Reply