Youtube Downloader
Verfasst: Dienstag 24. Januar 2023, 06:31
Iam currently trying to code a youtube downloader... I want to use DearPyGUI for a nice GUI, and I want the user to be able to search for videos, then it is supposed to show a list of those videos, and then they are supposed to be able to select the one they want and download it... For some reason I cannot get it to work! Thats my code:
```py
import pytube
import dearpygui.dearpygui as dpg
from pytube import Search
resultsarray = []
def searchforvideos():
resultsarray = []
searchfield = dpg.get_value("searchfield")
s = Search(searchfield)
for v in s.results:
resultsarray.append(v.watch_url)
dpg.configure_item("resultlist",items=resultsarray)
def selectarrayfromlink(Sender):
print(resultsarray[dpg.get_value(Sender)])
def downloadvideo():
print("Download")
dpg.create_context()
dpg.create_viewport(title='R4Z0R-TUBE', width=1280, height=640)
with dpg.window(label="R4Z0R-TUBE",width=1280,height=640):
dpg.add_input_text(id ="searchfield",default_value="Funny Videos...")
dpg.add_button(label="Search",callback=searchforvideos)
dpg.add_listbox(tag="resultlist",items=resultsarray,num_items=5,callback=selectarrayfromlink)
dpg.add_button(label="Download",callback=downloadvideo)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()
```
I get the following error while trying to select a link from the list:
```Traceback (most recent call last):
File "D:\Python Projects\R4Z0R-TUBE\r4z0r-tube.py", line 18, in selectarrayfromlink
print(resultsarray[dpg.get_value(Sender)])
TypeError: list indices must be integers or slices, not str```
```py
import pytube
import dearpygui.dearpygui as dpg
from pytube import Search
resultsarray = []
def searchforvideos():
resultsarray = []
searchfield = dpg.get_value("searchfield")
s = Search(searchfield)
for v in s.results:
resultsarray.append(v.watch_url)
dpg.configure_item("resultlist",items=resultsarray)
def selectarrayfromlink(Sender):
print(resultsarray[dpg.get_value(Sender)])
def downloadvideo():
print("Download")
dpg.create_context()
dpg.create_viewport(title='R4Z0R-TUBE', width=1280, height=640)
with dpg.window(label="R4Z0R-TUBE",width=1280,height=640):
dpg.add_input_text(id ="searchfield",default_value="Funny Videos...")
dpg.add_button(label="Search",callback=searchforvideos)
dpg.add_listbox(tag="resultlist",items=resultsarray,num_items=5,callback=selectarrayfromlink)
dpg.add_button(label="Download",callback=downloadvideo)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()
```
I get the following error while trying to select a link from the list:
```Traceback (most recent call last):
File "D:\Python Projects\R4Z0R-TUBE\r4z0r-tube.py", line 18, in selectarrayfromlink
print(resultsarray[dpg.get_value(Sender)])
TypeError: list indices must be integers or slices, not str```