import base64 def encode_base64(img_file): with open(img_file, 'rb') as f: img_data = f.read() base64_data = base64.b64encode(img_data) print(base64_data) return base64_data def decode_base64(base64_data): with open('base64.jpg', 'wb') as file: img = base64.b64decode(base64_data) file.write(img) if __name__ == '__main__': img_path = '5f2d09b016407.jpg' base64_data = encode_base64(img_path) decode_base64(base64_data)
import base64 b64url = 'aHR0cDovL3Y5LXhnLXdlYi1zLml4aWd1YS5jb20vZmFlZjUwZmNlOTY5ZTQzOTNlYWU0NDJjNTk2MmVlMzYvNjExNGY4OWMvdmlkZW8vdG9zL2NuL3Rvcy1jbi1vLTAwMDQvZGQ2YzViNjk1Yjk3NDkzYjg2NDUzZjhjNDFhODlkMjcvbWVkaWEtdmlkZW8tYXZjMS8/YT0xNzY4JmJyPTIzODMmYnQ9MjM4MyZjZD0wJTdDMCU3QzAmY2g9MCZjcj0wJmNzPTAmY3Y9MSZkcj0wJmRzPTQmZXI9MCZmdD01dEd+TFRURUhHUU1DfkZhNGswRTFldC5TaiZsPTAyMTYyODc2MDY1NTE3MjAwMDAwMDAwMDAwMDAwMDAwMDAwZmZmZjBhOTc1M2UzNGRjMTNhJmxyPWRlZmF1bHQmbWltZV90eXBlPXZpZGVvX21wNCZuZXQ9MCZwbD0wJnFzPTAmcmM9TXp0elpqUTZabmc3TnpNek5EY3pNMEFwYUdjN05qZGtOVHM0TjJScE5UZHBhV2R6WW1wamNqUXdaRjVnTFMxa0xTOXpjekpoTUMxaFl6QmlNakpqWGw1ak1XRTZZdyUzRCUzRCZ2bD0mdnI9' url = base64.b64decode(bytes(b64url, encoding='utf8')) print(url) --->>> b'http://v9-xg-web-s.ixigua.com/faef50fce969e4393eae442c5962ee36/6114f89c/video/tos/cn/tos-cn-o-0004/dd6c5b695b97493b86453f8c41a89d27/media-video-avc1/?a=1768&br=2383&bt=2383&cd=0%7C0%7C0&ch=0&cr=0&cs=0&cv=1&dr=0&ds=4&er=0&ft=5tG~LTTEHGQMC~Fa4k0E1et.Sj&l=02162876065517200000000000000000000ffff0a9753e34dc13a&lr=default&mime_type=video_mp4&net=0&pl=0&qs=0&rc=MztzZjQ6Zng7NzMzNDczM0ApaGc7NjdkNTs4N2RpNTdpaWdzYmpjcjQwZF5gLS1kLS9zczJhMC1hYzBiMjJjXl5jMWE6Yw%3D%3D&vl=&vr=' print(str(url, encoding='utf8')) --->>> http://v9-xg-web-s.ixigua.com/faef50fce969e4393eae442c5962ee36/6114f89c/video/tos/cn/tos-cn-o-0004/dd6c5b695b97493b86453f8c41a89d27/media-video-avc1/?a=1768&br=2383&bt=2383&cd=0%7C0%7C0&ch=0&cr=0&cs=0&cv=1&dr=0&ds=4&er=0&ft=5tG~LTTEHGQMC~Fa4k0E1et.Sj&l=02162876065517200000000000000000000ffff0a9753e34dc13a&lr=default&mime_type=video_mp4&net=0&pl=0&qs=0&rc=MztzZjQ6Zng7NzMzNDczM0ApaGc7NjdkNTs4N2RpNTdpaWdzYmpjcjQwZF5gLS1kLS9zczJhMC1hYzBiMjJjXl5jMWE6Yw%3D%3D&vl=&vr=