mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 14:47:29 +00:00
post shortcode converter
This commit is contained in:
parent
bf80104b1a
commit
efb5818a65
@ -10,11 +10,13 @@ import android.util.Patterns;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class TextUtils {
|
||||
// extracted from String class
|
||||
@ -106,4 +108,15 @@ public final class TextUtils {
|
||||
}
|
||||
return urls;
|
||||
}
|
||||
|
||||
// https://github.com/notslang/instagram-id-to-url-segment
|
||||
public static long shortcodeToId(final String shortcode) {
|
||||
long result = 0L;
|
||||
for (int i = 0; i < shortcode.length() && i < 11; i++){
|
||||
final char c = shortcode.charAt(i);
|
||||
final int k = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".indexOf(c);
|
||||
result = result * 64 + k;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
package awais.instagrabber.utils;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class TextUtilsTest {
|
||||
|
||||
@org.junit.jupiter.api.Test
|
||||
@Test
|
||||
void testMillisToTimeString() {
|
||||
String timeString = TextUtils.millisToTimeString(18000000);
|
||||
Assertions.assertEquals("05:00:00", timeString);
|
||||
@ -15,4 +16,12 @@ class TextUtilsTest {
|
||||
timeString = TextUtils.millisToTimeString(300000, true);
|
||||
Assertions.assertEquals("00:05:00", timeString);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testShortcodeConversion() {
|
||||
long conversion = TextUtils.shortcodeToId("CA0YnOonSfS");
|
||||
Assertions.assertEquals(2320587956892280786L, conversion);
|
||||
conversion = TextUtils.shortcodeToId("B_7n8mblwx6gv1ZaNvA5ZhAs2qslMnRiMMYW1c0");
|
||||
Assertions.assertEquals(2304611322577751162L, conversion);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user