Repository: SathyaBhat/spotify-dl

Issue:
Error SponsorBlock
The system downloads but does not convert to mp3 due to the error below, is there a way to skip this check?
Because it does not convert and is in webm format

[SponsorBlock] Fetching SponsorBlock segments
WARNING: Unable to communicate with SponsorBlock API: The read operation timed out. Retrying (1/3)...
WARNING: Unable to communicate with SponsorBlock API: The read operation timed out. Retrying (2/3)...
WARNING: Unable to communicate with SponsorBlock API: The read operation timed out. Retrying (3/3)...
ERROR: Postprocessing: Unable to communicate with SponsorBlock API: The read operation timed out
Failed to download Freak On a Leash, make sure yt_dlp is up to date
Failed to download: Freak On a Leash/Korn - Freak On a Leash.mp3, please ensure YouTubeDL is up-to-date.


Discussion:

Patch:
diff --git a/README.md b/README.md
index 1384fe5..b1752c0 100644
--- a/README.md
+++ b/README.md
@@ -30,6 +30,10 @@ If you want to make use of parallel download, pass `-mc <number>`, where `<numbe
 
     spotify_dl -mc 4 -l spotify_playlist_link_1 spotify_playlist_link_2
 
+Spotify-dl can make use of SponsorBlock and skip non-music sections when downloading from YouTube. This is disabled by default and can be enabled using:
+
+        spotify_dl -l spotify_playlist_link_1 -s y
+
 For running in verbose mode, append `-V`
 
     spotify_dl -V -l spotify_playlist_link -o download_directory
diff --git a/requirements.txt b/requirements.txt
index 186024e..2313956 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,5 +1,6 @@
 sentry_sdk~=1.5
 yt-dlp>=2022.01.21
-spotipy~=2.19
+spotipy~=2.21
 mutagen~=1.45
 rich~=12.0
+urllib3~=1.26
\ No newline at end of file
diff --git a/spotify_dl/spotify_dl.py b/spotify_dl/spotify_dl.py
index 94b0519..d1d6627 100755
--- a/spotify_dl/spotify_dl.py
+++ b/spotify_dl/spotify_dl.py
@@ -72,10 +72,10 @@ def spotify_dl():
     )
     parser.add_argument(
         "-s",
-        "--skip_non_music_sections",
-        default=False,
-        action="store_true",
-        help="Whether to skip non-music sections using SponsorBlock API.",
+        "--use_sponsorblock",
+        default="no",
+        action="store",
+        help="Whether to skip non-music sections using SponsorBlock API. Pass y or yes to skip using SponsorBlock",
     )
     parser.add_argument(
         "-w",
@@ -148,7 +148,9 @@ def spotify_dl():
         )
     )
     log.debug("Arguments: %s ", args)
-
+    console.print(
+        f"Sponsorblock enabled?: [bold green]{args.use_sponsorblock}[/bold green]"
+    )
     valid_urls = validate_spotify_urls(args.url)
     if not valid_urls:
         sys.exit(1)
@@ -180,7 +182,7 @@ def spotify_dl():
             skip_mp3=args.skip_mp3,
             keep_playlist_order=args.keep_playlist_order,
             no_overwrites=args.no_overwrites,
-            skip_non_music_sections=args.skip_non_music_sections,
+            use_sponsorblock=args.use_sponsorblock,
             file_name_f=file_name_f,
             multi_core=args.multi_core,
         )
diff --git a/spotify_dl/youtube.py b/spotify_dl/youtube.py
index 9538d1d..fc0e1ea 100644
--- a/spotify_dl/youtube.py
+++ b/spotify_dl/youtube.py
@@ -123,6 +123,7 @@ def find_and_download_songs(kwargs):
     the youtube_search lib is used to search for songs and get best url
     :param kwargs: dictionary of key value arguments to be used in download
     """
+    sponsorblock_postprocessor = []
     reference_file = kwargs["reference_file"]
     with open(reference_file, "r", encoding="utf-8") as file:
         for line in file:
@@ -140,27 +141,28 @@ def find_and_download_songs(kwargs):
             file_name = kwargs["file_name_f"](
                 name=name, artist=artist, track_num=kwargs["track_db"][i].get("num")
             )
-            sponsorblock_remove_list = (
-                ["music_offtopic"] if kwargs["skip_non_music_sections"] else []
-            )
 
-            file_path = path.join(kwargs["track_db"][i]["save_path"], file_name)
-            outtmpl = f"{file_path}.%(ext)s"
-            ydl_opts = {
-                "default_search": "ytsearch",
-                "format": "bestaudio/best",
-                "outtmpl": outtmpl,
-                "postprocessors": [
+            if kwargs["use_sponsorblock"][0].lower() == "y":
+
+                sponsorblock_postprocessor = [
                     {
                         "key": "SponsorBlock",
-                        "categories": sponsorblock_remove_list,
+                        "categories": ["skip_non_music_sections"],
                     },
                     {
                         "key": "ModifyChapters",
                         "remove_sponsor_segments": ["music_offtopic"],
                         "force_keyframes": True,
                     },
-                ],
+                ]
+
+            file_path = path.join(kwargs["track_db"][i]["save_path"], file_name)
+            outtmpl = f"{file_path}.%(ext)s"
+            ydl_opts = {
+                "default_search": "ytsearch",
+                "format": "bestaudio/best",
+                "outtmpl": outtmpl,
+                "postprocessors": sponsorblock_postprocessor,
                 "noplaylist": True,
                 "no_color": False,
                 "postprocessor_args": [


Test patch:
diff --git a/tests/test_youtube.py b/tests/test_youtube.py
index 0fccbf4..c941ac1 100644
--- a/tests/test_youtube.py
+++ b/tests/test_youtube.py
@@ -41,7 +41,7 @@ def test_download_one_false_skip():
         skip_mp3=False,
         keep_playlist_order=False,
         no_overwrites=False,
-        skip_non_music_sections=False,
+        use_sponsorblock="no",
         file_name_f=yt.default_filename,
         multi_core=0,
     )
@@ -49,7 +49,9 @@ def test_download_one_false_skip():
         "Hotel California - Live On MTV, 1994/Eagles - Hotel California - Live On MTV, 1994.mp3",
         ID3=EasyID3,
     )
-    tags = ID3("Hotel California - Live On MTV, 1994/Eagles - Hotel California - Live On MTV, 1994.mp3")
+    tags = ID3(
+        "Hotel California - Live On MTV, 1994/Eagles - Hotel California - Live On MTV, 1994.mp3"
+    )
     assert music["artist"][0] == "Eagles"
     assert music["album"][0] == "Hell Freezes Over (Remaster 2018)"
     assert music["genre"][0] == "album rock"
@@ -92,7 +94,7 @@ def test_download_one_true_skip():
         skip_mp3=True,
         keep_playlist_order=False,
         no_overwrites=False,
-        skip_non_music_sections=False,
+        use_sponsorblock="yes",
         file_name_f=yt.default_filename,
         multi_core=0,
     )
@@ -128,7 +130,7 @@ def test_download_cover_none():
         skip_mp3=False,
         keep_playlist_order=False,
         no_overwrites=False,
-        skip_non_music_sections=False,
+        use_sponsorblock="no",
         file_name_f=yt.default_filename,
         multi_core=0,
     )