I do REST for the site. The REST API must have a video
resource. When accessing domain.name/api/videos/
you need to return a list of all videos in the following format:
{ 'title': str, 'thumbnail': url, 'video': url }
With this no problem, of course, no.
The question is as follows:
for the site you need to implement the download (and subsequent display) of the video from:
youtube
vimeo
from the user's computer
To save a new video from youtube and vimeo, we can simply make a POST
request for domain.name/api/videos/
with the corresponding fields filled in (the values of which we previously received from api youtube and vimeo), and save the resulting object to the database on the server only validation.
And what about user videos - those that should be downloaded from the user's computer?
I think as follows:
Let's start with the thumbnail
. This is a picture. As far as I understand REST, it should be a separate resource available at domain.name/api/images/
. So before uploading a video, we need to cut a frame from the video (or the user will download the desired image into the form) and send it to the server - this is not a problem. In response, from POST => domain.name/api/images/
we get:
{ 'id': int, 'src' url }
And here the most interesting thing is that we give the absolute url of the image to the client, but in the database on the server we keep the path to it. That is, when creating an answer, we do something like settings.STATIC_BASE + image.path
(it's just pseudo-code to get my thoughts across).
But in video
we can’t just take an absolute url to a picture on our server, because today we have settings.STATIC_BASE == '245.41.20.48/static/'
and tomorrow it will turn into http://d111111abcdef8.cloudfront.net
and all downloaded thumnail'ы
will become unavailable. Right?
If true, then the thumbnail
the video
should be either:
ForeignKey
- in the case of a custom video (and a custom cover)or just a line - if the video is "downloaded" from youtube or vimeo
At the moment, none of this is implemented, so I can make any necessary option. I am interested in how this should be implemented in terms of:
- architecture
- models in code
- resources in rest
I do not expect a completely chewed answer, something should help me and in the spirit of "see how it's done here." I tried to look into api vk.com, fb.com, ok.ru myself, but they somehow have it all differently, so I decided to find out here which way to dig.
UPD:
So far, the most questions are how to solve the problem with the fact that the Video
model has a thumbnail
field that must be “simultaneously” with a ForeignKey that refers to an Image
object, and a simple строкой
containing a link to a picture on a third-party resource.
Video
thumbnail
field should be “simultaneously” with the Foreign Key, which refers to theImage
object, and a simple line containing a link to a picture on a third-party resource - fobedepsettings.STATIC_BASE
and do not forget to change them synchronously with the server when moving statics to another url? However, I am waiting for the evening, thanks for the desire to help. - fobedep