-
Notifications
You must be signed in to change notification settings - Fork 2
/
__init__.py
88 lines (74 loc) · 2.85 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# -*- coding: utf-8 -*-
import wx
import gui
import os
import sys
import globalPluginHandler
from .import youtube_settinsgs
from .import youtube_renamer
import api
import textInfos
from ui import message
from subprocess import Popen, PIPE
import addonHandler
addonHandler.initTranslation()
class GlobalPlugin(globalPluginHandler.GlobalPlugin):
scriptCategory = _("youtubeDownloader")
#!#######################################################
# ? THE SCRIPT STARTS EXCUTING FROM HERE
#!#######################################################
def script_start(self, gesture):
"""
get the current selected text and pass it to "orignal_script.py" file
Its shortcut is "alt+control+y"
"""
obj = api.getFocusObject()
treeInterceptor = obj.treeInterceptor
if hasattr(treeInterceptor, 'TextInfo') and not treeInterceptor.passThrough:
obj = treeInterceptor
try:
info = obj.makeTextInfo(textInfos.POSITION_SELECTION)
except (RuntimeError, NotImplementedError):
info = None
if not info or info.isCollapsed:
# Translators: This message is spoken if there's no selection.
message(_("Nothing selected."))
else:
message(_("The Script Has Started."))
link = (info.text)
SCRIPT_PATH = os.path.dirname(os.path.abspath(__file__))
MAIN_DOWNLOADER_FOLDER = "main_youtube_downloader"
original_script = os.path.join(SCRIPT_PATH, MAIN_DOWNLOADER_FOLDER,
"original_script.py")
#! use the orignal python because NVDA doesn't understand "orignal_script.py" imports
python_path = os.path.join(SCRIPT_PATH, "python", "python.exe")
args = [python_path, original_script, link]
Popen(" ".join(args), shell=True) # download file
script_start.__doc__ = _('start download')
def script_youtube_downloader_settings(self, gesture):
"""
open settings menu
"""
d = youtube_settinsgs.YoutubeDownloderSettings(parent=gui.mainFrame)
gui.mainFrame.prePopup()
d.Raise()
d.Show()
gui.mainFrame.postPopup()
script_youtube_downloader_settings.__doc__ = _(
'open youtubedownloader settings')
def script_youtube_rename(self, gesture):
"""
open gui to select folder contaning the videos to rename
"""
d = youtube_renamer.YoutubeRenamer(parent=gui.mainFrame)
gui.mainFrame.prePopup()
d.Raise()
d.Show()
gui.mainFrame.postPopup()
self.terminate()
script_youtube_rename.__doc__ = _('youtube rename files')
__gestures = {
"kb:alt+control+y": "start",
"kb:alt+control+r": "youtube_rename",
"kb:alt+control+l": "youtube_downloader_settings",
}