Search code examples
vine

Get vine short URL from video URL


Is there any way to get the short URL (e.g., https://vine.co/v/bnuOqmVhEWb) from the video URL (e.g., https://v.cdn.vine.co/v/videos/A5C08C32-A4AE-4DA4-A717-AEF60FBCA77F-3077-0000013C2DC639D3_1.0.4.mp4?versionId=g7.trI4Z0KR8P9qGEUvZ1LqP8BseMt25)?

I also have the vine's postId if that is helpful.


Solution

  • If you have postId, there is a way to hash it the way they do it.

    vine_key = 'BuzaW7ZmKAqbhMOei5J1nvr6gXHwdpDjITtFUPxQ20E9VY3Ll'
    example_post_id = 910326069930893312
    
    change example_post_id to base-49 (its vine_key size)
    # => [11, 20, 1, 14, 10, 7, 44, 12, 42, 4, 11]
    replace each digit of the base-49 number with the corresponding character on the vine_key # 0: B, 1: u, 2:z ... 47: L, 48: l
    # => [b, n, u, O, q, m, V, h, E, W, b]
    BOOM, you've got the hashed id
    # => "bnuOqmVhEWb"
    

    I implemented it on ruby, if you are interested: https://gist.github.com/davoclavo/7460039