Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Support HTTPS in IFDB URLs
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:51383353b7c3b6bddd45cb7e01fda57d8cd05300
User & Date: brandon 2018-11-08 23:33:20
Context
2018-11-08
23:46
Tweak the default column widths check-in: b81d2abe51 user: brandon tags: trunk
23:33
Support HTTPS in IFDB URLs check-in: 51383353b7 user: brandon tags: trunk
23:22
Add in support for GIF cover images via the new support in pyifbabel check-in: b8bb5542ae user: brandon tags: trunk
Changes

Changes to src/grotesque/ifdb.py.

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
..
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
        tuid: the TUID to search for (default: None; try to use the TUID
              stored in the object's annotation data)
    """
    # Access the IFDB public API
    if ifid is None and tuid is None:
        raise Exception("No IFID or TUID set")
    if tuid is not None:
        url = ''.join(['http://ifdb.tads.org/viewgame?ifiction&id=',
                       tuid])
    else:
        url = ''.join(['http://ifdb.tads.org/viewgame?ifiction&ifid=',
                       ifid])
    try:
        ific = urllib2.urlopen(url)
    except urllib2.HTTPError:
        return None
    ificstring = ific.read()
    try:
................................................................................
    return ificstory


def fetch_cover(tuid=None, ifid=None):
    if tuid is None and ifid is None:
        return None
    if tuid is not None:
        cover_url = ''.join(["http://ifdb.tads.org/viewgame?ifiction&id=",
                             tuid, "&coverart"])
    else:
        cover_url = ''.join(["http://ifdb.tads.org/viewgame?ifiction&ifid=",
                             ifid, "&coverart"])
    try:
        cover_file = urllib2.urlopen(cover_url)
    except urllib2.HTTPError:
        return None
    cover_data = cover_file.read()
    if cover_data in ["No game was found matching the requested IFID.",
                      "No image is available"]:
        cover_data = None
    return cover_data







|


|







 







|


|










34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
..
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
        tuid: the TUID to search for (default: None; try to use the TUID
              stored in the object's annotation data)
    """
    # Access the IFDB public API
    if ifid is None and tuid is None:
        raise Exception("No IFID or TUID set")
    if tuid is not None:
        url = ''.join(['https://ifdb.tads.org/viewgame?ifiction&id=',
                       tuid])
    else:
        url = ''.join(['https://ifdb.tads.org/viewgame?ifiction&ifid=',
                       ifid])
    try:
        ific = urllib2.urlopen(url)
    except urllib2.HTTPError:
        return None
    ificstring = ific.read()
    try:
................................................................................
    return ificstory


def fetch_cover(tuid=None, ifid=None):
    if tuid is None and ifid is None:
        return None
    if tuid is not None:
        cover_url = ''.join(["https://ifdb.tads.org/viewgame?ifiction&id=",
                             tuid, "&coverart"])
    else:
        cover_url = ''.join(["https://ifdb.tads.org/viewgame?ifiction&ifid=",
                             ifid, "&coverart"])
    try:
        cover_file = urllib2.urlopen(cover_url)
    except urllib2.HTTPError:
        return None
    cover_data = cover_file.read()
    if cover_data in ["No game was found matching the requested IFID.",
                      "No image is available"]:
        cover_data = None
    return cover_data

Changes to src/grotesque/ui/gtk3/dialogs/editdialog.py.

1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
....
1426
1427
1428
1429
1430
1431
1432
1433
1434

1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
        url_hbox.set_orientation(Gtk.Orientation.HORIZONTAL)
        url_hbox.set_column_spacing(PADDING/2)
        url_label = Gtk.Label()
        url_label.set_text("URL: ")
        ifdb_dialog.url_entry = Gtk.Entry()
        ifdb_dialog.url_entry.set_property(
            "placeholder-text",
            "http://ifdb.tads.org/viewgame?id=XXXXXXXXXXXXXXXX")
        ifdb_dialog.url_entry.connect("activate", self._on_ifdb_dialog_activate,
                                      ifdb_dialog)
        url_hbox.add(url_label)
        ifdb_dialog.url_entry.set_hexpand(True)
        url_hbox.add(ifdb_dialog.url_entry)
        ifdb_dialog.stack.add_titled(url_hbox, "URL", "URL")
        ifdb_dialog.stack.set_visible_child(url_hbox)
................................................................................
    def _on_ifdb_dialog_accept(self, ifdb_dialog, response_id):
        if response_id == Gtk.ResponseType.CANCEL:
            ifdb_dialog.destroy()
            return
        fetch_cover = ifdb_dialog.toggle.get_active()
        if ifdb_dialog.stack.get_visible_child_name() == "URL":
            url = ifdb_dialog.url_entry.get_text().lower().strip()
            if (not url or url.count("=") != 1 or
                    not url.startswith("http://ifdb.tads.org/viewgame?id=")):

                d = Gtk.MessageDialog(self, Gtk.DialogFlags.MODAL,
                                      Gtk.MessageType.ERROR,
                                      Gtk.ButtonsType.OK)
                d.set_markup("Invalid URL")
                d.run()
                d.destroy()
                ifdb_dialog.entry.set_text("")
            else:
                tuid = url.split("=")[1]
                self._fill_metadata_from_ifdb(tuid=tuid)
                if fetch_cover:
                    self._import_cover_from_ifdb(tuid=tuid)
        else:
            ifid = ifdb_dialog.ifid_combo.get_active_text()







|







 







|
|
>



|


|







1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
....
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
        url_hbox.set_orientation(Gtk.Orientation.HORIZONTAL)
        url_hbox.set_column_spacing(PADDING/2)
        url_label = Gtk.Label()
        url_label.set_text("URL: ")
        ifdb_dialog.url_entry = Gtk.Entry()
        ifdb_dialog.url_entry.set_property(
            "placeholder-text",
            "https://ifdb.tads.org/viewgame?id=XXXXXXXXXXXXXXXX")
        ifdb_dialog.url_entry.connect("activate", self._on_ifdb_dialog_activate,
                                      ifdb_dialog)
        url_hbox.add(url_label)
        ifdb_dialog.url_entry.set_hexpand(True)
        url_hbox.add(ifdb_dialog.url_entry)
        ifdb_dialog.stack.add_titled(url_hbox, "URL", "URL")
        ifdb_dialog.stack.set_visible_child(url_hbox)
................................................................................
    def _on_ifdb_dialog_accept(self, ifdb_dialog, response_id):
        if response_id == Gtk.ResponseType.CANCEL:
            ifdb_dialog.destroy()
            return
        fetch_cover = ifdb_dialog.toggle.get_active()
        if ifdb_dialog.stack.get_visible_child_name() == "URL":
            url = ifdb_dialog.url_entry.get_text().lower().strip()
            if ((not url or url.count("=") != 1 or
                 (not url.startswith("http://ifdb.tads.org/viewgame?id=") and
                  not url.startswith("https://ifdb.tads.org/viewgame?id=")))):
                d = Gtk.MessageDialog(self, Gtk.DialogFlags.MODAL,
                                      Gtk.MessageType.ERROR,
                                      Gtk.ButtonsType.OK)
                d.set_markup("Invalid IFDB URL")
                d.run()
                d.destroy()
                ifdb_dialog.url_entry.set_text("")
            else:
                tuid = url.split("=")[1]
                self._fill_metadata_from_ifdb(tuid=tuid)
                if fetch_cover:
                    self._import_cover_from_ifdb(tuid=tuid)
        else:
            ifid = ifdb_dialog.ifid_combo.get_active_text()