From b37dd9f75b7296f2742ae5e0f31685641ceddbb1 Mon Sep 17 00:00:00 2001
From: Christoph Stahl <christoph.stahl@tu-dortmund.de>
Date: Mon, 18 Nov 2024 13:42:09 +0100
Subject: [PATCH] Fixed ytsearch a bit more and fixed missing metainfo for
 direct yt links

---
 syng/sources/youtube.py | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/syng/sources/youtube.py b/syng/sources/youtube.py
index e835eae..a061b9b 100644
--- a/syng/sources/youtube.py
+++ b/syng/sources/youtube.py
@@ -57,7 +57,7 @@ class YouTube:
                 return
             if self._infos is None:
                 raise RuntimeError(f'Extraction not possible for "{url}"')
-            self.length = self._infos["duration"]
+            self.length = int(self._infos["duration"])
             self._title = self._infos["title"]
             self._author = self._infos["channel"]
             self.watch_url = url
@@ -129,9 +129,11 @@ class Search:
         :param channel: The channel to search in.
         :type channel: Optional[str]
         """
-        sp = "EgIQAQ=="  # This is a magic string, that tells youtube to search for videos
+        sp = "EgIQAfABAQ=="  # This is a magic string, that tells youtube to search for videos
         if channel is None:
-            query_url = f"https://youtube.com/results?{urlencode({'search_query': query})}"
+            query_url = (
+                f"https://youtube.com/results?{urlencode({'search_query': query, 'sp': sp})}"
+            )
         else:
             if channel[0] == "/":
                 channel = channel[1:]
@@ -142,7 +144,7 @@ class Search:
         results = YoutubeDL(
             {
                 "extract_flat": True,
-                "quiet": False,
+                "quiet": True,
                 "playlist_items": ",".join(map(str, range(1, 51))),
             }
         ).extract_info(
@@ -377,8 +379,7 @@ class YoutubeSource(Source):
         Video metadata should be read on the client to avoid banning
         the server.
         """
-        if entry.incomplete_data:
-            print(f"Looking up {entry.ident}")
+        if entry.incomplete_data or None in (entry.artist, entry.title):
             youtube_video: YouTube = await asyncio.to_thread(YouTube, entry.ident)
             return {
                 "duration": youtube_video.length,
-- 
GitLab