-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMusicBotFinal.py
More file actions
56 lines (45 loc) · 2.05 KB
/
MusicBotFinal.py
File metadata and controls
56 lines (45 loc) · 2.05 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import vlc
import pafy
import urllib.request
import re
import youtube_dl
import tkinter as tk
from tkinter import ttk
from tkinter import *
# this is the function called when the button is clicked
def btnClickFunction():
getInputBoxValue()
# this is a function to get the user input from the text input box
def getInputBoxValue():
rawsearch = SongName.get()
search_keyword = rawsearch.replace(" ", "+")
html = urllib.request.urlopen("https://www.youtube.com/results?search_query=" + search_keyword)
video_ids = re.findall(r"watch\?v=(\S{11})", html.read().decode())
url = ("https://www.youtube.com/watch?v=" + video_ids[0])
video = pafy.new(url)
best = video.getbest()
playurl = best.url
Instance = vlc.Instance()
player = Instance.media_player_new()
Media = Instance.media_new(playurl)
Media.get_mrl()
player.set_media(Media)
player.play()
root = Tk()
# This is the section of code which creates the main window
root.geometry('1200x550')
root.configure(background='#ff3333')
root.title('MusicBot')
# This is the section of code which creates a listbox
listBoxOn=Listbox(root, bg='#F0F8FF', font=('arial', 12, 'normal'), width=0, height=0)
listBoxOn.insert('0', 'MusicBot by Nayak.')
listBoxOn.insert('1', 'Insert your video name into the text field below.')
listBoxOn.insert('2', 'While youtube tracks your usage and data, and sends them to advertisers, this player gets your videos anonymously.')
listBoxOn.insert('3', 'Note: VLC Player has to be installed')
listBoxOn.place(x=268, y=176)
# This is the section of code which creates a text input box
SongName=Entry(root)
SongName.place(x=32, y=498, height=30, width=1000)
# This is the section of code which creates a button
Button(root, text='Play Music', bg='#EEDFCC', font=('arial', 12, 'normal'), command=btnClickFunction).place(x= 1100, y=498)
root.mainloop()