chevron_left chevron_right
Login Register invert_colors photo_library


Stay updated and chat with others! - Join the Discord!
Thread Rating:
  • 0 Vote(s) - 0 Average


GiyPy - Dynamic Google Searcher filter_list
Author
Message
GiyPy - Dynamic Google Searcher #1
GiyPy is a dynamic Google searcher, it searches for YouTube videos, Images, and Google results from Google itself.

This is actually REALLY long, and I've explained all of these functions on other threads before. The only unexplained function is the google searcher, which will be explained in another thread, and hopefully by @TryhardHusky. >.>

Code:
import urllib,urllib.parse,urllib.request,json,random,re

class google():
    def search(query):
        try:
            x = random.randint(0,2)
            xdat = json.loads(urllib.request.urlopen("http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q="+(urllib.parse.quote(query))).read().decode("utf-8"))
            return "\n%s\n%s" % (((xdat["responseData"]["results"][0])["title"]), (urllib.parse.unquote((xdat["responseData"]["results"][0])["url"])))
        except: return "Error"
    
    def youtube(query):
        try:
            xdat = str((urllib.request.urlopen("http://gdata.youtube.com/feeds/api/videos?vq="+query.replace(' ','_')+"&racy=include&orderby=relevance&max-results=1")).read())
            if "<openSearch:totalResults>0</openSearch:totalResults>" in (xdat): return "No results."
            else:
                trash , yclean=(xdat).split("<media:player url='http://www.youtube.com/watch?v=",1)
                yclean , trash=yclean.split("&amp;",1)
                trash2 , yclean2=(xdat).split("<media:title type='plain'>",1)
                yclean2 , trash2=yclean2.split("</media:title>",1)
                trash3 , yclean3=(xdat).split(yclean+"'/><author><name>",1)
                yclean3 , trash3=yclean3.split("</name>",1)
                return yclean2.capitalize()+"\nUploaded by "+yclean3.capitalize()+"\nhttps://www.youtube.com/watch?v="+yclean
        except: return "Error"
    def images(query):
        try:
            mx = []
            for m in (re.finditer('"unescapedUrl":"(.+?)","url":"', ((urllib.request.urlopen("http://ajax.googleapis.com/ajax/services/search/images?v=1.0&q="+("+".join(query)))).read().decode()))):
                m = str(m.group(1))
                mx.append(m)
            return random.choice(mx)
        except: return "Error"

Explanations:
- YouTube: https://www.sinister.ly/Thread-YouTube-Search-Explained
- Google Images: https://www.sinister.ly/Thread-Google-Im...ch-program
- Google Search: https://www.sinister.ly/Thread-GITpy-Goo...-Explained

Credit:
@TryhardHusky - Programming
@Duubz - Programming

Additionally, if you would like to have a program that uses these functions, you can view my GitHub repository at https://github.com/Duubz/GiyPy/blob/master/giy.py.

Reply






Users browsing this thread: 1 Guest(s)