MCPcopy Create free account
hub / github.com/Mrinank-Bhowmick/python-beginner-projects / search

Method search

projects/Qt5_YouTube/main.py:137–156  ·  view source on GitHub ↗

Search for query or URL and play it.

(self)

Source from the content-addressed store, hash-verified

135 self.mediaPlayer.error.connect(self.handleError)
136
137 def search(self) -> None:
138 """Search for query or URL and play it."""
139 query = self.searchBox.text()
140 if not query:
141 return
142
143 with YoutubeDL() as ydl:
144 try:
145 video = ydl.extract_info(query, download=False)
146 except DownloadError:
147 entries = ydl.extract_info(f"ytsearch:{query}", download=False)[
148 "entries"
149 ]
150 try:
151 video = entries[0]
152 except IndexError:
153 video = {}
154 if video:
155 self.mediaPlayer.setMedia(QMediaContent(QUrl(video["formats"][-1]["url"])))
156 self.playButton.setEnabled(True)
157
158 def openFile(self) -> None:
159 """Open and play a local file."""

Callers 14

get_all_chapter_linksFunction · 0.80
playSongFunction · 0.80
recommendSongFunction · 0.80
mainFunction · 0.80
__init__Method · 0.80
check_for_torrentsFunction · 0.80
findFunction · 0.80
regexSearchFunction · 0.80
testPasswordStrengthFunction · 0.80
fillGapsFunction · 0.80

Calls 1

textMethod · 0.45

Tested by

no test coverage detected