mirror of
https://github.com/jack-something/gib-sauce
synced 2024-11-21 19:44:16 -05:00
:D
This commit is contained in:
parent
339cac4dc4
commit
4b84a39654
@ -1 +1,3 @@
|
||||
# gib-sauce
|
||||
|
||||
A CLI program which allows you to find where a picture is from, it also prints a bunch of URLs (in the terminal) where you can download the original picture.
|
54
sauce
Executable file
54
sauce
Executable file
@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import json
|
||||
import sys
|
||||
from urllib.request import Request, urlopen
|
||||
from urllib.request import urlretrieve
|
||||
import argparse
|
||||
|
||||
def get_json(picture_url):
|
||||
url = "https://saucenao.com/search.php?db=999&output_type=2&testmode=1&numres=16&url=" + picture_url
|
||||
req = Request(url, headers={"User-Agent": 'Mozilla/5.0'})
|
||||
data = json.loads(urlopen(req).read().decode())
|
||||
|
||||
return data
|
||||
|
||||
def parse_json(data):
|
||||
title = []
|
||||
sources = []
|
||||
for d in data["results"]:
|
||||
if d["data"]:
|
||||
for k,v in d["data"].items():
|
||||
if (k == "material"):
|
||||
title.append(v)
|
||||
elif (k == "ext_urls"):
|
||||
|
||||
for i in v:
|
||||
sources.append(i)
|
||||
#else:
|
||||
#sources.append(v)
|
||||
|
||||
return title, sources
|
||||
|
||||
|
||||
|
||||
def main(picture_url):
|
||||
data = get_json(picture_url)
|
||||
arr = parse_json(data)
|
||||
print("Found the following matches:")
|
||||
for i in arr[0]:
|
||||
print( "-" + i)
|
||||
|
||||
print("\nWith the following pictures:")
|
||||
for j in arr[1]:
|
||||
print(str(j))
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--url", help="url of the picture you wish to look up")
|
||||
args = parser.parse_args()
|
||||
if (args.url == None):
|
||||
print("You need to specify an URL.")
|
||||
exit(-1)
|
||||
else:
|
||||
main(args.url)
|
Loading…
Reference in New Issue
Block a user