Пример #1
0
    def _get_torrent_from_infohash(self, infohash):
        dict = self._torrent_db.getTorrent(infohash, keys=['C.torrent_id', 'infohash', 'name', 'length', 'category', 'status', 'num_seeders', 'num_leechers'])
        if dict:
            t = Torrent(dict['C.torrent_id'], dict['infohash'], dict['name'], dict['length'], dict['category'], dict['status'], dict['num_seeders'], dict['num_leechers'], None)
            t.torrent_db = self._torrent_db
            t.channelcast_db = self._channelcast_db

            # prefetching channel, metadata
            _ = t.channel
            return t
Пример #2
0
                def create_torrent(a):
                    # channel = channels.get(a[-10], False)
                    # if channel and (channel.isFavorite() or channel.isMyChannel()):
                    #    t = ChannelTorrent(*a[:-12] + [channel, None])
                    # else:
                    t = Torrent(*a[:11] + [False])

                    t.torrent_db = self._torrent_db
                    t.channelcast_db = self._channelcast_db
                    t.assignRelevance(a[-11])
                    return t
Пример #3
0
    def _get_torrent_from_infohash(self, infohash):
        dict = self._torrent_db.getTorrent(infohash, keys=['C.torrent_id', 'infohash', 'name', 'length', 'category', 'status', 'num_seeders', 'num_leechers'])
        if dict:
            t = Torrent(dict['C.torrent_id'], dict['infohash'], dict['name'], dict['length'], dict['category'], dict['status'], dict['num_seeders'], dict['num_leechers'], None)
            t.torrent_db = self._torrent_db
            t.channelcast_db = self._channelcast_db
            # TODO: ENABLE metadata_db WHEN METADATA COMMUNITY IS ENABLED
            t.metadata_db = None  #self._metadata_db

            # prefetching channel, metadata
            _ = t.channel
            _ = t.metadata
            return t
Пример #4
0
    def _get_torrent_from_infohash(self, infohash):
        dict = self._torrent_db.getTorrent(infohash,
                                           keys=[
                                               'C.torrent_id', 'infohash',
                                               'name', 'length', 'category',
                                               'status', 'num_seeders',
                                               'num_leechers'
                                           ])
        if dict:
            t = Torrent(dict['C.torrent_id'], dict['infohash'], dict['name'],
                        dict['length'], dict['category'], dict['status'],
                        dict['num_seeders'], dict['num_leechers'], None)
            t.torrent_db = self._torrent_db
            t.channelcast_db = self._channelcast_db
            # TODO: ENABLE metadata_db WHEN METADATA COMMUNITY IS ENABLED
            t.metadata_db = None  #self._metadata_db

            # prefetching channel, metadata
            _ = t.channel
            _ = t.metadata
            return t
Пример #5
0
                def create_torrent(a):
                    #channel = channels.get(a[-10], False)
                    #if channel and (channel.isFavorite() or channel.isMyChannel()):
                    #    t = ChannelTorrent(*a[:-12] + [channel, None])
                    #else:
                    t = Torrent(*a[:11] + [False])

                    t.misc_db = self._misc_db
                    t.torrent_db = self._torrent_db
                    t.channelcast_db = self._channelcast_db
                    #t.metadata_db = self._metadata_db
                    t.assignRelevance(a[-11])
                    return t
Пример #6
0
    def __init__(self,
                 parent,
                 tdef,
                 defaultdir,
                 defaultname,
                 selectedFiles=None):
        self._logger = logging.getLogger(self.__class__.__name__)
        wx.Dialog.__init__(self,
                           parent,
                           -1,
                           'Please specify a target directory',
                           name="SaveAsDialog")

        self.guiutility = GUIUtility.getInstance()
        self.utility = self.guiutility.utility
        self.SetSize((600, 550))

        self.filehistory = []
        try:
            self.filehistory = json.loads(
                self.utility.read_config("recent_download_history",
                                         literal_eval=False))
        except:
            pass

        self.defaultdir = defaultdir
        self.listCtrl = None
        self.collected = tdef

        lastUsed = self.filehistory[0] if self.filehistory else defaultdir

        vSizer = wx.BoxSizer(wx.VERTICAL)

        if tdef:
            line = 'Please select a directory where to save:'
        else:
            line = 'Please select a directory where to save this torrent'

        firstLine = wx.StaticText(self, -1, line)
        _set_font(firstLine, fontweight=wx.FONTWEIGHT_BOLD)
        vSizer.Add(firstLine, 0, wx.EXPAND | wx.BOTTOM, 3)

        if tdef:
            torrentName = wx.StaticText(self, -1, tdef.get_name_as_unicode())
            torrentName.SetMinSize((1, -1))
            vSizer.Add(torrentName, 0, wx.EXPAND | wx.BOTTOM | wx.RIGHT, 3)

        hSizer = wx.BoxSizer(wx.HORIZONTAL)
        hSizer.Add(wx.StaticText(self, -1, 'Save as:'), 0,
                   wx.ALIGN_CENTER_VERTICAL | wx.RIGHT | wx.BOTTOM, 3)

        choices = copy.copy(self.filehistory)
        if defaultdir not in choices:
            choices.append(defaultdir)

        if defaultname:
            default_path = os.path.join(lastUsed, defaultname)
            choices.insert(0, default_path)
        else:
            default_path = lastUsed

        self.dirTextCtrl = wx.ComboBox(self,
                                       -1,
                                       default_path,
                                       choices=choices,
                                       style=wx.CB_DROPDOWN)
        self.dirTextCtrl.Select(0)

        hSizer.Add(self.dirTextCtrl, 1, wx.EXPAND | wx.RIGHT | wx.BOTTOM, 3)

        browseButton = wx.Button(self, -1, 'Browse')
        browseButton.Bind(wx.EVT_BUTTON, self.OnBrowseDir)
        hSizer.Add(browseButton)

        vSizer.Add(hSizer, 0, wx.EXPAND | wx.BOTTOM, 3)

        self.cancel = wx.Button(self, wx.ID_CANCEL)
        self.cancel.Bind(wx.EVT_BUTTON, self.OnCancel)

        self.ok = wx.Button(self, wx.ID_OK)
        self.ok.Bind(wx.EVT_BUTTON, self.OnOk)

        self.anonymity_dialog = None
        self.anonymity_dialog = AnonymityDialog(self)
        vSizer.Add(self.anonymity_dialog, 0, wx.EXPAND, 3)

        self.Bind(EVT_COLLECTED, self.OnCollected)

        # Add file list
        if tdef and tdef.get_files():
            self.AddFileList(tdef, selectedFiles, vSizer,
                             len(vSizer.GetChildren()))

        elif isinstance(tdef, TorrentDefNoMetainfo):
            text = wx.StaticText(self, -1,
                                 "Attempting to retrieve .torrent...")
            _set_font(text, size_increment=1)
            ag = wx.animate.GIFAnimationCtrl(
                self, -1,
                os.path.join(self.guiutility.utility.getPath(), LIBRARYNAME,
                             'Main', 'vwxGUI', 'images', 'search_new.gif'))
            ag.Play()
            sizer = wx.BoxSizer(wx.HORIZONTAL)
            sizer.AddStretchSpacer()
            sizer.Add(text, 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 10)
            sizer.Add(ag, 0, wx.ALIGN_CENTER_VERTICAL)
            sizer.AddStretchSpacer()
            vSizer.Add(sizer, 1, wx.EXPAND | wx.BOTTOM, 3)
            self.SetSize((600, 285))

            # convert tdef into guidbtuple, and collect it using torrentsearch_manager.downloadTorrentfileFromPeers
            torrent = Torrent.fromTorrentDef(tdef)
            torrentsearch_manager = self.guiutility.torrentsearch_manager

            def callback(saveas_id, infohash):
                saveas = wx.FindWindowById(saveas_id)
                if saveas:
                    tdef = TorrentDef.load_from_memory(
                        self.utility.session.lm.torrent_store.get(infohash))
                    event = CollectedEvent(tdef=tdef)
                    wx.PostEvent(saveas, event)

            cb = lambda torrent_filename, saveas_id=self.Id: callback(
                saveas_id, torrent_filename)
            torrentsearch_manager.downloadTorrentfileFromPeers(torrent, cb)

        bSizer = wx.StdDialogButtonSizer()
        bSizer.AddButton(self.cancel)
        bSizer.AddButton(self.ok)
        bSizer.Realize()
        vSizer.Add(bSizer, 0, wx.EXPAND | wx.BOTTOM, 3)

        sizer = wx.BoxSizer()
        sizer.Add(vSizer, 1, wx.EXPAND | wx.ALL, 10)
        self.SetSizer(sizer)
Пример #7
0
    def __init__(self, parent, tdef, defaultdir, defaultname, selectedFiles=None):
        self._logger = logging.getLogger(self.__class__.__name__)
        wx.Dialog.__init__(self, parent, -1, 'Please specify a target directory', name="SaveAsDialog")

        self.guiutility = GUIUtility.getInstance()
        self.utility = self.guiutility.utility
        self.SetSize((600, 550))

        self.filehistory = []
        try:
            self.filehistory = json.loads(self.utility.read_config("recent_download_history", literal_eval=False))
        except:
            pass

        self.defaultdir = defaultdir
        self.listCtrl = None
        self.collected = tdef

        lastUsed = self.filehistory[0] if self.filehistory else defaultdir

        vSizer = wx.BoxSizer(wx.VERTICAL)

        if tdef:
            line = 'Please select a directory where to save:'
        else:
            line = 'Please select a directory where to save this torrent'

        firstLine = wx.StaticText(self, -1, line)
        _set_font(firstLine, fontweight=wx.FONTWEIGHT_BOLD)
        vSizer.Add(firstLine, 0, wx.EXPAND | wx.BOTTOM, 3)

        if tdef:
            torrentName = wx.StaticText(self, -1, tdef.get_name_as_unicode())
            torrentName.SetMinSize((1, -1))
            vSizer.Add(torrentName, 0, wx.EXPAND | wx.BOTTOM | wx.RIGHT, 3)

        hSizer = wx.BoxSizer(wx.HORIZONTAL)
        hSizer.Add(wx.StaticText(self, -1, 'Save as:'), 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT | wx.BOTTOM, 3)

        choices = copy.copy(self.filehistory)
        if defaultdir not in choices:
            choices.append(defaultdir)

        if defaultname:
            default_path = os.path.join(lastUsed, defaultname)
            choices.insert(0, default_path)
        else:
            default_path = lastUsed

        self.dirTextCtrl = wx.ComboBox(self, -1, default_path, choices=choices, style=wx.CB_DROPDOWN)
        self.dirTextCtrl.Select(0)

        hSizer.Add(self.dirTextCtrl, 1, wx.EXPAND | wx.RIGHT | wx.BOTTOM, 3)

        browseButton = wx.Button(self, -1, 'Browse')
        browseButton.Bind(wx.EVT_BUTTON, self.OnBrowseDir)
        hSizer.Add(browseButton)

        vSizer.Add(hSizer, 0, wx.EXPAND | wx.BOTTOM, 3)

        self.cancel = wx.Button(self, wx.ID_CANCEL)
        self.cancel.Bind(wx.EVT_BUTTON, self.OnCancel)

        self.ok = wx.Button(self, wx.ID_OK)
        self.ok.Bind(wx.EVT_BUTTON, self.OnOk)

        self.anonymity_dialog = None
        self.anonymity_dialog = AnonymityDialog(self)
        vSizer.Add(self.anonymity_dialog, 0, wx.EXPAND, 3)

        self.Bind(EVT_COLLECTED, self.OnCollected)

        # Add file list
        if tdef and tdef.get_files():
            self.AddFileList(tdef, selectedFiles, vSizer, len(vSizer.GetChildren()))

        elif isinstance(tdef, TorrentDefNoMetainfo):
            text = wx.StaticText(self, -1, "Attempting to retrieve .torrent...")
            _set_font(text, size_increment=1)
            ag = wx.animate.GIFAnimationCtrl(self, -1, os.path.join(
                self.guiutility.utility.getPath(), LIBRARYNAME, 'Main', 'vwxGUI', 'images', 'search_new.gif'))
            ag.Play()
            sizer = wx.BoxSizer(wx.HORIZONTAL)
            sizer.AddStretchSpacer()
            sizer.Add(text, 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 10)
            sizer.Add(ag, 0, wx.ALIGN_CENTER_VERTICAL)
            sizer.AddStretchSpacer()
            vSizer.Add(sizer, 1, wx.EXPAND | wx.BOTTOM, 3)
            self.SetSize((600, 285))

            # convert tdef into guidbtuple, and collect it using torrentsearch_manager.downloadTorrentfileFromPeers
            torrent = Torrent.fromTorrentDef(tdef)
            torrentsearch_manager = self.guiutility.torrentsearch_manager

            def callback(saveas_id, infohash):
                saveas = wx.FindWindowById(saveas_id)
                if saveas:
                    tdef = TorrentDef.load_from_memory(self.utility.session.lm.torrent_store.get(infohash))
                    event = CollectedEvent(tdef=tdef)
                    wx.PostEvent(saveas, event)

            cb = lambda torrent_filename, saveas_id = self.Id: callback(saveas_id, torrent_filename)
            torrentsearch_manager.downloadTorrentfileFromPeers(torrent, cb)

        bSizer = wx.StdDialogButtonSizer()
        bSizer.AddButton(self.cancel)
        bSizer.AddButton(self.ok)
        bSizer.Realize()
        vSizer.Add(bSizer, 0, wx.EXPAND | wx.BOTTOM, 3)

        sizer = wx.BoxSizer()
        sizer.Add(vSizer, 1, wx.EXPAND | wx.ALL, 10)
        self.SetSizer(sizer)
Пример #8
0
    def _update(self):
        if len(self.torrents) >= self.max_torrents:
            return

        feed_elem = self.parsed_rss['feed']

        self.title = feed_elem['title']
        self.description = feed_elem['subtitle']

        torrent_keys = [
            'name', 'metainfo', 'creation_date', 'length', 'num_files',
            'num_seeders', 'num_leechers', 'enabled', 'last_seeding_stats'
        ]

        def __cb_body(body_bin, item_torrent_entry):
            tdef = None
            metainfo = None

            # tdef.get_infohash returned binary string by length 20
            try:
                metainfo = lt.bdecode(body_bin)
                tdef = TorrentDef.load_from_dict(metainfo)
                self.session.save_collected_torrent(tdef.get_infohash(),
                                                    body_bin)
            except ValueError, err:
                self._logger.error(
                    "Could not parse/save torrent, skipping %s. Reason: %s",
                    item_torrent_entry['link'], err.message +
                    ", metainfo is " + ("not " if metainfo else "") + "None")

            if tdef and len(self.torrents) < self.max_torrents:
                # Create a torrent dict.
                real_infohash = tdef.get_infohash()
                torrent_values = [
                    item_torrent_entry['title'], tdef,
                    tdef.get_creation_date(),
                    tdef.get_length(),
                    len(tdef.get_files()), -1, -1, self.enabled, {}
                ]

                # store the real infohash to generated infohash
                self.torrents[real_infohash] = dict(
                    zip(torrent_keys, torrent_values))
                self.fake_infohash_id[sha1(
                    item_torrent_entry['id']).digest()] = real_infohash

                # manually generate an ID and put this into DB
                self.torrent_db.addOrGetTorrentID(real_infohash)
                self.torrent_db.addExternalTorrent(tdef)

                # create Torrent object and store it
                self.torrent_mgr.load_torrent(Torrent.fromTorrentDef(tdef))

                # Notify the BoostingManager and provide the real infohash.
                if self.torrent_insert_callback:
                    self.torrent_insert_callback(self.source, real_infohash,
                                                 self.torrents[real_infohash])
            elif tdef:
                self._logger.debug(
                    "Max torrents in source reached. Not adding %s",
                    tdef.get_infohash())