[nvda-addons] Re: Working on a new addon, problems with some imports

  • From: Noelia <nrm1977@xxxxxxxxx>
  • To: nvda-addons@xxxxxxxxxxxxx
  • Date: Thu, 30 Jul 2015 11:39:50 +0200

Hi, I like your add-ons, though unfortunately now I'm not available for revision work, but imo you have good and creative ideas.
I don't kno if this can be useful for you. But in ReadFeeds add-on I had problems with imports and I could fix them with a "hack", adding this to xml2/__init__.py:


import globalPluginHandler

class GlobalPlugin(globalPluginHandler.GlobalPlugin):

"""Plugin class"""

You can compare your problems with ReadFeeds removing this code of the add-on, available in NVDA add-ons website.
Thanks.



El 30/07/2015 a las 11:26, Hrvoje Katić escribió:

Hi all,
I'm working on a new addon that will download youtube videos and save
them into chosen video or audio format automatically with a single
keystroke. It works as follows: You open a URL with a video, press
nvda+shift+y and ther URL will be autodetected and the download begins
automatically, so you can download while listening video with no need to
paste url or switch to another window.
To achieve this, I'm using youtube_dl which works both as a single app
and a Python module. I don't wanna run it as an app, because it'll
pop-up command prompt while downloading, and also I'll not be able to
catch exceptions that may eventually happen, so I'm running it as a
Python module. Unfortunately, youtube_dl uses some python modules not
included with NVDA by default, so I copied manually all required
external modules from python27/lib into a lib subfolder inside the
globalPlugin's folder, and I added this subfolder to the sys.path inside
the addon's __init__.py as follows:
PLUGIN_DIR = os.path.dirname(__file__)
sys.path.append(os.path.join(PLUGIN_DIR, "lib"))
import youtube_dl
del sys.path[-1]
This allowed youtube_dl to import all required modules including
urllib2, json and others, but the problem begins when it comes to import
xml.etree.ElementTree. Here's what I get when i open log viewer:
ERROR - globalPluginHandler.listPlugins (11:06:50):
Error importing global plugin youtube
Traceback (most recent call last):
File "globalPluginHandler.pyc", line 22, in listPlugins
File
"C:\Users\pc3\AppData\Roaming\nvda\addons\Youtube\globalPlugins\youtube\__init__.py",
line 31, in <module>
File
"C:\Users\pc3\AppData\Roaming\nvda\addons\Youtube\globalPlugins\youtube\youtube_dl\__init__.py",
line 16, in <module>
File
"C:\Users\pc3\AppData\Roaming\nvda\addons\Youtube\globalPlugins\youtube\youtube_dl\options.py",
line 8, in <module>
File
"C:\Users\pc3\AppData\Roaming\nvda\addons\Youtube\globalPlugins\youtube\youtube_dl\downloader\__init__.py",
line 3, in <module>
File
"C:\Users\pc3\AppData\Roaming\nvda\addons\Youtube\globalPlugins\youtube\youtube_dl\downloader\common.py",
line 9, in <module>
File
"C:\Users\pc3\AppData\Roaming\nvda\addons\Youtube\globalPlugins\youtube\youtube_dl\utils.py",
line 32, in <module>
ImportError: No module named etree.ElementTree
So, the utils.py submodule of youtube_dl cannot find xml.etree, although
I've double checked that xml folder is copied properly with all the
subfolders.
I tried to fix this in many ways, so I really have no more ideas on how
to get all external submodules imported properly when running the plugin.
Thanks for any help!

----------------------------------------------------------------
NVDA add-ons: A list to discuss add-on code enhancements and for reporting bugs.
Community addons are available from: http://addons.nvda-project.org
To send a message to the list: nvda-addons@xxxxxxxxxxxxx
To change your list settings/unsubscribe:
//www.freelists.org/list/nvda-addons
To contact list moderators: nvda-addons-moderators@xxxxxxxxxxxxx

Other related posts: