dougou7008 2015-06-21 15:24
浏览 52
已采纳

你如何构建youtube url?

I am wondering how the youtube url is constructed? for example https://www.youtube.com/watch?v=L7Jd910Bw84

  1. how is the value L7Jd910Bw8 created, is it a hash value ?
  2. is there any PHP function to use for creating this kind of urls?
  3. how is it possible to make sure that the two diffrent objects dont get the same value ?
  4. what is the advantages and disanvatages using this kind of url?

Thanks :) !

  • 写回答

1条回答 默认 最新

  • dsxz84851 2015-06-21 16:07
    关注
    1. It is basically just an ID to uniquely identify a video. Technically, there is no need to hash it, but they do encode it into a string to make the ID a little more unreadable.
    2. Not specifically for YouTube URLs, but it is easy to create your own "hashed" ID string for any resource item with a numeric ID (like an auto-increment numeric primary key). You just run the numeric ID through some simple reversible math function, then encode the resultant number with an alphabet of characters you want, e.g. base58. Or you can simply hash it with a more complicated algorithm, if CPU power is not a concern.
    3. If your IDs are different to begin with, there should be no collisions if all you do is a simple encoding, e.g. some math function, then decimal to base58. Even if you use a more complicated algorithm, there's also next-to-zero chance for most algorithms.
    4. Advantage and Disadvantage
      • Advantage: security / privacy. Since most numeric IDs run in sequence, if you simply use id=123456, everyone sort of knows that you have 123456 items in your DB. With an encoded string, nobody knows.
      • Disadvantage: processing. Obviously, there's going to be a slight increase in processing required to generate these IDs.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程