How to generate a unique hash for a URL?

前端 未结 12 1393
时光取名叫无心
时光取名叫无心 2020-12-28 08:11

Given these two images from twitter.

http://a3.twimg.com/profile_images/130500759/lowres_profilepic.jpg
http://a1.twimg.com/profile_images/58079916/lowres_pr         


        
12条回答
  •  甜味超标
    2020-12-28 08:44

    It appears that the numerical part of twimg.com URLs are already a unique value for each image. My research indicates that the number is sequential (i.e. the example url below is for the 433,484,366th profile image ever uploaded - which just happens to be mine). Thus, this number is unique. My solution would be to simply use the numerical part of the filename as the "hash value", with no fear of ever finding a non-unique value.

    • URL: http:​//a2.twimg.com/profile_images/433484366/terrorbite-industries-256.png
    • Filename: 433484366.terrorbite-industries-256.png
    • Unique ID: 433484366

    I already use this system for a Python script that displays notifications for new tweets, and as part of its operation it caches profile image thumbnails to reduce unneccessary downloads.

    P.S. It makes no difference what subdomain the image is downloaded from, all images are available from all subdomains.

提交回复
热议问题