Repository: J-CPelletier/webcomix

Issue:
Enhancement Schlock Mercenary 
Is it possible to add https://www.schlockmercenary.com/ to the list of supported comics?

Discussion:

Patch:
diff --git a/webcomix/comic.py b/webcomix/comic.py
index 54bb578..e135208 100644
--- a/webcomix/comic.py
+++ b/webcomix/comic.py
@@ -1,5 +1,6 @@
 import os
 from typing import List, Mapping
+from urllib.parse import urlparse
 from zipfile import ZipFile, BadZipFile
 
 import click
@@ -153,10 +154,13 @@ class Comic:
         if url.count(".") <= 1:
             # No file extension (only dot in url is domain name)
             return str(page)
-        elif title_present:
-            return "{}-{}{}".format(comic_name, page, url[url.rindex(".") :])
+
+        parsed_filepath = urlparse(url).path
+        file_extension = parsed_filepath[parsed_filepath.rindex(".") :]
+        if title_present:
+            return "{}-{}{}".format(comic_name, page, file_extension)
         else:
-            return "{}{}".format(page, url[url.rindex(".") :])
+            return "{}{}".format(page, file_extension)
 
     @staticmethod
     def save_alt_text_location(page: int, directory_name: str = "") -> str:
diff --git a/webcomix/supported_comics.py b/webcomix/supported_comics.py
index b4e76e7..8c62ded 100644
--- a/webcomix/supported_comics.py
+++ b/webcomix/supported_comics.py
@@ -75,4 +75,9 @@ supported_comics = {
         "//img[@class='comicnormal']/@src",
         "//a[img[contains(@src, 'next')]]/@href",
     ),
+    "SchlockMercenary": (
+        "https://www.schlockmercenary.com/2000-06-12",
+        "//div[@class='strip-images']//img/@src",
+        "//a[@class='next-strip']/@href",
+    ),
 }


Test patch:
diff --git a/webcomix/tests/test_comic.py b/webcomix/tests/test_comic.py
index f11a01c..7fdb46c 100644
--- a/webcomix/tests/test_comic.py
+++ b/webcomix/tests/test_comic.py
@@ -66,6 +66,12 @@ def test_save_image_location():
         == "foo/1.jpg"
     )
     assert Comic.save_image_location("", 1, "bar") == "bar/1"
+    assert (
+        Comic.save_image_location(
+            "http://imgs.xkcd.com/comics/barrel_cropped_(1).jpg?q=123", 1, "foo"
+        )
+        == "foo/1.jpg"
+    )
 
 
 def test_save_image_filename_with_title_present():