repl.it
@minermaniac447/

Get Youtube Link from Search Query (sync)

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import requests
import re

def ytsearch(num, query):
    html = requests.get("https://youtube.com/results?search_query={}".format(query))
    html = str(html.content)
    dresults = (re.findall('href=\"/watch\?v=(.{11})', html))
    results = []
    for result in dresults:
        if result in results:
            continue
        else:
            results.append(result)
    if num > len(results):
        num = len(results)
    for x in range(num):
        link = "https://youtu.be/" + results[x]
        print(link)

query = input("pls\n")
num = input("how mnay videyoz do yew want\n")

try:
    num = int(num)
except Exception:
    num = 1

ytsearch(num, query)