Getting Video ID

Subscribe to Getting Video ID 8 posts, 3 voices

 
Avatar Alex Ezell 18 posts

How does one get the VideoID of a video which has just been uploaded via the API? So, my user uploads his video directly to HW via a form on my site. I want to show him an encode link, but I need to know the VideoID for that video. How do I find it out if there are several other raw videos which have been uploaded by other users?

 
Avatar Bruno Celeste 374 posts

When a video has been uploaded from your site, you will receive a ping (if you enable it) with all the info about the new video (including the video id).

See the howto on the wiki, it will help you.

 
Avatar andjules 3 posts

this should probably be a post in the suggestions forum, but: having to develop/enable a REST API just to get the video ID seems like a big hurdle, or maybe I am missing something (and as a never-as-smart-as-I’d-like-to-be developer, I find it a lot easier to use an API than to develop/provide one).

if the typical use case is to upload a video, have it encoded and get it back to me… then I really should be able to predict the filename of the encode right from the upload point, either from a) info I provide you in my upload, or b) by a response I get from you after the upload. EXAMPLE: I set up auto FTP transfer, perhaps even auto-encode. I then use the API or a form to upload a video. Either the response or (if I used a form) the querystring/post of the success redirect should give me an ID or a “name”. If I either i) code my app to issue an encode request after the upload, or ii) have my user on the redirect page trigger the encode, or iii) have set up auto encoding, I should expect that when things are done (encode/FTP), I will find a file in my FTP folder called something like VIDEOID_ENCODEID.mov or VIDEONAME_ENCODEID.flv or something like that.

If I am having my user upload a video as part of some user “post” (like a blog, etc.) then I want to be able to build that blog post in my app right then and there. I can’t really – at least not without developing an api to respond to the ping. I need to wait and do some back-and-forth stuff to figure out what my final video path/filename will be. I don’t mind that the video won’t be available right away (when people try to access it, I can do a simple file check (or API check) and give a ‘waiting’ status if the video isn’t ready yet), but I would like to know what it will be called when it gets here.

 
Avatar Bruno Celeste 374 posts

If you activate the ping after upload, you will receive something like this:

{"upload_id"=>"UPLOAD_ID", "your_site_user_id"=>"20", "video"=>"<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<video>
<title>my video title</title>
<specs>
   <thumb><a href="http://static-1.heywatch.com/thumbs/NoqnVdHmocq4UznykpZl36FrkH0Q1estKaWuK73M.jpg">http://static-1.heywatch.com/thumbs/NoqnVdHmocq4UznykpZl36FrkH0Q1estKaWuK73M.jpg</a></thumb>
  <mime-type>video/x-msvideo</mime-type>
  <audio codec=\"mp3\" sample_rate=\"48000\" channels=\"2\" stream=\"0.1\" bitrate=\"192\"/>
  <size>239099</size>
  <video codec=\"mpeg4\" container=\"avi\" length=\"1439\" aspect=\"1.78\" fps=\"23.98\" width=\"704\" height=\"396\" stream=\"0.0\" bitrate=\"1360\"/>
</specs>
<id>1018</id>
<created-at>Tue Jan 23 12:27:21 CET 2007</created-at>
</video>"}

You have the video id: 1018.

When you receive a ping after encode, you get the filename. So, you should find the encoded video by this filename easily in your FTP. Note that the thumb is uploaded too: filename.jpg

 
Avatar andjules 3 posts

I did see that. It’s just that an intermediate developer would have a much easier time extracting the info (video ID) from the response (either the upload API call, or a form > success redirect). An intermediate developer will be far more intimidated by trying to develop a page or API that reacts, parses and extracts from your ping and marries the upload_ID to the upload API call that just finished, then marry the video ID to the user post on their site. I’d like to think I am a bit better than “intermediate”, and I am intimidated.

Bruno, do you have any simple sample code of what a PHP page might look like at the ping-after-upload URL, as far as parsing the mix of array + XML you send back?

It’s also unfortunate that auto-encode (and auto FTP) is an option, but tracking encoded video by the upload_ID isn’t possible. Not much saved if you have to get the video ID from the upload ID, and then get the encoded video ID from the video ID.

 
Avatar Bruno Celeste 374 posts

If I decided to marry XML and parameters, it is because you maybe need other info than the ID. Instead of pinging http://heywatch.com/video/ID.xml, you have all the info directly.

The upload_id you receive by ping is not important for you. The most important is the “your_site_user_id”, having this value, you can do the relation between the video object and the user (from your site).

To get what you want is easy (not tested):

$_POST['your_site_user_id'];

$video = simplexml_load_string($_POST['video']);
$video_id = $video->id;

So, I don’t see the point.

Unfortunately, I have no complete PHP sample, I’m not a PHP guy :)

Here is the whole process, maybe you will understand it better:

If you upload from the disk (3 steps):

  • upload => return video object
  • job creation => when status=finished, encoded_video_id is filled
  • encoded video => get the link to download it

If you transfer from the web (4 steps):

  • discover => when status=ok, result is filled (not necessary if the url you put is pointing to a video)
  • download => when status=finished, video_id is filled
  • job creation => when status=finished, encoded_video_id is filled
  • encoded video => get the link to download it

Keep in mind that automatic encode and send to FTP/S3 are for general purpose and you can’t track all the process that way. If you need to track from the beginning to the ending or need something more specific, you have to do it ‘manually’ and follow the steps I wrote.

 
Avatar andjules 3 posts thanks for the reply. perhaps I missed something:

upload => return video object

are you saying that the upload already does return info about the video (in the form of a response)? or are you just talking about the xml ping?

as per “your_site_user_id” being the important thing, I am seeing videos being married to “posts” on my site, not just users. Ideally, I want the user – perhaps in a multistep form – to upload, then add description, tags, etc. I’d like to build the post right then, right there, and know that I can expect to find the encoded video id when it is ready. “your_site_user_id” may be problematic if the user uploads several videos in a short span – will I have trouble marrying the right video to the right ‘post’ on my end. I think I can do everything else I need to by contacting your API and without building my own an API to parse the XML ping, except for getting my hands on the video ID.

A different perspective, I suppose, and obviously I am working from a phobia around building an API to react to your ping (as opposed to parsing a simple response to the original upload request). I suppose I could re-purpose “your_site_user_id” as “post_id” from my end.

Bruno, I have to say I am impressed with your API and your involvements in these forums. Thanks for the discussion.

 
Avatar Bruno Celeste 374 posts

Yes, when the upload is done, you’ve get in response the new video in XML with all the info, no need of ping. But you want your users upload directly from your site via an HTML form, so the only possibility is the ping.

In fact, you can put whathever you want in custom parameters. In your case, of course post_id, user_id are the fields you must include in the form to track the process. It’s really simple, following what you said:

<form action="http://heywatch.com/upload" method="post">
<input type="hidden" name="key" value="yourkey" />
<input type="hidden" name="post_id" value="postid" />
<input type="hidden" name="user_id" value="youruserid" />
<input type="file" name="data" />
<input type="text" name="title"  />
<input type="text" name="tags"  />
<textarea name="description"></textarea>
<input type="sumbit" value="Go" />

“your_user_id” is just an example ;) The custom parameters are unlimited, you can put all you want.

Via this form, you will receive all the values via the ping request. You can track your user, the post and the raw video.

To continue the process: Lets say you have a hwjob table (id, user_id, post_id, video_id, job_id[default=NULL], encoded_video_id[default=NULL])
  • When you get the ping after upload, save the user_id, post_id and the video_id you received in the hwjob table.
  • Create the job with the following parameters: video_id (you just get it) and format_id (what you want) => return the job in XML including the ID
  • Save the job_id in hwjob
  • At this point, you have one row in your table with these values (just examples) : |id=1| user_id=40 | post_id= 2500| job_id=4000 |
  • At the end of the encode, you get notified via ping with parameter “encoded_video” in XML format. It contains the famous “job_id” in it. You search in your hwjob the row with job_id=the_job_id_you_just_get
  • Update the row to put the ID of the new encoded video.

It’s just an example, I don’t know what you’re trying to do, but I think you have the key ;)