-
Notifications
You must be signed in to change notification settings - Fork 1
/
yoogle.py
28 lines (26 loc) · 790 Bytes
/
yoogle.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 re
from video import search_video
from playlist import search_playlist
def parse(url):
if 'list' in url:
#parse for list
exp = "list=([a-zA-Z0-9-_]+)&?"
return re.findall(exp, url)[0], 1
elif 'v=' in url:
# parse for videoID
if '&' in url:
return url[url.find('v=')+2 : url.find('&')], 0
else:
return url[url.find('v=')+2:], 0
elif '.be' in url:
return url[url.find('.be')+4:], 0
else:
return None, None
def main(url,searchTerm = None):
extracted_id, n = parse(url)
if not extracted_id:
return {'messages': ['Invalid URL']}
if n == 1:
return search_playlist(extracted_id, searchTerm)
else:
return search_video(extracted_id, searchTerm)