Beispiel #1
0
    def test_bookmark():
        mock_sys = mock.MagicMock()
        mock_sys.listitem.getPath.return_value = \
            'plugin://plugin.googledrive/?item_id=18cvS&driveid=10773&item_driveid=000753&action=play&content_type=video'

        with patch('bookmark.sys', mock_sys):
            with patch('bookmark.KodiDB', FakeKodiDB):
                bookmark = Bookmark()

        mock_sys.listitem.getPath.return_value = '/path/to/video'
        with patch('bookmark.sys', mock_sys):
            with patch('bookmark.KodiDB', FakeKodiDB):
                bookmark = Bookmark()
def extract_dt_data(dt):
    """Function to extract data from dt tag.
    
    The html is structure such that a dt tag will either contain an a tag or a h3 tag and dl tag.
    """

    for child in dt:

        if child.name == 'a':

            temp_bookmark = {
                'name': child.text,
                'url': child.get('href'),
                'icon': child.get('icon')
            }

            data = Bookmark(**temp_bookmark)

        elif child.name == 'h3':

            data = {}
            header = child.text
            data[header] = []

        elif child.name == 'dl':

            data[header] = child

    return data
Beispiel #3
0
    def scheduler_bookmark(self, limit=BOOKMARK_CYCLE):
        """
		收藏作品
		"""
        b = Bookmark()
        while True:
            b.run()
            time.sleep(BOOKMARK_CYCLE)
Beispiel #4
0
 def _generate_bookmarks(cursor):
     bookmarks = []
     for row in cursor:
         bookmarks.append(
             Bookmark(title=row[0],
                      url=row[1],
                      identifier=row[2],
                      date=row[3]))
     return bookmarks
Beispiel #5
0
    def test_save_positions():
        mock_sys = mock.MagicMock()
        item_path = '/path/to/video'

        with patch('bookmark.sys', mock_sys):
            with patch('bookmark.KodiDB', FakeKodiDB):
                with patch('bookmark.Bookmark._get_save_dir',
                           return_value='/tmp'):
                    bookmark = Bookmark(item_path)
                    bookmark.save_positions()
Beispiel #6
0
    def test_import_bookmark_from_plot():
        mock_sys = mock.MagicMock()
        mock_sys.listitem.getVideoInfoTag.return_value.getPlot.return_value = '[30, 10]'
        item_path = '/path/to/video'

        with patch('bookmark.sys', mock_sys):
            with patch('bookmark.KodiDB', FakeKodiDB):
                with patch('bookmark.Bookmark._get_save_dir',
                           return_value='/tmp'):
                    bookmark = Bookmark(item_path)
                    bookmark.import_bookmark_from_plot()
Beispiel #7
0
 def parseLSSharedFileListPlist(self, mru_file):
     plist = self.load_bplist(mru_file)
     if plist == None:
         return []
     bookmarks = []
     try:
         for n,item in enumerate(plist["RecentDocuments"]["CustomListItems"]):
             bookmarks.append(Bookmark(data=item["Bookmark"]).parse())
     except Exception as e:
         pass
     return bookmarks
Beispiel #8
0
    def test_save_thumbnails_none_plot():
        mock_sys = mock.MagicMock()
        mock_sys.listitem.getVideoInfoTag.return_value.getPlot.return_value = None
        item_path = '/path/to/video'

        with patch('bookmark.sys', mock_sys):
            with patch('bookmark.KodiDB', FakeKodiDB):
                with patch('bookmark.Bookmark._get_save_dir',
                           return_value='/tmp'):
                    bookmark = Bookmark(item_path)
                    bookmark.save_thumbnails()
Beispiel #9
0
    def test_add_position():
        item_path = '/path/to/video'
        thumb = '/home/kodi/.kodi/temp/A-thumb-120.jpg'
        position = 120

        with patch('bookmark.KodiDB', FakeKodiDB):
            with patch('bookmark.Bookmark.add_position',
                       return_value=None) as pmock:
                bookmark = Bookmark(item_path)
                bookmark.add_position(position, thumb)
                pmock.assert_called_once()
Beispiel #10
0
    def test_save_positions_without_initial_folder():
        mock_sys = mock.MagicMock()
        item_path = "plugin://path/to/video"
        save_folder = '/path/to/save'

        with patch('bookmark.sys', mock_sys):
            with patch('bookmark.KodiDB', FakeKodiDB):
                with patch('setting.Setting.get_addon_setting',
                           return_value=None) as mock_fun:
                    bookmark = Bookmark(item_path)
                    bookmark.save_positions()
                    mock_fun.assert_called_once()
Beispiel #11
0
 def parseSFL(self, mru_file):
     plist_objects = self.load_plist_objects(mru_file)
     if plist_objects == None:
         return []
     bookmarks = []
     try:
         if plist_objects["root"]["NS.keys"][2] == "items":
             items = plist_objects["root"]["NS.objects"][2]["NS.objects"] 
             for n,item in enumerate(items):
                 if "LSSharedFileList.RecentHosts" not in mru_file:
                     bookmarks.append(Bookmark(data=item["bookmark"]).parse())
     except Exception as e:
         pass
     return bookmarks
Beispiel #12
0
def run():
    """
    Main
    """
    if len(sys.argv) > 2 and sys.argv[1] == '-r':
        Bookmark.select(sys.argv[2]).delete()
    elif len(sys.argv) > 2 and Bookmark.select(sys.argv[1]) is None:
        Bookmark(sys.argv[1], sys.argv[2]).persist()
    else:
        bookmark = Bookmark.select(sys.argv[1])
        if bookmark is not None:
            call([NEW_TAB_COMMAND, bookmark.link])
        else:
            print('No bookmark ' + sys.argv[1])
Beispiel #13
0
 def parseRecentItemsPlist(self, mru_file):
     plist = self.load_bplist(mru_file)
     if plist == None:
         return []
     bookmarks = []
     aliases = []
     try:
         for n,item in enumerate(plist["RecentApplications"]["CustomListItems"]):
             bookmarks.append(Bookmark(data=item["Bookmark"]).parse())
     except:
         pass
     try:
         for n,item in enumerate(plist["RecentDocuments"]["CustomListItems"]):
             bookmarks.append(Bookmark(data=item["Bookmark"]).parse())
     except:
         pass
     try:
         for n,item in enumerate(plist["RecentServers"]["CustomListItems"]):
             bookmarks.append(Bookmark(data=item["Bookmark"]).parse())
     except:
         pass
     try:
         for n,item in enumerate(plist["Applications"]["CustomListItems"]):
             aliases.append(Alias(data=item["Alias"]).parse())
     except:
         pass
     try:
         for n,item in enumerate(plist["Documents"]["CustomListItems"]):
             aliases.append(Alias(data=item["Alias"]).parse())
     except:
         pass
     try:
         for n,item in enumerate(plist["Servers"]["CustomListItems"]):
             aliases.append(Alias(data=item["Alias"]).parse())
     except:
         pass
     return bookmarks, aliases
Beispiel #14
0
 def parseSFL2(self, mru_file):
     plist_objects = self.load_plist_objects(mru_file)
     if plist_objects == None:
         return []
     bookmarks = []
     try:
         if plist_objects["root"]["NS.keys"][0] == "items":
             items = plist_objects["root"]["NS.objects"][0]["NS.objects"] 
             for n,item in enumerate(items):
                 attribute_keys = plist_objects["root"]["NS.objects"][0]["NS.objects"][n]["NS.keys"]
                 attribute_values = plist_objects["root"]["NS.objects"][0]["NS.objects"][n]["NS.objects"]
                 attributes = dict(zip(attribute_keys,attribute_values))
                 if "LSSharedFileList.RecentHosts" not in mru_file:
                     bookmarks.append(Bookmark(data=attributes["Bookmark"]).parse())
     except Exception as e:
         pass
     return bookmarks
Beispiel #15
0
 def parseMSOffice2016Plist(self, mru_file):
     bookmarks = []
     try:
         plistfile = plistlib.readPlist(mru_file)
         for n,item in enumerate(plistfile):
             try:
                 bookmarkdata = plistfile[item]["kBookmarkDataKey"]
                 for attr, blob in bookmarkdata.__dict__.iteritems():
                     try:
                         bookmarks.append(Bookmark(data=blob).parse())
                     except:
                         pass
             except:
                 pass
     except:
         pass
     return bookmarks
Beispiel #16
0
 def parseFinderPlist(self, mru_file):
     plist = self.load_bplist(mru_file)
     if plist == None:
         return []
     bookmarks = []
     aliases = []
     try:
         for n,item in enumerate(plist["FXRecentFolders"]):
             try:
                 bookmarks.append(Bookmark(data=item["file-bookmark"]).parse())
             except:
                 pass
             try:
                 pass
                 aliases.append(Alias(data=item["file-data"]["_CFURLAliasData"]).parse())
             except:
                 pass
     except:
         pass
     return bookmarks, aliases
Beispiel #17
0
from bookmark import Bookmark
from webpage import Webpage

bm = Bookmark('https://en.wikipedia.org/wiki/Futurama')
words = bm.get_words()
links = bm.get_links()

for link in links:
    bm = Bookmark(link)
    more_links = bm.get_links()
    if more_links:
        links.extend(more_links)
        print('__________________________________')
        print('  new links: ' + str(len(more_links)))
        print('total links: ' + str(len(links)))
        print('  avg links: ' + str(bm.link_avg()))
        print('  std links: ' + str(bm.link_std()))
    if len(links) > 1000: break

for link in links:
    bm = Bookmark(link)
    more_words = bm.get_words()
    if more_words:
        words.extend(more_words)
        print('__________________________________')
        print('  new words: ' + str(len(more_words)))
        print('total words: ' + str(len(words)))
        print('  avg words: ' + str(bm.word_avg()))
        print('  std words: ' + str(bm.word_std()))

bm.get_bow(words)
Beispiel #18
0
def validate_url(bc, url):
    b = Bookmark(url)
    if b.verify():
        print_bookmark(b)
    else:
        print('not able to validate')
Beispiel #19
0
def main():
    hatena_id = os.environ['HATENAID']
    bookmark = Bookmark(hatena_id)
    titles = bookmark.get_title()

    create_wordcloud(titles)
def main():
    bookmark = Bookmark()

    bookmark.import_bookmark_from_plot()
Beispiel #21
0
logger = log.get_logger('bkm-org', log_path=log_path)
collection_home = Path(config['bkm-org']['plain_home'])
default_collection_fpath = Path(config['bkm-org']['collection_fpath'])

ignore_categories = ['Bookmarks Menu', 'Bookmarks Toolbar', 'Mobile Bookmarks']

current_collection = BookmarkCollection(default_collection_fpath)

while True:
    receivedMessage = nm.getMessage()
    if receivedMessage:
        command = receivedMessage['command']
        if command == 'add-bookmark':
            created = utils.get_date_from_unix_timestamp(
                str(receivedMessage['created']))
            bookmark = Bookmark(receivedMessage['url'],
                                receivedMessage['title'], created)
            if 'categories' in receivedMessage:
                bookmark.categories = utils.get_category_hierarchy_str(
                    receivedMessage['categories'])
                bookmark.tags = [
                    utils.get_tag_from_category(c)
                    for c in receivedMessage['categories']
                    if c not in ignore_categories
                ]
            if 'tags' in receivedMessage and receivedMessage['tags']:
                bookmark.add_tags(receivedMessage['tags'].split(','))
            success = current_collection.add(bookmark)
            if success:
                nm.send("user-message",
                        f"added bookmark: {receivedMessage['url']}")
            continue
Beispiel #22
0
def import_gdrive_image(file_name, item_path):
    position = utils.retrieve_position_from_thumb(file_name)
    if position != 0:
        file = xbmc.translatePath('special://temp') + file_name
        bookmark = Bookmark(item_path)
        add_thumb(bookmark, file, position)
def main():
    bookmark = Bookmark()
    bookmark.save_positions()
    bookmark.save_thumbnails()