fixed blocking subprocess launch to xdg-open for magnet link handling

master v1.0
Chris Punches 2018-10-08 00:26:41 -04:00
parent 277feac742
commit 46ecc8ed04
9 changed files with 7 additions and 526 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.idea

View File

@ -21,14 +21,12 @@ class Config:
class Scallywag: class Scallywag:
def on_btnRefresh_clicked( self, object, data=None ): def on_btnRefresh_clicked( self, object, data=None ):
# TODO implement refresh
self.status("refresh pressed") self.status("refresh pressed")
def on_btnSearch_clicked( self, object, data=None ): def on_btnSearch_clicked( self, object, data=None ):
self.status("search pressed") self.status("search pressed")
# clear the results_store # clear the results_store
# seeders, leechers, size, name # seeders, leechers, size, name
self.results_store.clear() self.results_store.clear()
@ -36,10 +34,6 @@ class Scallywag:
for row in self.results_store: for row in self.results_store:
self.results_store.remove(row) self.results_store.remove(row)
# prove to me that the results_store is populated
for row in self.results_store:
print(row[:])
for column in self.results_tree_view.get_columns(): for column in self.results_tree_view.get_columns():
self.results_tree_view.remove_column(column) self.results_tree_view.remove_column(column)
@ -47,7 +41,6 @@ class Scallywag:
self.results_tree_view.set_model(self.results_store) self.results_tree_view.set_model(self.results_store)
# add search result entries to the results store # add search result entries to the results store
# TODO add retrieval from search textentry
search_field = self.builder.get_object("txtSearch") search_field = self.builder.get_object("txtSearch")
search_terms = search_field.get_text() search_terms = search_field.get_text()
@ -55,10 +48,6 @@ class Scallywag:
print( result.__str__() ) print( result.__str__() )
self.results_store.append( [ result.seeders, result.leechers, result.size, result.title, result.author, result.url ]) self.results_store.append( [ result.seeders, result.leechers, result.size, result.title, result.author, result.url ])
# prove to me that the results_store is populated
for row in self.results_store:
print(row[:])
for i, col_title in enumerate( [ "Seeders", "Leechers", "Size", "Title", "Author", "Url" ] ): for i, col_title in enumerate( [ "Seeders", "Leechers", "Size", "Title", "Author", "Url" ] ):
# renderer creation # renderer creation
renderer = Gtk.CellRendererText() renderer = Gtk.CellRendererText()
@ -69,8 +58,6 @@ class Scallywag:
# add column to tvw # add column to tvw
self.results_tree_view.append_column(column) self.results_tree_view.append_column(column)
def get_current_proxy(self): def get_current_proxy(self):
return self.mnuPulldown.get_active_text() return self.mnuPulldown.get_active_text()
@ -80,9 +67,7 @@ class Scallywag:
self.status( str.format( "Changed PirateBay proxy site to {0}", self.config.proxy ) ) self.status( str.format( "Changed PirateBay proxy site to {0}", self.config.proxy ) )
def get_results(self, search_terms): def get_results(self, search_terms):
self.searcher = searcher.Scraper( self.config ) self.searcher = searcher.Scraper( self.config )
results = self.searcher.get_results( search_terms ) results = self.searcher.get_results( search_terms )
@ -95,11 +80,10 @@ class Scallywag:
selection = self.results_tree_view.get_selection() selection = self.results_tree_view.get_selection()
(tm, ti) = selection.get_selected() (tm, ti) = selection.get_selected()
url = tm.get_value(ti, 5) url = tm.get_value(ti, 5)
# TODO scrape url for magnet link then pass to xdg-open
magnet = self.searcher.get_magnet( url ) magnet = self.searcher.get_magnet( url )
subprocess.call(["xdg-open", magnet]) subprocess.Popen( "xdg-open {0}".format(magnet), shell=True )
self.status("Opening Magnet with xdg-open...") self.status("Opening Magnet with xdg-open...")
@ -149,7 +133,6 @@ class Scallywag:
self.window.show_all() self.window.show_all()
if __name__ == "__main__": if __name__ == "__main__":
main = Scallywag("config.ini") main = Scallywag("config.ini")

View File

@ -33,13 +33,11 @@ class Scraper:
def craft_url(self, protocol, proxy, search_terms): def craft_url(self, protocol, proxy, search_terms):
# https://pirate.blue/s/?q=Raising+Arizona&category=0&page=0&orderby=99 # https://pirate.blue/s/?q=Raising+Arizona&category=0&page=0&orderby=99
f = { 'q': search_terms, 'category': 0, 'page': 0, 'orderby': 99 } f = { 'q': search_terms, 'category': 0, 'page': 0, 'orderby': 99 }
return str.format( "{0}://{1}/s/?{2}", protocol, proxy, urllib.parse.urlencode(f) ) url = str.format( "{0}://{1}/s/?{2}", protocol, proxy, urllib.parse.urlencode(f) )
print(url)
return url
def get_results(self, search_terms): def get_results(self, search_terms):
print("Fetching from")
print(self.config.proxy)
url = self.craft_url( "https", self.config.proxy, search_terms ) url = self.craft_url( "https", self.config.proxy, search_terms )
fetch_results = self.client.get( url ) fetch_results = self.client.get( url )
@ -76,7 +74,7 @@ class Scraper:
title = tr.xpath('td[2]/div[1]/a[1]/text()')[0] title = tr.xpath('td[2]/div[1]/a[1]/text()')[0]
seeders = tr.xpath('td[3]/text()')[0] seeders = tr.xpath('td[3]/text()')[0]
leechers = tr.xpath('td[4]/text()')[0] leechers = tr.xpath('td[4]/text()')[0]
author = tr.xpath('td[2]/font/a/text()')[0] author = tr.xpath('td[2]/font/a/text()')
size_unprocessed = tr.xpath('td[2]/font/text()')[0] size_unprocessed = tr.xpath('td[2]/font/text()')[0]
url = tr.xpath('td/div[@class="detName"]/a[@class="detLink"]/@href')[0] url = tr.xpath('td/div[@class="detName"]/a[@class="detLink"]/@href')[0]

View File

@ -1,211 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.4 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkWindow" id="winMain">
<property name="name">winMain</property>
<property name="can_focus">False</property>
<property name="default_width">500</property>
<property name="default_height">600</property>
<signal name="destroy" handler="on_winMain_destroy" swapped="no"/>
<child>
<object class="GtkBox" id="boxMain">
<property name="name">boxMain</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkSeparator">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkComboBoxText" id="mnuPulldown">
<property name="name">mnuPulldown</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">6</property>
<property name="margin_right">6</property>
<property name="margin_top">6</property>
<signal name="changed" handler="on_mnuPulldown_changed" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btnRefresh">
<property name="label">gtk-refresh</property>
<property name="name">btnRefresh</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="margin_right">6</property>
<property name="margin_top">6</property>
<property name="use_stock">True</property>
<property name="always_show_image">True</property>
<signal name="clicked" handler="on_btnRefresh_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkStatusbar" id="stsBar">
<property name="name">stsBar</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">10</property>
<property name="margin_right">10</property>
<property name="margin_start">10</property>
<property name="margin_end">10</property>
<property name="margin_top">6</property>
<property name="margin_bottom">6</property>
<property name="hexpand">True</property>
<property name="spacing">2</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkSeparator">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">6</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btnDownload">
<property name="label" translatable="yes">Open in Client</property>
<property name="name">btnDownload</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="on_btnDownload_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow" id="scwResults">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkViewport">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkTreeView" id="tvwResults">
<property name="name">tvwResults</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">5</property>
</packing>
</child>
<child>
<object class="GtkBox" id="boxSearch">
<property name="name">boxSearch</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkEntry" id="txtSearch">
<property name="name">txtSearch</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="has_focus">True</property>
<property name="is_focus">True</property>
<property name="has_default">True</property>
<property name="margin_left">6</property>
<property name="margin_right">6</property>
<property name="activates_default">True</property>
<signal name="activate" handler="on_btnSearch_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btnSearch">
<property name="label">gtk-find</property>
<property name="name">btnSearch</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="has_default">True</property>
<property name="receives_default">True</property>
<property name="margin_right">6</property>
<property name="use_stock">True</property>
<property name="always_show_image">True</property>
<signal name="clicked" handler="on_btnSearch_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">6</property>
</packing>
</child>
</object>
</child>
<child type="titlebar">
<object class="GtkSeparator">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
</child>
</object>
</interface>

View File

@ -1,80 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.4 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkWindow">
<property name="can_focus">False</property>
<property name="default_width">440</property>
<property name="default_height">250</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="lblLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Select a PirateBay Proxy</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkComboBox" id="mnuPulldown">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btnSelect">
<property name="label" translatable="yes">Select</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btnRefresh">
<property name="label" translatable="yes">Refresh</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
<child>
<placeholder/>
</child>
</object>
</interface>

View File

@ -1,210 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.4 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkWindow" id="winMain">
<property name="name">winMain</property>
<property name="can_focus">False</property>
<property name="default_width">500</property>
<property name="default_height">600</property>
<signal name="destroy" handler="on_winMain_destroy" swapped="no"/>
<child>
<object class="GtkBox" id="boxMain">
<property name="name">boxMain</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkSeparator">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkComboBoxText" id="mnuPulldown">
<property name="name">mnuPulldown</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">6</property>
<property name="margin_right">6</property>
<property name="margin_top">6</property>
<signal name="changed" handler="on_mnuPulldown_changed" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btnRefresh">
<property name="label">gtk-refresh</property>
<property name="name">btnRefresh</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="margin_right">6</property>
<property name="margin_top">6</property>
<property name="use_stock">True</property>
<property name="always_show_image">True</property>
<signal name="clicked" handler="on_btnRefresh_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkStatusbar" id="stsBar">
<property name="name">stsBar</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">10</property>
<property name="margin_right">10</property>
<property name="margin_start">10</property>
<property name="margin_end">10</property>
<property name="margin_top">6</property>
<property name="margin_bottom">6</property>
<property name="hexpand">True</property>
<property name="spacing">2</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkSeparator">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">6</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btnDownload">
<property name="label" translatable="yes">Open in Client</property>
<property name="name">btnDownload</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="on_btnDownload_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow" id="scwResults">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkViewport">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkTreeView" id="tvwResults">
<property name="name">tvwResults</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">5</property>
</packing>
</child>
<child>
<object class="GtkBox" id="boxSearch">
<property name="name">boxSearch</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkEntry" id="txtSearch">
<property name="name">txtSearch</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="is_focus">True</property>
<property name="has_default">True</property>
<property name="margin_left">6</property>
<property name="margin_right">6</property>
<property name="activates_default">True</property>
<signal name="activate" handler="on_btnSearch_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btnSearch">
<property name="label">gtk-find</property>
<property name="name">btnSearch</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="has_default">True</property>
<property name="receives_default">True</property>
<property name="margin_right">6</property>
<property name="use_stock">True</property>
<property name="always_show_image">True</property>
<signal name="clicked" handler="on_btnSearch_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">6</property>
</packing>
</child>
</object>
</child>
<child type="titlebar">
<object class="GtkSeparator">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
</child>
</object>
</interface>