存储附加到用户贡献内容的 YouTube 内容的最佳方法是什么?

发布于 2024-10-30 17:43:47 字数 471 浏览 0 评论 0原文

因此,我正在尝试实现与 Facebook 类似的功能,如果用户帖子包含链接,我会包含来自 YouTube 的信息,并且在单击时嵌入视频。

到目前为止我已经完成了,我只是想知道 Facebook 如何存储这些信息。

对我来说,有两种选择:

1)将帖子保存为普通文本(它只是纯文本),如果帖子包含 YouTube 链接,则每当查看该内容。不过我知道,当您发布链接时,Facebook 会为您提供更改标题、描述等的选项。这导致我..

2) 生成在查看和存储时附加的 HTML它与数据库插入级别的帖子一起。

如果是这样,这是否会为每个帖子添加大量信息?如果您稍后想要更改网站帖子中所有 YouTube 内容的格式,会发生什么情况?每个都将单独存储,看起来会很痛苦。

管理和维护的最佳方式是什么?设计这种功能?

干杯,

So I'm trying to implement similar functionality to Facebook where I am including information from YouTube should a users post contain a link, and when clicked it embeds the video.

I've accomplished it thus far, I'm just wondering how Facebook stores this information.

To me there are two options:

1) Have the post saved as normal (it is just plain text), and if the post contains a youtube link, append it on the fly in JavaScript whenever that content is viewed. However I know that when you post a link, Facebook gives you the option to change the title, description etc. Which leads me to..

2) Generate the HTML that would be otherwise appended when viewed and store it alongside the post at the database-insert level.

If so, doesnt that add a significant amount of information per post? What happens if you want to change the formatting of all youtube content within posts on your site later on? Each will be stored individually and seems like it would be a pain.

What is the best way to manage & engineer this sort of functionality?

Cheers,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

执手闯天涯 2024-11-06 17:43:47

我会将信息本身存储在数据库中,但不是以 HTML 形式存储。动态生成 HTML,但将数据存储在单独的位置。如果您不想添加太多额外的数据库字段,请考虑以某种序列化形式存储信息(例如 PHP 中的 serialize())。

无论如何,我总是将信息分开,并且从不存储自动生成的 HTML,除非它是某种可以重新生成的缓存

I'd store the information itself in the database, but not as HTML. Generate the HTML on the fly but store the data in a separate place. If you don't want to add too many extra database fields consider storing the information in some serialized form (like serialize() in PHP).

Anyway I would always keep information separated and never store auto-generated HTML unless it's some sort of cache that can be re-generated.

走过海棠暮 2024-11-06 17:43:47

如果您希望用户将视频包含在文本中,请在用户干预期间将链接存储在 HTML 中,并按原样从页面上的数据库中输出。然后,您的用户可以编辑他们的帖子,决定是否将视频放置在之前、之后、中间或根本不放置,并且可以更改 HTML 中的详细信息。

如果您以某种标准方式显示视频,请将视频链接与帖子一起存储在单独的数据库列中,并动态生成 HTML。您可以在尺寸、颜色等列中包含数据,但灵活性始终仅限于您决定存储的内容:如果有颜色的数据库列,那么您将让用户选择颜色,否则.. 。 不是。

因此,最灵活的方法是让用户输入 HTML。如果您认为他们无法胜任,或者您想限制他们对可以格式化的内容的选择,您可以使用 stackoverflow、wikipedia 等中提供的 java(script) 富文本编辑器,并且有多种可能性通过按钮以某些选定的方式编辑文本。您还可以将帖子存储在 XML 中,例如在选定的 HTML5 子集中(在特定容器中有效的任何内容......),并在演示时对其进行转换。

If you want the user to include his video within his text, store the link in HTML within that user's intervention, and output it as is from the database on the page. Then your users can edit their posts to decide whether to place the video before, after, in the middle or not at all, and can change the details in HTML.

If you are showing the video in some standard way, then store the video link along with the post in a separate database column, and generate the HTML on the fly. You can have data in columns for size, colour etc..., but the flexibility will always be limited to what you decide to store: if there is a database coloumn for colour then you are letting the user choose the colour, otherwise... not.

So, the most flexible is to let your users type HTML. If you think they aren't up to it, or you want to limit their choices of what they can format, you could use a java(script) rich text editor of the type that you have in stackoverflow, wikipedia etc., with possibilities to edit text in certain chosen ways via buttons. You could also store the post in XML, say in a chosen subset of HTML5 (anything that is valid in a certain container...), and transform it at presentation time.

愛放△進行李 2024-11-06 17:43:47

对我来说,这听起来像是一个太过分的问题。
如果您在帖子表单中实现 ckeditor,
它应该可以解决问题(如果我理解正确的话),
因为在 ckeditor 中你可以嵌入 swf/flv,
并且输出将是 html。

这使编辑者有权准确决定他想要视频的位置(因为他可以在表单中的任何位置添加链接)。

由于 flv/swf 附带来自 youtube 的元数据,因此您不需要保存该数据,
只是视频的链接。

to me this sounds like a problem that was taken too far.
if you implement ckeditor in your post form,
it should resolve the problem ( if i understood it right ),
since in ckeditor you can embed an swf/flv,
and the output will be html.

that gives the editor the power to decide exactly where he want the video ( since he can add the link wherever he wants in the form ).

since the flv/swf come with its meta data from youtube, you dont need to save that data,
just the link to the video.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文