113 Commits

Author SHA1 Message Date
7f2956e47a Exclude crypt32.dll from dist 2018-12-13 17:37:13 -06:00
36a199946e Call setOnlyne every 4:40 instead of 15 minutes 2018-12-13 17:16:56 -06:00
d79f29d237 Update URL in app info 2018-12-13 17:14:14 -06:00
0d440fafa7 Minor changes 2018-12-13 16:49:30 -06:00
353a487ded fixed some issue when building a distributable file 2018-12-13 16:36:46 -06:00
a0c4ad6af4 Reads incoming chat message if the current buffer is the buffer receiving the message 2018-12-13 12:05:48 -06:00
f16576c03c Added voice messages to the list of supported attached files in chats 2018-12-13 11:48:17 -06:00
0144a5787a Reconnects the ongpoll chat server after a ReadTimeout or ConnectionError 2018-12-12 13:41:57 -06:00
ed624f5bf1 Plays a different sound when a conversation has been created 2018-12-12 12:38:01 -06:00
2699feada5 Added 'custom' notifications for chat settings 2018-12-12 12:24:05 -06:00
1affb38cd5 Replaced message_received.ogg 2018-12-12 12:23:27 -06:00
2feb5bc6ff Reverted experiment. Not working 2018-12-12 08:08:07 -06:00
2f175f5529 Added an experiment (stage 1 of 3) 2018-12-12 05:49:28 -06:00
cf4971a6c4 Started recovering the search function 2018-12-11 18:02:49 -06:00
65e253a538 Avoids trying to send a blank chat message to VK 2018-12-11 12:17:08 -06:00
5f010b68af Removed support for audio albm delete as is not supported by vk_api 2018-12-11 12:08:56 -06:00
e04d098527 Removed audio album creation as it is not supported by vk_api 2018-12-11 12:07:18 -06:00
24b5e279db Added audio albums (still not working) 2018-12-11 12:04:04 -06:00
26f4c0bcff Removed count_for_audio_buffers from config settings controller 2018-12-11 11:49:26 -06:00
b82c94bf51 Added chat settings in the config dialog 2018-12-11 11:45:38 -06:00
6f9a5ce8d2 Chat messages should be able to be send with enter in the edit box 2018-12-11 09:26:14 -06:00
e0eb0eefce Handled deleted comments properly in wall posts 2018-12-11 09:04:57 -06:00
641921537b Added 'keep as follower' for friendship requests (needs testing) 2018-12-10 17:52:01 -06:00
52f892f35f Added accepting/declining friend requests from friendship request folder by using the menu key or right mouse click 2018-12-10 17:35:36 -06:00
15e4c19f04 Removed unneeded comments 2018-12-10 14:54:54 -06:00
cca89f9260 Call to account.setOffline when closing the app to notify everyone about it 2018-12-10 13:25:30 -06:00
bbee451f2c Added support for description in photo uploading 2018-12-10 12:20:01 -06:00
51f7daba6c Updated links for readme file 2018-12-10 09:36:52 -06:00
7fa35f18e4 Clear attachments list when switching to a new message in chats 2018-12-10 02:32:57 -06:00
217765254d Updated changelog 2018-12-10 00:49:01 -06:00
c747be2743 Shows a notification when someone is onlyne or offline 2018-12-10 00:48:40 -06:00
2d60e2b461 Call to get_my_data after logging in VK 2018-12-10 00:47:25 -06:00
69cd540329 Removed count for audio buffers in config GUI 2018-12-10 00:45:56 -06:00
ad57be052e Removed audio count for buffers in config 2018-12-10 00:03:08 -06:00
5cded5f27c Updated code for the new deletion of methods in vk sessions 2018-12-09 21:41:09 -06:00
39d1663fa1 Removed login with tokens only due to vk_api login requirements 2018-12-09 21:40:25 -06:00
6ddea35dec Fixed a typo 2018-12-09 12:43:56 -06:00
f3e8a3024f generate random_id with randint 2018-12-09 11:26:21 -06:00
7d35facdaf Generate random_id as integer value 2018-12-09 10:53:50 -06:00
7ba24f7a54 Removed some unneeded code 2018-12-09 07:28:13 -06:00
feb3215745 Use methods provided in vk_api for supporting conversations 2018-12-09 07:25:30 -06:00
ba5d734a05 Restored access to audios by users 2018-12-09 05:22:37 -06:00
bb26d45f1d Replaced VK with vk_api 2018-12-09 05:21:52 -06:00
1a79e7149c Updated requirements 2018-12-09 05:20:35 -06:00
4bdd2b3894 Fixed issues related to sound unable to be played 2018-12-07 17:53:55 -06:00
5d804b2d8e Display audio attachments in chat messages properly 2018-12-06 17:56:22 -06:00
4a83edf3bc Adapted some files to changes present in renderers 2018-12-06 17:34:48 -06:00
d0de4ac677 Removed sound_lib and platform_utils and install them as external deps 2018-12-06 15:57:13 -06:00
49530b8d0c Separated rendering functions from the rest of the code 2018-12-06 15:37:16 -06:00
3aa5a27268 Updated changelog again 2018-12-05 17:34:25 -06:00
88518338f1 Updated changelog 2018-12-05 15:59:55 -06:00
965f14e249 Change date formatting for chat messages 2018-12-05 15:56:23 -06:00
c91e04b4d8 Re-enable audio playback (works with audios transferred in chats) 2018-12-05 15:55:24 -06:00
8fa8267e04 Added some comments in important parts in chat buffer 2018-12-05 15:54:24 -06:00
73fa9532b5 Improved chats focusing. Now they should work properly 2018-12-05 12:43:33 -06:00
04102677f2 Added first experiment on focus mode for chat history 2018-12-04 17:53:10 -06:00
331636b9f4 Refactored chat widget to be more manageable for screen readers. Needs improvements 2018-12-04 16:58:40 -06:00
8c1d9c3fe2 Updated readme 2018-12-03 16:49:14 -06:00
c655e23cb3 Replaced libloader and accessible_output2 for modules retrieved in requirements file 2018-12-03 15:56:57 -06:00
26b78eecf6 Added more comments 2018-12-03 15:55:55 -06:00
08484d9807 Added call to trackVisitor for helping with app statistics 2018-11-05 10:04:02 -06:00
13b19fec75 Added docstrings to attachment controllers and deprecated the previously audio attacher 2018-11-05 09:37:40 -06:00
6fb70a5b32 Added docstrings to profile viewer 2018-11-05 09:11:20 -06:00
317aea7492 Updated changelog 2018-11-04 02:18:58 -06:00
0936ae6fb6 Chats with more than 200 messages will be displayed properly 2018-11-04 01:39:06 -06:00
6bf29a45db Fixed arrow formatter when dealing with profile birthdates 2018-10-14 08:13:12 -05:00
b00668e758 Added option to open authenticated user's profile in browser 2018-09-06 13:07:55 -05:00
6941f26e97 When visiting an user's 'website', handles case where there are multiple sites listed. #7 2018-09-06 12:34:08 -05:00
71a15a24bc Mae profile viewer a tabbed window. Added photo to the dialog. Separated profile code from other post types 2018-09-06 10:47:10 -05:00
964ff00520 Fixed strange issue with chat messages 2018-09-03 13:55:27 -05:00
856b2527e3 Replaced AppendItem for Append in context menus 2018-09-03 13:22:54 -05:00
92158f2496 Replaced old translator by the new yandex powered translator 2018-09-03 10:24:59 -05:00
2a5a184662 Stopped using deprecated objects when Loading images due to WX 4 2018-09-03 10:00:23 -05:00
d45bfb0eeb Started using VK API V 5.84 2018-09-03 09:43:33 -05:00
314a615b68 Commented issue #11 2018-09-03 09:18:32 -05:00
e77276ae52 Fixed error when getting VK API error 5. Closes #11 2018-09-03 09:15:52 -05:00
72348008a2 More WX Python 4 changes 2018-09-03 08:33:05 -05:00
3e43f67ee2 Updated contributors list 2018-09-02 08:42:37 -05:00
d1fd6d1861 Removed VK module from repo. Install it via pip. Custom modules has been moved to mysc 2018-09-02 08:38:49 -05:00
c7743fccb9 Updated GUI regarding WX 4.0.3 2018-09-02 07:57:21 -05:00
ee75c6a53d Moved some dependencies to PIP. Updated Python to 2.7.15 and WX to 4.0.3 2018-09-02 07:50:00 -05:00
fc637e553c Updated WidgetUtils for WXPython 4 2018-09-02 07:33:09 -05:00
fc76b3929b Added comments to buffers.py 2018-01-14 14:55:53 -06:00
0e83c7368d Updated author information 2018-01-14 07:22:54 -06:00
0b8e1a1a0d Switched to VK API V 5.69 2018-01-14 07:18:00 -06:00
6d6a801a01 Removed unneeded prints 2018-01-14 06:58:24 -06:00
ba2ba9bc58 Removed audio elements in menus and main window 2017-09-26 05:19:30 -05:00
268138d726 Changed author information 2017-05-12 12:16:07 +04:00
7fe615a7ee Merge branch 'master' of manuelcortez.net:manuelcortez/socializer 2017-05-12 12:07:52 +04:00
d4fa723155 Disabled audio playback 2017-05-12 12:06:53 +04:00
ae5ec93b53 Added some changes 2017-04-30 16:09:11 -05:00
ead1f186f0 Update API version 2017-03-13 02:16:34 -06:00
2c6704ae9e Updated readme 2016-12-10 07:13:58 -06:00
e2a2758f6d Added support for playing voice messages in VK 2016-09-25 14:24:40 -05:00
3973b57413 Added relationship status, occupation, last seen and website to profile viewer #7 2016-09-21 13:59:31 -05:00
f1ce4b834a Enabled view profile option in the menu for items in people buffers 2016-09-21 13:54:52 -05:00
69346bfaa1 Added a very basic user profile viewer #7 2016-09-20 10:36:17 -05:00
9df49c354b Player object will not be unusable after an error 2016-09-19 17:13:40 -05:00
444d506359 Keep loading other buffers if a section cannot be loaded 2016-09-15 15:27:38 -05:00
65815113d5 Updated changelog 2016-09-05 13:15:13 -05:00
53196b5dda Fixed a bug in the user selection dialog 2016-09-05 13:13:45 -05:00
03f73564da Tag people in posts and comments. Closes #6 2016-08-19 04:25:49 -05:00
9fd845c424 Added a setting for load (or not) images in posts. Closes #9 2016-08-17 17:18:17 -05:00
f079907a9e Parse replies in comments. Start changes for #1 2016-08-17 16:25:01 -05:00
ee308fb5aa Added video search 2016-08-15 17:00:49 -05:00
4900b67882 My videos, album management, add/remove to video albums 2016-08-14 07:46:41 -05:00
4ae167e461 Chats can be sent by pressing enter in the text box 2016-08-14 02:12:49 -05:00
4491a600f3 Fixed problem with false positives in error 6: Too many requests per second 2016-08-13 20:12:18 -05:00
c8927e0b60 Using VK API Version 5.53 2016-08-13 19:50:27 -05:00
50355abdda Added pauses between calls to vk.audio.get in when loading albums 2016-08-10 17:37:36 -05:00
f190b7651e Added an experimental photo viewer in posts dialog 2016-08-10 12:58:11 -05:00
38c394581c Added friendship requests buffers inside the people buffer 2016-08-02 10:38:10 -05:00
00d7cf48af Added audio player menu in menu bar 2016-07-18 17:34:37 -05:00
173 changed files with 2223 additions and 6004 deletions

View File

@@ -1,43 +1,38 @@
# socializer
> Note: this project has two different main repositories. [Here is the official repository, hosted in my Gitlab Instance,](https://code.manuelcortez.net/manuelcortez/socializer) [Here is a mirror repository hosted in GitHub.](https://github.com/manuelcortez/socializer) Github repository will accept pull requests and issues reported by github users, while Gitlab's repository will provide the wiki, documentation, and support for user reported issues.
A desktop application for handling [vk.com](http://vk.com) in an easy way.
## weekly builds
## download the current build
Socializer's functionality is far to be perfect, in fact there are lots of methods of the VK API that this application doesn't support right now, but if you are curious enough, and you want to help by giving me your impressions and making tests for fixing bugs, you can download the last source code, compiled as an application. This is the weekly build of socializer. This version is only for testing purposes, never think that it can be used for everyday use. This version does not include any documentation, Only the changelog, because it's build with an authomatic process. This weekly build is built every week, depending in the updates that the repository has receibed.
Socializer's functionality is far to be perfect, in fact there are lots of methods of the VK API that this application doesn't support right now, but if you are curious enough, and you want to help by giving me your impressions and making tests for fixing bugs, you can download the last source code, compiled as an application. This is the snapshot build of socializer. This version is only for testing purposes, never think that it can be used for everyday use. This version does not include any documentation, Only the changelog, because it's build with an authomatic process.
Before downloading, take in to account the following: This source code is completely experimental. The current functionality in this application is not very useful. If you decide to use nightly build versions, take into account that this doesn't work as an application for everyday use yet.
Version: 2016.07.9
Build date: Jul 9 2016
[Download socializer weekly build](https://github.com/manuelcortez/socializer/blob/master/nightly/socializer-nightly-build.zip?raw=true)
[Download socializer](https://github.com/manuelcortez/socializer/blob/master/nightly/socializer-nightly-build.zip?raw=true)
I have started this effort as an open source project on Feb 13, 2016. Pull requests and bug reports are welcome. Socializer is not a definitive name for this project, it could be changed in future.
I have started this effort as an open source project on Feb 13, 2016. Pull requests and bug reports are welcome.
## dependencies
## dependencies not installed by PIP
* [Python,](http://python.org) version 2.7.11
* [wxPython](http://www.wxpython.org) for Python 2.7, version 3.0.2.0
* [Python windows extensions (pywin32)](http://www.sourceforge.net/projects/pywin32/) for python 2.7, build 220
For other dependencies, do pip install --upgrade -r requirements.txt
* [Python,](http://python.org) version 2.7.15
* [PyEnchant,](http://pythonhosted.org/pyenchant/) version 1.6.6.
* [VK API bindings for Python](https://github.com/dimka665/vk) (already included in the SRC directory)
* pypubsub
* configobj
* requests-oauthlib
* future
* arrow==0.6
* microsofttranslator
* [Pandoc](http://pandoc.org/installing.html) for generating the changelog.
## Documentation
I am trying to write an updated manual for socializer. It can be found in the documentation folder once the program zip file is uncompressed, or in the manual.md file (in markdown). The idea of this manual is to be updated as socializer receives new features or improvements.
A copy of the English version of the manual can be read here: [Manual in the socializer's wiki](https://github.com/manuelcortez/socializer/wiki/manual)
A copy of the English version of the manual can be read here: [Manual in the socializer's wiki](https://code.manuelcortez.net/manuelcortez/socializer/wikis/manual)
## Contributing
If you are interested in this project, you can help it by [translating this program](https://github.com/manuelcortez/socializer/wiki/translate) into your native language and give more people the possibility of using it. Thank you in advance!
If you are interested in this project, you can help it by [translating this program](https://code.manuelcortez.net/manuelcortez/socializer/wikis/translate) into your native language and give more people the possibility of using it. Thank you in advance!
## contact

View File

@@ -1,6 +1,21 @@
% Changelog
# Changelog
## Changes for the current build (08/07/2016)
## Changes in the current build ()
* Added two more buffers: "Followers" and "I follow", located in the people buffer, under "friendship requests".
* Added an experimental photo viewer. Will show options for displaying the next and previous photo if the current post contains multiple images. Fullscreen button still doesn't work.
* Improved chats, now they should be more stable. Also you will be able to send the message by pressing enter in the text box. If you are trying to send the same message multiple times, you will be warned.
* Added video management (my videos, video albums and video search). For playing videos, you will be redirected to a website in your browser due to the VK'S policy.
* Added a setting that allows you to specify if you want socializer to load images when you are opening posts. It could be useful for slow connections or those who don't want images to be loaded.
* Added basic tagging for users in posts and comments. You can tag only people in your friends buffer.
* Added a basic user profile viewer.
* Added support for listening voice messages in chats. Currently it is not possible to send them, until the new API will be released.
* Fixed an error that was making Socializer unable to display chat history properly. It was showing the first 200 items in a conversation instead the last 200 items. Now chat will be displayed accordingly.
* Changed the chat history widget from list of items to a read only text box, similar to how it was displayed in skype. Now the widget should be fully visible and messages will work in the same way.
* It is possible to play songs sent in a chat message by opening them from the attachments panel.
* Reimplemented most of the audio playback methods.
## Changes in build 2016.07.08 (08/07/2016)
* Removed platform from "last seen" column in the friends list as it could cause some problems and it was being not so exact.
* Now deleted audios are not parsed and displayed as "audio removed from library". They are silently ignored.

View File

@@ -1,2 +1,2 @@
Manuel E. Cortéz
Manuel Cortéz
Valeria K

View File

@@ -11,4 +11,5 @@ def create_archive():
shutil.make_archive("socializer-nightly-build", "zip", "socializer")
shutil.rmtree("socializer")
create_build()
create_archive()

14
requirements.txt Normal file
View File

@@ -0,0 +1,14 @@
wxpython
pywin32
vk_api
configobj
pypubsub==3.3.0
requests-oauthlib
future
arrow
yandex.translate
# forked repositories previously found at http://q-continuum.net
git+https://code.manuelcortez.net/manuelcortez/libloader
git+https://code.manuelcortez.net/manuelcortez/platform_utils
git+https://github.com/chrisnorman7/sound_lib
git+https://code.manuelcortez.net/manuelcortez/accessible_output2

View File

@@ -1,33 +0,0 @@
from __future__ import absolute_import
import ctypes
import os
import types
from platform_utils import paths
def load_library(libname, cdll=False):
if paths.is_frozen():
libfile = os.path.join(paths.embedded_data_path(), 'accessible_output2', 'lib', libname)
else:
libfile = os.path.join(paths.module_path(), 'lib', libname)
if cdll:
return ctypes.cdll[libfile]
else:
return ctypes.windll[libfile]
def get_output_classes():
from . import outputs
module_type = types.ModuleType
classes = [m.output_class for m in outputs.__dict__.values() if type(m) == module_type and hasattr(m, 'output_class')]
return sorted(classes, key=lambda c: c.priority)
def find_datafiles():
import os
import platform
from glob import glob
import accessible_output2
if platform.system() != 'Windows':
return []
path = os.path.join(accessible_output2.__path__[0], 'lib', '*.dll')
results = glob(path)
dest_dir = os.path.join('accessible_output2', 'lib')
return [(dest_dir, results)]

View File

@@ -1,20 +0,0 @@
from __future__ import absolute_import
import platform
if platform.system() == 'Windows':
from . import nvda
from . import jaws
from . import sapi5
from . import window_eyes
from . import system_access
from . import dolphin
from . import pc_talker
#import sapi4
if platform.system() == 'Darwin':
from . import voiceover
from . import say
if platform.system() == 'Linux':
from . import e_speak
from . import auto

View File

@@ -1,40 +0,0 @@
from __future__ import absolute_import
import accessible_output2
from .base import Output, OutputError
class Auto(Output):
def __init__(self):
output_classes = accessible_output2.get_output_classes()
self.outputs = []
for output in output_classes:
try:
self.outputs.append(output())
except OutputError:
pass
def get_first_available_output(self):
for output in self.outputs:
if output.is_active():
return output
return None
def speak(self, *args, **kwargs):
output = self.get_first_available_output()
if output:
output.speak(*args, **kwargs)
def braille(self, *args, **kwargs):
output = self.get_first_available_output()
if output:
output.braille(*args, **kwargs)
def output(self, *args, **kwargs):
output = self.get_first_available_output()
if output:
output.speak(*args, **kwargs)
def is_system_output(self):
output = self.get_first_available_output()
if output:
return output.is_system_output()

View File

@@ -1,47 +0,0 @@
from accessible_output2 import load_library
import platform
class OutputError(Exception):
pass
class Output(object):
name = "Unnamed Output"
lib32 = None
lib64 = None
argtypes = {}
cdll = False
priority = 100
system_output = False
def __init__(self):
self.is_32bit = platform.architecture()[0] == "32bit"
if self.lib32 and self.is_32bit:
self.lib = load_library(self.lib32, cdll=self.cdll)
elif self.lib64:
self.lib = load_library(self.lib64, cdll=self.cdll)
else:
self.lib = None
if self.lib is not None:
for func in self.argtypes:
try:
getattr(self.lib, func).argtypes = self.argtypes[func]
except AttributeError:
pass
def output(self, text, **options):
output = False
if self.speak(text, **options):
output = True
if self.braille(text, **options):
output = True
if not output:
raise RuntimeError("Output %r does not have any method defined to output" % self)
def is_system_output(self):
return self.system_output
def speak(self, **optiont):
return False
def braille(self, *args, **options):
return False

View File

@@ -1,33 +0,0 @@
from __future__ import absolute_import
import os
import ctypes
from .base import Output
class Dolphin (Output):
"""Supports dolphin products."""
name = 'Dolphin'
lib32 = 'dolapi.dll'
argtypes = {
'DolAccess_Command': (ctypes.c_wchar_p, ctypes.c_int, ctypes.c_int),
'DolAccess_Action': (ctypes.c_int,),
}
def speak(self, text, interrupt=0):
if interrupt:
self.silence()
#If we don't call this, the API won't let us speak.
if self.is_active():
self.lib.DolAccess_Command(text, (len(text)*2)+2, 1)
def silence(self):
self.lib.DolAccess_Action(141)
def is_active(self):
try:
return self.lib.DolAccess_GetSystem() in (1, 4, 8)
except:
return False
output_class = Dolphin

View File

@@ -1,31 +0,0 @@
from __future__ import absolute_import
from .base import Output
try:
import espeak.core
except:
raise RuntimeError("Cannot find espeak.core. Please install python-espeak")
class ESpeak(Output):
"""Speech output supporting ESpeak on Linux
Note this requires python-espeak to be installed
This can be done on Debian distros by using apt-get install python-espeak
Or through this tarball: https://launchpad.net/python-espeak
"""
name = "Linux ESpeak"
def is_active(self):
try:
import espeak.core
except:
return False
return True
def speak(self, text, interrupt = 0):
if interrupt:
self.silence()
espeak.core.synth(text)
def silence(self):
espeak.core.cancel()
output_class = ESpeak

View File

@@ -1,34 +0,0 @@
from __future__ import absolute_import
import win32gui
from libloader.com import load_com
import pywintypes
from .base import Output, OutputError
class Jaws (Output):
"""Output supporting the Jaws for Windows screen reader."""
name = 'jaws'
def __init__(self, *args, **kwargs):
super (Jaws, self).__init__(*args, **kwargs)
try:
self.object = load_com("FreedomSci.JawsApi", "jfwapi")
except pywintypes.com_error:
raise OutputError
def braille(self, text, **options):
# HACK: replace " with ', Jaws doesn't seem to understand escaping them with \
text = text.replace('"', "'")
self.object.RunFunction("BrailleString(\"%s\")" % text)
def speak(self, text, interrupt=False):
self.object.SayString(' %s' % text, interrupt)
def is_active(self):
try:
return self.object.SayString('',0) == True or win32gui.FindWindow("JFWUI2", "JAWS") != 0
except:
return False
output_class = Jaws

View File

@@ -1,37 +0,0 @@
from __future__ import absolute_import
import os
import platform
import ctypes
from platform_utils import paths
from libloader import load_library
from .base import Output
class NVDA(Output):
"""Supports The NVDA screen reader"""
name = "NVDA"
lib32 = 'nvdaControllerClient32.dll'
lib64 = 'nvdaControllerClient64.dll'
argtypes = {
'nvdaController_brailleMessage': (ctypes.c_wchar_p,),
'nvdaController_speakText': (ctypes.c_wchar_p,),
}
def is_active(self):
try:
return self.lib.nvdaController_testIfRunning() == 0
except:
return False
def braille(self, text, **options):
self.lib.nvdaController_brailleMessage(text)
def speak(self, text, interrupt=False):
if interrupt:
self.silence()
self.lib.nvdaController_speakText(text)
def silence(self):
self.lib.nvdaController_cancelSpeech()
output_class = NVDA

View File

@@ -1,24 +0,0 @@
from __future__ import absolute_import
import ctypes
from .base import Output
class PCTalker(Output):
lib32 = 'pctkusr.dll'
lib64 = 'pctkusr64.dll'
cdll = True
argtypes = {
'PCTKPRead': (ctypes.c_char_p, ctypes.c_int, ctypes.c_int)
}
def speak(self, text, interrupt=False):
if interrupt:
self.silence()
self.lib.PCTKPRead(text.encode('cp932', 'replace'), 0, 1)
def silence(self):
self.lib.PCTKVReset()
def is_active(self):
return self.lib.PCTKStatus() != 0
output_class = PCTalker

View File

@@ -1,143 +0,0 @@
from __future__ import absolute_import
from builtins import range
from libloader.com import load_com
from .base import Output
import logging
log = logging.getLogger(__name__)
class Sapi4(Output):
name = 'sapi4'
priority = 102
def __init__(self):
sapi4 = load_com("{EEE78591-FE22-11D0-8BEF-0060081841DE}")
self._voiceNo = sapi4.Find(0)
sapi4.Select(self._voiceNo)
sapi4.Speak(" ")
self.__object = sapi4
self._voice_list = self._available_voices()
def _set_capabilities(self):
sapi4 = self.__object
try:
sapi4.Pitch = sapi4.Pitch
self._min_pitch = sapi4.MinPitch
self._max_pitch = sapi4.MaxPitch
self._has_pitch = True
except:
self._min_pitch = 0
self._max_pitch = 0
self._has_pitch = False
try:
sapi4.Speed = sapi4.Speed
self._min_rate = sapi4.MinSpeed
self._max_rate = sapi4.MaxSpeed
self._has_rate = True
except:
self._min_rate = 0
self._max_rate = 0
self._has_rate = False
try:
sapi4.VolumeLeft = sapi4.VolumeLeft
self._min_volume = sapi4.MinVolumeLeft
self._max_volume = sapi4.MaxVolumeLeft
self._has_volume = True
except:
self._min_volume = 0
self._max_volume = 0
self._has_volume = False
def _available_voices(self):
voice_list = []
for voice_no in range(1, self.__object.CountEngines):
voice_list.append(self.__object.ModeName(voice_no))
return voice_list
@property
def available_voices(self):
return self._voice_list
def list_voices(self):
return self.available_voices
def get_voice(self):
return self.__object.ModeName(self._voice_no)
def set_voice(self, value):
self._voice_no = self.list_voices().index(value) + 1
self.__object.Select(self._voice_no)
self.silence()
self.__object.Speak(" ")
self._set_capabilities()
def get_pitch(self):
if self.has_pitch:
return self.__object.Pitch
def set_pitch(self, value):
if self.has_pitch:
self.__object.Pitch = value
def get_rate(self):
if self.has_rate:
return self.__object.Speed
def set_rate(self, value):
if self.has_rate:
self.__object.Speed = value
def get_volume(self):
if self.has_volume:
return self.__object.VolumeLeft
def set_volume(self, value):
if self.has_volume:
self.__object.VolumeLeft = value
@property
def has_pitch(self):
return self._has_pitch
@property
def has_rate(self):
return self._has_rate
@property
def has_volume(self):
return self._has_volume
@property
def min_pitch(self):
return self._min_pitch
@property
def max_pitch(self):
return self._max_pitch
@property
def min_rate(self):
return self._min_rate
@property
def max_rate(self):
return self._max_rate
@property
def min_volume(self):
return self._min_volume
@property
def max_volume(self):
return self._max_volume
def speak(self, text, interrupt=False):
if interrupt:
self.silence()
self.__object.Speak(text)
def silence(self):
self.__object.AudioReset()
output_class = Sapi4

View File

@@ -1,95 +0,0 @@
from __future__ import absolute_import
from collections import OrderedDict
from libloader.com import load_com
from .base import Output, OutputError
import pywintypes
import logging
log = logging.getLogger(__name__)
SVSFDefault = 0
SVSFlagsAsync = 1
SVSFPurgeBeforeSpeak = 2
SVSFIsFilename = 4
SVSFIsXML = 8
SVSFIsNotXML = 16
SVSFPersistXML = 32
class SAPI5(Output):
has_volume = True
has_rate = True
has_pitch = True
min_pitch = -10
max_pitch = 10
min_rate = -10
max_rate = 10
min_volume = 0
max_volume = 100
name = "sapi5"
priority = 101
system_output = True
def __init__(self):
try:
self.object = load_com("SAPI.SPVoice")
self._voices = self._available_voices()
except pywintypes.com_error:
raise OutputError
self._pitch = 0
def _available_voices(self):
_voices = OrderedDict()
for v in self.object.GetVoices():
_voices[v.GetDescription()] = v
return _voices
def list_voices(self):
return list(self._voices.keys())
def get_voice(self):
return self.object.Voice.GetDescription()
def set_voice(self, value):
log.debug("Setting SAPI5 voice to \"%s\"" % value)
self.object.Voice = self._voices[value]
# For some reason SAPI5 does not reset audio after changing the voice
# By setting the audio device after changing voices seems to fix this
# This was noted from information at:
# http://lists.nvaccess.org/pipermail/nvda-dev/2011-November/022464.html
self.object.AudioOutput = self.object.AudioOutput
def get_pitch(self):
return self._pitch
def set_pitch(self, value):
log.debug("Setting pitch to %d" % value)
self._pitch = value
def get_rate(self):
return self.object.Rate
def set_rate(self, value):
log.debug("Setting rate to %d" % value)
self.object.Rate = value
def get_volume(self):
return self.object.Volume
def set_volume(self, value):
self.object.Volume = value
def speak(self, text, interrupt=False):
if interrupt:
self.silence()
# We need to do the pitch in XML here
textOutput = "<pitch absmiddle=\"%d\">%s</pitch>" % (round(self._pitch), text.replace("<", "&lt;"))
self.object.Speak(textOutput, SVSFlagsAsync | SVSFIsXML)
def silence(self):
self.object.Speak("", SVSFlagsAsync | SVSFPurgeBeforeSpeak)
def is_active(self):
if self.object:
return True
return False
output_class = SAPI5

View File

@@ -1,21 +0,0 @@
from __future__ import absolute_import
import os
from .base import Output
class AppleSay(Output):
"""Speech output supporting the Apple Say subsystem."""
name = 'Apple Say'
def __init__(self, voice = 'Alex', rate = '300'):
self.voice = voice
self.rate = rate
super(AppleSay, self).__init__()
def is_active(self):
return not os.system('which say')
def speak(self, text, interrupt = 0):
if interrupt:
self.silence()
os.system('say -v %s -r %s "%s" &' % (self.voice, self.rate, text))
def silence(self):
os.system('killall say')
output_class = AppleSay

View File

@@ -1,29 +0,0 @@
from __future__ import absolute_import
import ctypes
from .base import Output
class SystemAccess (Output):
"""Supports System Access and System Access Mobile"""
name = "System Access"
lib32 = 'saapi32.dll'
argtypes = {
'SA_BrlShowTextW': (ctypes.c_wchar_p,),
'SA_SayW': (ctypes.c_wchar_p,),
}
priority = 99
def braille(self, text, **options):
self.lib.SA_BrlShowTextW(text)
def speak(self, text, interrupt=False):
if self.is_active():
self.dll.SA_SayW(str(text))
def is_active(self):
try:
return self.dll.SA_IsRunning()
except:
return False
output_class = SystemAccess

View File

@@ -1 +0,0 @@
from __future__ import absolute_import

View File

@@ -1,33 +0,0 @@
from __future__ import absolute_import
import win32gui
from libloader.com import load_com
from .base import Output, OutputError
import pywintypes
class WindowEyes (Output):
"""Speech output supporting the WindowEyes screen reader"""
name = 'Window-Eyes'
def __init__(self, *args, **kwargs):
super(WindowEyes, self).__init__(*args, **kwargs)
try:
self.object = load_com("gwspeak.speak")
except pywintypes.com_error:
raise OutputError
def speak(self, text, interrupt=0):
if interrupt:
self.silence()
self.object.SpeakString(text)
def silence (self):
self.object.Silence()
def is_active(self):
try:
return win32gui.FindWindow("GWMExternalControl", "External Control") != 0
except:
return False
output_class = WindowEyes

View File

@@ -1,12 +1,12 @@
# -*- coding: utf-8 -*-
name = "Socializer"
version = "0.14"
author = u"Manuel Cortéz"
version = "0.16"
author = u"Manuel Cortez"
authorEmail = "manuel@manuelcortez.net"
copyright = u"Copyright (C) 2016, Manuel cortéz."
copyright = u"Copyright (C) 2016-2018, Manuel Cortez"
description = unicode(name+" Is an accessible VK client for Windows.")
url = "https://github.com/manuelcortez/socializer"
update_url = "https://raw.githubusercontent.com/manuelcortez/socializer/master/update-files/socializer.json"
url = "https://manuelcortez.net/socializer"
update_url = "https://code.manuelcortez.net/manuelcortez/socializer/raw/master/update-files/socializer.json"
# The short name will be used for detecting translation files. See languageHandler for more details.
short_name = "socializer"
translators = [u"Valeria K (Russian)", u"Manuel Cortez (Spanish)"]

View File

@@ -1,23 +1,38 @@
# -*- coding: utf-8 -*-
""" Attachment upload methods for different kind of posts in VK. This should become the framework for posting attachment files to the social network."""
import os
import widgetUtils
import logging
import widgetUtils
from wxUI.dialogs import attach as gui
from wxUI.dialogs import selector
log = logging.getLogger("controller.attach")
class attach(object):
def __init__(self):
class attachFromLocal(object):
""" Controller used in some sections of the application, mainly for uploading photos from the local computer to VK.
This controller will not upload the contents by itself, but will generate the data structures for being send over the VK API.
At the current time, only photo uploading is supported."""
def __init__(self, voice_messages=False):
""" Constructor.
@voice_messages bool: If True, will add a button for sending voice messages. Functionality for this button has not been added yet.
"""
# Self.attachments will hold a reference to all attachments added to the dialog.
self.attachments = list()
self.dialog = gui.attachDialog()
# Type is just a reference, as there will be local and online based attachments.
self.type = "local"
self.dialog = gui.attachDialog(voice_messages)
widgetUtils.connect_event(self.dialog.photo, widgetUtils.BUTTON_PRESSED, self.upload_image)
widgetUtils.connect_event(self.dialog.remove, widgetUtils.BUTTON_PRESSED, self.remove_attachment)
self.dialog.get_response()
log.debug("Attachments controller started.")
def upload_image(self, *args, **kwargs):
""" allows uploading an image from the computer. In theory
"""
image, description = self.dialog.get_image()
if image != None:
imageInfo = {"type": "photo", "file": image, "description": os.path.basename(image)}
# Define data structure for this attachment, as will be required by VK API later.
imageInfo = {"type": "photo", "file": image, "description": description}
log.debug("Image data to upload: %r" % (imageInfo,))
self.attachments.append(imageInfo)
# Translators: This is the text displayed in the attachments dialog, when the user adds a photo.
@@ -26,6 +41,7 @@ class attach(object):
self.dialog.remove.Enable(True)
def remove_attachment(self, *args, **kwargs):
""" Remove the currently focused item from the attachments list."""
current_item = self.dialog.attachments.get_selected()
log.debug("Removing item %d" % (current_item,))
if current_item == -1: current_item = 0
@@ -35,5 +51,49 @@ class attach(object):
log.debug("Removed")
def check_remove_status(self):
""" Checks whether the remove button should remain enabled."""
if len(self.attachments) == 0 and self.dialog.attachments.get_count() == 0:
self.dialog.remove.Enable(False)
class attachFromOnline(object):
""" this was the previously working audio attachment uploader. As VK has deprecated their Audio API for third party clients, this class will not work.
However, I have decided to keep this here so in future it may be modified to attach different kind of online based attachments, such as posted photos, videos, etc.
"""
def __init__(self, session):
""" Default constructor.
@session vk.session: An VK session, capable of calling methods from the VK API.
"""
self.session = session
# Self.attachments will hold a reference to all attachments added to the dialog.
self.attachments = list()
# Define type as online.
self.type = "online"
self.dialog = gui.attachDialog()
widgetUtils.connect_event(self.dialog.audio, widgetUtils.BUTTON_PRESSED, self.add_audio)
# widgetUtils.connect_event(self.dialog.remove, widgetUtils.BUTTON_PRESSED, self.remove_attachment)
self.dialog.get_response()
log.debug("Attachments controller started.")
def add_audio(self, *args, **kwargs):
""" Allow adding an audio directly from the user's audio library."""
list_of_audios = self.session.vk.client_audio.get()
# list_of_audios = list_of_audios["items"]
audios = []
for i in list_of_audios:
audios.append(u"{0}, {1}".format(i["title"], i["artist"]))
select = selector.selectAttachment(_(u"Select the audio files you want to send"), audios)
if select.get_response() == widgetUtils.OK and select.attachments.GetCount() > 0:
attachments = select.get_all_attachments()
for i in attachments:
list_of_audios[i]["type"] = "audio"
self.attachments.append(list_of_audios[i])
def parse_attachments(self):
""" Retrieve all attachments and convert them to data structures required by VK API."""
result = ""
for i in self.attachments:
# Define data structures required by VK API.
preresult = "{0}{1}_{2}".format(i["type"], i["owner_id"], i["id"])
result = preresult+","
return result

View File

@@ -1,76 +1,90 @@
# -*- coding: utf-8 -*-
import languageHandler
""" A buffer is a (virtual) list of items. All items belong to a category (wall posts, messages, persons...)"""
import random
import logging
import webbrowser
import arrow
import wx
import languageHandler
import widgetUtils
import messages
import utils
import posts
import player
import output
import logging
import selector
from wxUI.tabs import home
import posts
import attach
from pubsub import pub
from sessionmanager import session
from vk_api.exceptions import VkApiError
from vk_api import upload
from wxUI.tabs import home
from sessionmanager import session, renderers, utils
from mysc.thread_utils import call_threaded
from wxUI import commonMessages, menus
from vk import upload
from vk.exceptions import VkAPIMethodError
from sessionmanager.utils import add_attachment
log = logging.getLogger("controller.buffers")
class baseBuffer(object):
""" a basic representation of a buffer. Other buffers should be derived from this class"""
""" a basic representation of a buffer. Other buffers should be derived from this class. This buffer represents the "news feed" """
def get_post(self):
""" Return the currently focused post."""
return self.session.db[self.name]["items"][self.tab.list.get_selected()]
def __init__(self, parent=None, name="", session=None, composefunc=None, *args, **kwargs):
""" parent wx.Treebook: parent for the buffer panel,
name str: Name for saving this buffer's data in the local storage variable,
session sessionmanager.session.vkSession: Session for performing operations in the Vk API. This session should be logged in when this class is instanciated.
composefunc str: This function will be called for composing the result which will be put in the listCtrl. Composefunc should existss in the sessionmanager.session module.
args and kwargs will be passed to get_items()"""
""" Constructor:
@parent wx.Treebook: parent for the buffer panel,
@name str: Name for saving this buffer's data in the local storage variable,
@session sessionmanager.session.vkSession: Session for performing operations in the Vk API. This session should be logged in when this class is instanciated.
@composefunc str: This function will be called for composing the result which will be put in the listCtrl. Composefunc should existss in the sessionmanager.session module.
args and kwargs will be passed to get_items() without any filtering. Be careful there.
"""
super(baseBuffer, self).__init__()
self.args = args
self.kwargs = kwargs
# Create GUI associated to this buffer.
self.create_tab(parent)
# Add the name to the new control so we could look for it when needed.
# Add name to the new control so we could look for it when needed.
self.tab.name = name
self.session = session
self.compose_function = composefunc
#Update_function will be called every 3 minutes and it should be able to
# Get all new items in the buffer and sort them properly in the CtrlList.
# ToDo: Shall we allow dinamically set for update_function?
self.update_function = "get_page"
self.name = name
# Bind local events (they will respond to events happened in the buffer).
self.connect_events()
# source_key and post_key will point to the keys for sender and posts in VK API objects.
# They can be changed in the future for other item types in different buffers.
self.user_key = "source_id"
self.post_key = "post_id"
# When set to False, update_function won't be executed here.
self.can_get_items = True
def create_tab(self, parent):
""" Creates the Wx panel."""
""" Create the Wx panel."""
self.tab = home.homeTab(parent)
def insert(self, item, reversed=False):
""" Add a new item to the list. Uses session.composefunc for parsing the dictionary and create a valid result for putting it in the list."""
item_ = getattr(session, self.compose_function)(item, self.session)
item_ = getattr(renderers, self.compose_function)(item, self.session)
self.tab.list.insert_item(reversed, *item_)
def get_items(self, show_nextpage=False):
""" Retrieves items from the VK API. This function is called repeatedly by the main controller and users could call it implicitly as well with the update buffer option.
show_nextpage boolean: If it's true, it will try to load previous results.
""" Retrieve items from the VK API. This function is called repeatedly by the main controller and users could call it implicitly as well with the update buffer option.
@show_nextpage boolean: If it's true, it will try to load previous results.
"""
if self.can_get_items == False: return
retrieved = True # Control variable for handling unauthorised/connection errors.
try:
num = getattr(self.session, "get_newsfeed")(show_nextpage=show_nextpage, name=self.name, *self.args, **self.kwargs)
except VkAPIMethodError as err:
print(u"Error {0}: {1}".format(err.code, err.message))
except VkApiError as err:
log.error(u"Error {0}: {1}".format(err.code, err.message))
retrieved = err.code
return retrieved
if show_nextpage == False:
if self.tab.list.get_count() > 0 and num > 0:
print "inserting a value"
v = [i for i in self.session.db[self.name]["items"][:num]]
v.reverse()
[self.insert(i, True) for i in v]
@@ -82,14 +96,19 @@ class baseBuffer(object):
return retrieved
def get_more_items(self):
""" Returns previous items in the buffer."""
self.get_items(show_nextpage=True)
def post(self, *args, **kwargs):
p = messages.post(title=_(u"Write your post"), caption="", text="")
""" Create a post in the current user's wall.
This process is handled in two parts. This is the first part, where the GUI is created and user can send the post.
During the second part (threaded), the post will be sent to the API."""
p = messages.post(session=self.session, title=_(u"Write your post"), caption="", text="")
if p.message.get_response() == widgetUtils.OK:
call_threaded(self.do_last, p=p)
def do_last(self, p):
""" Second part of post function. Here everything is going to be sent to the API"""
msg = p.message.get_text().encode("utf-8")
privacy_opts = p.get_privacy_options()
attachments = ""
@@ -105,9 +124,12 @@ class baseBuffer(object):
p.message.Destroy()
def upload_attachments(self, attachments):
""" Upload attachments to VK before posting them.
Returns attachments formatted as string, as required by VK API.
Currently this function only supports photos."""
# To do: Check the caption and description fields for this kind of attachments.
local_attachments = ""
uploader = upload.VkUpload(self.session.vk.client)
uploader = upload.VkUpload(self.session.vk.session_object)
for i in attachments:
if i["type"] == "photo":
photos = i["file"]
@@ -120,6 +142,7 @@ class baseBuffer(object):
return local_attachments
def connect_events(self):
""" Bind all events to this buffer"""
widgetUtils.connect_event(self.tab.post, widgetUtils.BUTTON_PRESSED, self.post)
widgetUtils.connect_event(self.tab.list.list, widgetUtils.KEYPRESS, self.get_event)
widgetUtils.connect_event(self.tab.list.list, wx.EVT_LIST_ITEM_RIGHT_CLICK, self.show_menu)
@@ -127,6 +150,7 @@ class baseBuffer(object):
self.tab.set_focus_function(self.onFocus)
def show_menu(self, ev, pos=0, *args, **kwargs):
""" Show contextual menu when pressing menu key or right mouse click in a list item."""
if self.tab.list.get_count() == 0: return
menu = self.get_menu()
if pos != 0:
@@ -135,12 +159,14 @@ class baseBuffer(object):
self.tab.PopupMenu(menu, ev.GetPosition())
def show_menu_by_key(self, ev):
""" Show contextual menu when menu key is pressed"""
if self.tab.list.get_count() == 0:
return
if ev.GetKeyCode() == wx.WXK_WINDOWS_MENU:
self.show_menu(widgetUtils.MENU, pos=self.tab.list.list.GetPosition())
def get_menu(self):
""" Returns contextual menu options. They will change according to the focused item"""
m = menus.postMenu()
p = self.get_post()
if p.has_key("likes") == False:
@@ -154,9 +180,11 @@ class baseBuffer(object):
widgetUtils.connect_event(m, widgetUtils.MENU, self.do_like, menuitem=m.like)
widgetUtils.connect_event(m, widgetUtils.MENU, self.do_dislike, menuitem=m.dislike)
widgetUtils.connect_event(m, widgetUtils.MENU, self.do_comment, menuitem=m.comment)
widgetUtils.connect_event(m, widgetUtils.MENU, self.open_person_profile, menuitem=m.view_profile)
return m
def do_like(self, *args, **kwargs):
""" Set like in the currently focused post."""
post = self.get_post()
user = post[self.user_key]
id = post[self.post_key]
@@ -171,6 +199,7 @@ class baseBuffer(object):
output.speak(_(u"You liked this"))
def do_dislike(self, *args, **kwargs):
""" Set dislike (undo like) in the currently focused post."""
post = self.get_post()
user = post[self.user_key]
id = post[self.post_key]
@@ -185,6 +214,7 @@ class baseBuffer(object):
output.speak(_(u"You don't like this"))
def do_comment(self, *args, **kwargs):
""" Make a comment into the currently focused post."""
comment = messages.comment(title=_(u"Add a comment"), caption="", text="")
if comment.message.get_response() == widgetUtils.OK:
msg = comment.message.get_text().encode("utf-8")
@@ -195,9 +225,10 @@ class baseBuffer(object):
self.session.vk.client.wall.addComment(owner_id=user, post_id=id, text=msg)
output.speak(_(u"You've posted a comment"))
except Exception as msg:
print msg
log.error(msg)
def get_event(self, ev):
""" Parses keyboard input in the ListCtrl and executes the event associated with user keypresses."""
if ev.GetKeyCode() == wx.WXK_RETURN and ev.ControlDown() and ev.ShiftDown(): event = "pause_audio"
elif ev.GetKeyCode() == wx.WXK_RETURN and ev.ControlDown(): event = "play_audio"
elif ev.GetKeyCode() == wx.WXK_RETURN: event = "open_post"
@@ -213,18 +244,32 @@ class baseBuffer(object):
pass
def volume_down(self):
""" Decreases player volume by 5%"""
player.player.volume = player.player.volume-5
def volume_up(self):
""" Increases player volume by 5%"""
player.player.volume = player.player.volume+5
def play_audio(self, *args, **kwargs):
post = self.session.db[self.name]["items"][self.tab.list.get_selected()]
""" Play audio in currently focused buffer, if possible."""
post = self.get_post()
if post.has_key("type") and post["type"] == "audio":
pub.sendMessage("play-audio", audio_object=post["audio"]["items"][0])
return True
def open_person_profile(self, *args, **kwargs):
""" Views someone's user profile."""
selected = self.get_post()
# Check all possible keys for an user object in VK API.
keys = ["from_id", "source_id", "id"]
for i in keys:
if selected.has_key(i):
pub.sendMessage("user-profile", person=selected[i])
def open_post(self, *args, **kwargs):
post = self.session.db[self.name]["items"][self.tab.list.get_selected()]
""" Opens the currently focused post."""
post = self.get_post()
if post.has_key("type") and post["type"] == "audio":
a = posts.audio(self.session, post["audio"]["items"])
a.dialog.get_response()
@@ -235,12 +280,16 @@ class baseBuffer(object):
pub.sendMessage("open-post", post_object=post, controller_="postController")
def pause_audio(self, *args, **kwargs):
""" pauses audio playback."""
player.player.pause()
def remove_buffer(self, mandatory): return False
def remove_buffer(self, mandatory):
""" Function for removing a buffer. Returns True if removal is successful, False otherwise"""
return False
def get_users(self):
post = self.session.db[self.name]["items"][self.tab.list.get_selected()]
""" Returns source user in the post."""
post = self.get_post()
if post.has_key("type") == False:
return [post["from_id"]]
else:
@@ -249,27 +298,26 @@ class baseBuffer(object):
def onFocus(self, *args,**kwargs):
""" Function executed when the item in a list is selected.
For this buffer it updates the date of posts in the list."""
post = self.session.db[self.name]["items"][self.tab.list.get_selected()]
post = self.get_post()
original_date = arrow.get(post["date"])
created_at = original_date.humanize(locale=languageHandler.getLanguage())
self.tab.list.list.SetStringItem(self.tab.list.get_selected(), 2, created_at)
created_at = original_date.humanize(locale=languageHandler.curLang[:2])
self.tab.list.list.SetItem(self.tab.list.get_selected(), 2, created_at)
class feedBuffer(baseBuffer):
""" This buffer represents an user's wall. It may be used either for the current user or someone else."""
def get_items(self, show_nextpage=False):
""" Update buffer with newest items or get older items in the buffer."""
if self.can_get_items == False: return
retrieved = True
try:
num = getattr(self.session, "get_page")(show_nextpage=show_nextpage, name=self.name, *self.args, **self.kwargs)
print num
except VkAPIMethodError as err:
print(u"Error {0}: {1}".format(err.code, err.message))
except ValueError:
log.error(u"Error {0}: {1}".format(err.code, err.message))
retrieved = err.code
return retrieved
if show_nextpage == False:
if self.tab.list.get_count() > 0 and num > 0:
print "inserting a value"
v = [i for i in self.session.db[self.name]["items"][:num]]
v.reverse()
[self.insert(i, True) for i in v]
@@ -278,6 +326,7 @@ class feedBuffer(baseBuffer):
return retrieved
def remove_buffer(self, mandatory=False):
""" Remove buffer if the current buffer is not the logged user's wall."""
if "me_feed" == self.name:
output.speak(_(u"This buffer can't be deleted"))
return False
@@ -298,6 +347,9 @@ class feedBuffer(baseBuffer):
self.post_key = "id"
class audioBuffer(feedBuffer):
""" this buffer was supposed to be used with audio elements
but is deprecated as VK removed its audio support for third party apps."""
def create_tab(self, parent):
self.tab = home.audioTab(parent)
@@ -308,7 +360,29 @@ class audioBuffer(feedBuffer):
def play_audio(self, *args, **kwargs):
selected = self.tab.list.get_selected()
if selected == -1:
selected = 0
pub.sendMessage("play-audio", audio_object=self.session.db[self.name]["items"][selected])
return True
def play_next(self, *args, **kwargs):
selected = self.tab.list.get_selected()
if selected < 0 or selected == self.tab.list.get_count()-1:
selected = 0
if self.tab.list.get_count() <= selected+1:
newpos = 0
else:
newpos = selected+1
self.tab.list.select_item(newpos)
self.play_audio()
def play_previous(self, *args, **kwargs):
selected = self.tab.list.get_selected()
if selected <= 0:
selected = self.tab.list.get_count()
newpos = selected-1
self.tab.list.select_item(newpos)
self.play_audio()
def open_post(self, *args, **kwargs):
selected = self.tab.list.get_selected()
@@ -323,6 +397,7 @@ class audioBuffer(feedBuffer):
selected = 0
audios = [i for i in self.session.db[self.name]["items"][selected:]]
pub.sendMessage("play-audios", audios=audios)
return True
def remove_buffer(self, mandatory=False):
if "me_audio" == self.name or "popular_audio" == self.name or "recommended_audio" == self.name:
@@ -368,7 +443,7 @@ class audioBuffer(feedBuffer):
self.tab.list.remove_item(self.tab.list.get_selected())
def move_to_album(self, *args, **kwargs):
album = selector.audioAlbum(_(u"Select the album where you want to move this song"), self.session)
album = selector.album(_(u"Select the album where you want to move this song"), self.session)
if album.item == None: return
id = self.get_post()["id"]
response = self.session.vk.client.audio.moveToAlbum(album_id=album.item, audio_ids=id)
@@ -391,6 +466,8 @@ class audioBuffer(feedBuffer):
return m
class audioAlbum(audioBuffer):
""" this buffer was supposed to be used with audio albums
but is deprecated as VK removed its audio support for third party apps."""
def create_tab(self, parent):
self.tab = home.audioAlbumTab(parent)
@@ -409,6 +486,117 @@ class audioAlbum(audioBuffer):
self.tab.play.Enable(True)
self.tab.play_all.Enable(True)
class videoBuffer(feedBuffer):
""" This buffer represents video elements, and it can be used for showing videos for the logged user or someone else."""
def create_tab(self, parent):
self.tab = home.videoTab(parent)
def connect_events(self):
widgetUtils.connect_event(self.tab.play, widgetUtils.BUTTON_PRESSED, self.play_audio)
super(videoBuffer, self).connect_events()
def play_audio(self, *args, **kwargs):
""" Due to inheritance this method should be called play_audio, but play the currently focused video.
Opens a webbrowser pointing to the video's URL."""
selected = self.tab.list.get_selected()
if selected == -1:
selected = 0
output.speak(_(u"Opening video in webbrowser..."))
webbrowser.open_new_tab(self.session.db[self.name]["items"][selected]["player"])
return True
def open_post(self, *args, **kwargs):
selected = self.tab.list.get_selected()
audios = [self.session.db[self.name]["items"][selected]]
a = posts.audio(self.session, audios)
a.dialog.get_response()
a.dialog.Destroy()
def remove_buffer(self, mandatory=False):
if "me_video" == self.name:
output.speak(_(u"This buffer can't be deleted"))
return False
else:
if mandatory == False:
dlg = commonMessages.remove_buffer()
else:
dlg = widgetUtils.YES
if dlg == widgetUtils.YES:
self.session.db.pop(self.name)
return True
else:
return False
def get_more_items(self, *args, **kwargs):
# Translators: Some buffers can't use the get previous item feature due to API limitations.
output.speak(_(u"This buffer doesn't support getting more items."))
def onFocus(self, *args, **kwargs):
pass
def add_to_library(self, *args, **kwargs):
post = self.get_post()
args = {}
args["video_id"] = post["id"]
if post.has_key("album_id"):
args["album_id"] = post["album_id"]
args["owner_id"] = post["owner_id"]
video = self.session.vk.client.video.add(**args)
if video != None and int(video) > 21:
output.speak(_(u"Video added to your library"))
def remove_from_library(self, *args, **kwargs):
post = self.get_post()
args = {}
args["video_id"] = post["id"]
args["owner_id"] = self.session.user_id
result = self.session.vk.client.video.delete(**args)
if int(result) == 1:
output.speak(_(u"Removed video from library"))
self.tab.list.remove_item(self.tab.list.get_selected())
def move_to_album(self, *args, **kwargs):
album = selector.album(_(u"Select the album where you want to move this video"), self.session, "video_albums")
if album.item == None: return
id = self.get_post()["id"]
response = self.session.vk.client.video.addToAlbum(album_ids=album.item, video_id=id, target_id=self.session.user_id, owner_id=self.get_post()["owner_id"])
if response == 1:
# Translators: Used when the user has moved an video to an album.
output.speak(_(u"Moved"))
def get_menu(self):
""" We'll use the same menu that is used for audio items, as the options are exactly the same"""
p = self.get_post()
m = menus.audioMenu()
# widgetUtils.connect_event(m, widgetUtils.MENU, self.open_post, menuitem=m.open)
# widgetUtils.connect_event(m, widgetUtils.MENU, self.play_audio, menuitem=m.play)
widgetUtils.connect_event(m, widgetUtils.MENU, self.move_to_album, menuitem=m.move)
# if owner_id is the current user, the audio is added to the user's audios.
if p["owner_id"] == self.session.user_id:
m.library.SetItemLabel(_(u"&Remove from library"))
widgetUtils.connect_event(m, widgetUtils.MENU, self.remove_from_library, menuitem=m.library)
else:
widgetUtils.connect_event(m, widgetUtils.MENU, self.add_to_library, menuitem=m.library)
return m
class videoAlbum(videoBuffer):
def create_tab(self, parent):
self.tab = home.videoAlbumTab(parent)
self.tab.play.Enable(False)
def connect_events(self):
super(videoAlbum, self).connect_events()
widgetUtils.connect_event(self.tab.load, widgetUtils.BUTTON_PRESSED, self.load_album)
def load_album(self, *args, **kwargs):
output.speak(_(u"Loading album..."))
self.can_get_items = True
self.tab.load.Enable(False)
wx.CallAfter(self.get_items)
self.tab.play.Enable(True)
class empty(object):
def __init__(self, name=None, parent=None, *args, **kwargs):
@@ -425,34 +613,87 @@ class empty(object):
class chatBuffer(baseBuffer):
def onFocus(self, *args, **kwargs):
msg = self.session.db[self.name]["items"][-1]
if msg.has_key("read_state") and msg["read_state"] == 0 and msg["id"] not in self.reads:
self.reads.append(msg["id"])
self.session.db[self.name]["items"][-1]["read_state"] = 1
def insert(self, item, reversed=False):
""" Add a new item to the list. Uses session.composefunc for parsing the dictionary and create a valid result for putting it in the list."""
item_ = getattr(renderers, self.compose_function)(item, self.session)
# the self.chat dictionary will have (first_line, last_line) as keys and message ID as a value for looking into it when needed.
# Here we will get first and last line of a chat message appended to the history.
values = self.tab.add_message(item_[0])
self.chats[values] = item["id"]
def get_focused_post(self):
""" Gets chat message currently in focus"""
# this function replaces self.get_post for normal buffers, as we rely in a TextCtrl control for getting chats.
# Instead of the traditional method to do the trick.
# Get text position here.
position = self.tab.history.PositionToXY(self.tab.history.GetInsertionPoint())
id_ = None
for i in self.chats.keys():
# Check if position[2] (line position) matches with something in self.chats
# (All messages, except the last one, should be able to be matched here).
# position[2]+1 is added because line may start with 0, while in wx.TextCtrl.GetNumberLines() that is not possible.
if position[2]+1 >= i[0] and position[2]+1 < i[1]:
id_ = self.chats[i]
# print i
break
# Retrieve here the object based in id_
if id_ != None:
for i in self.session.db[self.name]["items"]:
if i["id"] == id_:
return i
return False
get_post = get_focused_post
def onFocus(self, event, *args, **kwargs):
if event.GetKeyCode() == wx.WXK_UP or event.GetKeyCode() == wx.WXK_DOWN or event.GetKeyCode() == wx.WXK_START or event.GetKeyCode() == wx.WXK_PAGEUP or event.GetKeyCode() == wx.WXK_PAGEDOWN or event.GetKeyCode() == wx.WXK_END:
msg = self.get_focused_post()
if msg == False: # Handle the case where the last line of the control cannot be matched to anything.
return
if msg.has_key("read_state") and msg["read_state"] == 0 and msg["id"] not in self.reads:
self.reads.append(msg["id"])
self.session.db[self.name]["items"][-1]["read_state"] = 1
# print msg
if msg.has_key("attachments") and len(msg["attachments"]) > 0:
self.tab.attachments.list.Enable(True)
self.attachments = list()
self.tab.attachments.clear()
self.parse_attachments(msg)
else:
self.tab.attachments.list.Enable(False)
self.tab.attachments.clear()
event.Skip()
def create_tab(self, parent):
self.tab = home.chatTab(parent)
self.attachments = list()
def connect_events(self):
widgetUtils.connect_event(self.tab.send, widgetUtils.BUTTON_PRESSED, self.send_chat_to_user)
widgetUtils.connect_event(self.tab.attachment, widgetUtils.BUTTON_PRESSED, self.add_attachment)
widgetUtils.connect_event(self.tab.text, widgetUtils.KEYPRESS, self.catch_enter)
self.tab.set_focus_function(self.onFocus)
def catch_enter(self, event, *args, **kwargs):
if event.GetKeyCode() == wx.WXK_RETURN:
self.send_chat_to_user()
event.Skip()
def get_items(self, show_nextpage=False):
if self.can_get_items == False: return
retrieved = True # Control variable for handling unauthorised/connection errors.
try:
num = getattr(self.session, "get_messages")(name=self.name, *self.args, **self.kwargs)
except VkAPIMethodError as err:
print(u"Error {0}: {1}".format(err.code, err.message))
except ValueError as err:
log.error(u"Error {0}: {1}".format(err.code, err.message))
retrieved = err.code
return retrieved
if show_nextpage == False:
if self.tab.list.get_count() > 0 and num > 0:
print "inserting a value"
if self.tab.history.GetValue() != "" and num > 0:
v = [i for i in self.session.db[self.name]["items"][:num]]
v.reverse()
[self.insert(i, True) for i in v]
# v.reverse()
[self.insert(i, False) for i in v]
else:
[self.insert(i) for i in self.session.db[self.name]["items"][:num]]
else:
@@ -460,14 +701,96 @@ class chatBuffer(baseBuffer):
[self.insert(i, False) for i in self.session.db[self.name]["items"][:num]]
return retrieved
def add_attachment(self, *args, **kwargs):
a = attach.attachFromOnline(self.session)
r = a.parse_attachments()
if r != "":
self.attachments_to_be_sent = r
def send_chat_to_user(self, *args, **kwargs):
text = self.tab.text.GetValue()
if text == "": return
response = self.session.vk.client.messages.send(user_id=self.kwargs["user_id"], message=text)
if text == "" and not hasattr(self, "attachments_to_be_sent"):
wx.Bell()
return
call_threaded(self._send_message, text=text)
def _send_message(self, text):
try:
# Let's take care about the random_id attribute.
# This should be unique per message and should be changed right after the message has been sent.
# If the message is tried to be sent twice this random_id should be the same for both copies.
# At the moment we just calculate len(text)_user_id, hope that will work.
random_id = random.randint(0, 100000)
if hasattr(self, "attachments_to_be_sent"):
response = self.session.vk.client.messages.send(user_id=self.kwargs["user_id"], message=text, attachment=self.attachments_to_be_sent, random_id=random_id)
else:
response = self.session.vk.client.messages.send(user_id=self.kwargs["user_id"], message=text, random_id=random_id)
except ValueError as ex:
if ex.code == 9:
output.speak(_(u"You have been sending a message that is already sent. Try to update the buffer if you can't see the new message in the history."))
finally:
self.tab.text.SetValue("")
def __init__(self, *args, **kwargs):
super(chatBuffer, self).__init__(*args, **kwargs)
self.reads = []
self.chats = dict()
def parse_attachments(self, post):
attachments = []
if post.has_key("attachments"):
for i in post["attachments"]:
# We don't need the photos_list attachment, so skip it.
if i["type"] == "photos_list":
continue
attachments.append(add_attachment(i))
self.attachments.append(i)
self.tab.attachments.list.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.open_attachment)
self.tab.insert_attachments(attachments)
def open_attachment(self, *args, **kwargs):
index = self.tab.attachments.get_selected()
attachment = self.attachments[index]
if attachment["type"] == "audio":
a = posts.audio(session=self.session, postObject=[attachment["audio"]])
a.dialog.get_response()
a.dialog.Destroy()
elif attachment["type"] == "audio_message":
link = attachment["audio_message"]["link_mp3"]
output.speak(_(u"Playing..."))
player.player.play(url=dict(url=link), set_info=False)
elif attachment["type"] == "link":
output.speak(_(u"Opening URL..."), True)
webbrowser.open_new_tab(attachment["link"]["url"])
elif attachment["type"] == "doc":
output.speak(_(u"Opening document in web browser..."))
webbrowser.open(attachment["doc"]["url"])
elif attachment["type"] == "video":
# it seems VK doesn't like to attach video links as normal URLS, so we'll have to
# get the full video object and use its "player" key which will open a webbrowser in their site with a player for the video.
# see https://vk.com/dev/attachments_w and and https://vk.com/dev/video.get
# However, the flash player isn't good for visually impaired people (when you press play you won't be able to close the window with alt+f4), so it could be good to use the HTML5 player.
# For firefox, see https://addons.mozilla.org/ru/firefox/addon/force-html5-video-player-at-vk/
# May be I could use a dialogue here for inviting people to use this addon in firefox. It seems it isn't possible to use this html5 player from the player URL.
object_id = "{0}_{1}".format(attachment["video"]["owner_id"], attachment["video"]["id"])
video_object = self.session.vk.client.video.get(owner_id=attachment["video"]["owner_id"], videos=object_id)
video_object = video_object["items"][0]
output.speak(_(u"Opening video in web browser..."), True)
webbrowser.open_new_tab(video_object["player"])
elif attachment["type"] == "photo":
output.speak(_(u"Opening photo in web browser..."), True)
# Possible photo sizes for looking in the attachment information. Try to use the biggest photo available.
possible_sizes = [1280, 604, 130, 75]
url = ""
for i in possible_sizes:
if attachment["photo"].has_key("photo_{0}".format(i,)):
url = attachment["photo"]["photo_{0}".format(i,)]
break
if url != "":
webbrowser.open_new_tab(url)
else:
log.debug("Unhandled attachment: %r" % (attachment,))
class peopleBuffer(feedBuffer):
@@ -486,21 +809,102 @@ class peopleBuffer(feedBuffer):
post = self.session.db[self.name]["items"][self.tab.list.get_selected()]
if post.has_key("last_seen") == False: return
original_date = arrow.get(post["last_seen"]["time"])
created_at = original_date.humanize(locale=languageHandler.getLanguage())
self.tab.list.list.SetStringItem(self.tab.list.get_selected(), 1, created_at)
created_at = original_date.humanize(locale=languageHandler.curLang[:2])
self.tab.list.list.SetItem(self.tab.list.get_selected(), 1, created_at)
def open_timeline(self, *args, **kwargs):
pass
def get_menu(self, *args, **kwargs):
m = menus.peopleMenu()
""" display menu for people buffers (friends and requests)"""
# If this is an incoming requests buffer, there is a flag in the peopleMenu that shows a few new options.
# So let's make sure we call it accordingly.
if self.name == "friend_requests":
m = menus.peopleMenu(is_request=True)
# Connect the accept and decline methods from here.
widgetUtils.connect_event(m, widgetUtils.MENU, self.accept_friendship, menuitem=m.accept)
widgetUtils.connect_event(m, widgetUtils.MENU, self.decline_friendship, menuitem=m.decline)
widgetUtils.connect_event(m, widgetUtils.MENU, self.keep_as_follower, menuitem=m.keep_as_follower)
else:
m = menus.peopleMenu(is_request=False)
# It is not allowed to send messages to people who is not your friends, so let's disble it if we're in a pending or outgoing requests folder.
if "friend_requests" in self.name:
m.message.Enable(False)
widgetUtils.connect_event(m, widgetUtils.MENU, self.new_chat, menuitem=m.message)
widgetUtils.connect_event(m, widgetUtils.MENU, self.open_timeline, menuitem=m.timeline)
widgetUtils.connect_event(m, widgetUtils.MENU, self.open_person_profile, menuitem=m.view_profile)
return m
def open_post(self, *args, **kwargs): pass
def play_audio(self, *args, **kwargs): pass
def play_audio(self, *args, **kwargs): return False
def pause_audio(self, *args, **kwargs): pass
def accept_friendship(self, *args, **kwargs):
pass
def decline_friendship(self, *args, **kwargs):
pass
def keep_as_follower(self, *args, **kwargs):
pass
class requestsBuffer(peopleBuffer):
def get_items(self, show_nextpage=False):
if self.can_get_items == False: return
retrieved = True
try:
ids = self.session.vk.client.friends.getRequests(*self.args, **self.kwargs)
except ValueError as err:
log.error(u"Error {0}: {1}".format(err.code, err.message))
retrieved = err.code
return retrieved
num = self.session.get_page(name=self.name, show_nextpage=show_nextpage, endpoint="get", parent_endpoint="users", count=1000, user_ids=", ".join([str(i) for i in ids["items"]]), fields="uid, first_name, last_name, last_seen")
if show_nextpage == False:
if self.tab.list.get_count() > 0 and num > 0:
v = [i for i in self.session.db[self.name]["items"][:num]]
v.reverse()
[self.insert(i, True) for i in v]
else:
[self.insert(i) for i in self.session.db[self.name]["items"][:num]]
return retrieved
def accept_friendship(self, *args, **kwargs):
""" Adds a person to a list of friends. This method is done for accepting someone else's friend request.
https://vk.com/dev/friends.add
"""
person = self.get_post()
result = self.session.vk.client.friends.add(user_id=person["id"])
if result == 2:
msg = _(u"{0} {1} now is your friend.").format(person["first_name"], person["last_name"])
pub.sendMessage("notify", message=msg)
self.session.db[self.name]["items"].pop(self.tab.list.get_selected())
self.tab.list.remove_item(self.tab.list.get_selected())
def decline_friendship(self, *args, **kwargs):
""" Declines a freind request.
https://vk.com/dev/friends.delete
"""
person = self.get_post()
result = self.session.vk.client.friends.delete(user_id=person["id"])
if "out_request_deleted" in result:
msg = _(u"You've deleted the friends request to {0} {1}.").format(person["first_name"], person["last_name"])
elif "in_request_deleted" in result:
msg = _(u"You've declined the friend request of {0} {1}.").format(person["first_name"], person["last_name"])
pub.sendMessage("notify", message=msg)
self.session.db[self.name]["items"].pop(self.tab.list.get_selected())
self.tab.list.remove_item(self.tab.list.get_selected())
def keep_as_follower(self, *args, **kwargs):
""" Adds a person to The followers list of the current user.
https://vk.com/dev/friends.add
"""
person = self.get_post()
result = self.session.vk.client.friends.add(user_id=person["id"], follow=1)
if result == 2:
msg = _(u"{0} {1} is following you.").format(person["first_name"], person["last_name"])
pub.sendMessage("notify", message=msg)
self.session.db[self.name]["items"].pop(self.tab.list.get_selected())
self.tab.list.remove_item(self.tab.list.get_selected())

View File

@@ -4,6 +4,18 @@ from wxUI.dialogs import configuration as configurationUI
class configuration(object):
def get_notification_type(self, value):
if value == _(u"Native"):
return "native"
else:
return "custom"
def get_notification_label(self, value):
if value == "native":
return _(u"Native")
else:
return _(u"Custom")
def __init__(self, session):
self.session = session
self.dialog = configurationUI.configurationDialog(_(u"Preferences"))
@@ -12,11 +24,23 @@ class configuration(object):
def create_config(self):
self.dialog.create_general()
self.dialog.set_value("general", "wall_buffer_count", self.session.settings["buffers"]["count_for_wall_buffers"])
self.dialog.set_value("general", "audio_buffers_count", self.session.settings["buffers"]["count_for_audio_buffers"])
self.dialog.set_value("general", "video_buffers_count", self.session.settings["buffers"]["count_for_video_buffers"])
self.dialog.set_value("general", "load_images", self.session.settings["general"]["load_images"])
self.dialog.create_chat()
self.dialog.set_value("chat", "notify_online", self.session.settings["chat"]["notify_online"])
self.dialog.set_value("chat", "notify_offline", self.session.settings["chat"]["notify_offline"])
self.dialog.set_value("chat", "open_unread_conversations", self.session.settings["chat"]["open_unread_conversations"])
self.dialog.set_value("chat", "automove_to_conversations", self.session.settings["chat"]["automove_to_conversations"])
self.dialog.set_value("chat", "notifications", self.get_notification_label(self.session.settings["chat"]["notifications"]))
self.dialog.realize()
self.response = self.dialog.get_response()
def save_configuration(self):
self.session.settings["buffers"]["count_for_audio_buffers"] = self.dialog.get_value("general", "wall_buffer_count")
self.session.settings["buffers"]["count_for_audio_buffers"] = self.dialog.get_value("general", "audio_buffers_count")
self.session.settings["buffers"]["count_for_video_buffers"] = self.dialog.get_value("general", "video_buffers_count")
self.session.settings["general"]["load_images"] = self.dialog.get_value("general", "load_images")
self.session.settings["chat"]["notify_online"] = self.dialog.get_value("chat", "notify_online")
self.session.settings["chat"]["notify_offline"] = self.dialog.get_value("chat", "notify_offline")
self.session.settings["chat"]["open_unread_conversations"] = self.dialog.get_value("chat", "open_unread_conversations")
self.session.settings["chat"]["automove_to_conversations"] = self.dialog.get_value("chat", "automove_to_conversations")
self.session.settings["chat"]["notifications"] = self.get_notification_type(self.dialog.get_value("chat", "notifications"))
self.session.settings.write()

View File

@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
import threading
from vk_api.longpoll import VkLongPoll, VkEventType
from pubsub import pub
from requests.exceptions import ReadTimeout
from logging import getLogger
log = getLogger("controller.longpolThread")
class worker(threading.Thread):
def __init__(self, session):
super(worker, self).__init__()
log.debug("Instantiating longPoll server")
self.session = session
self.longpoll = VkLongPoll(self.session.vk.session_object)
def run(self):
try:
for event in self.longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW:
pub.sendMessage("order-sent-message", obj=event)
elif event.type == VkEventType.USER_ONLINE:
pub.sendMessage("user-online", event=event)
elif event.type == VkEventType.USER_OFFLINE:
pub.sendMessage("user-offline", event=event)
except ReadTimeout:
pub.sendMessage("longpoll-read-timeout")

View File

@@ -1,22 +0,0 @@
# -*- coding: utf-8 -*-
import threading
from vk import longpool
from pubsub import pub
class worker(threading.Thread):
def __init__(self, session):
super(worker, self).__init__()
self.session = session
self.l = longpool.LongPoll(self.session.vk.client)
def run(self):
while self.session.is_logged == True:
p = self.l.check()
for i in p:
# print i.message_id, i.flags, i.from_id, i.user_id, i.mask, i.byself, i.message_flags
# if i.flags == 4 or i.flags == 51 or i.flags == 49:
if i.text != None and i.from_id != None and i.flags != None and i.message_flags != None:
# print i.message_id, i.flags, i.from_id, i.user_id, i.mask, i.byself, i.message_flags
# if i.from_id != None:
# print "ordering sent stuff"
pub.sendMessage("order-sent-message", obj=i)

View File

@@ -2,23 +2,25 @@
import time
import os
import wx
import utils
import widgetUtils
import messages
import buffers
import configuration
import player
import posts
import profiles
import webbrowser
import logging
import longpoolthread
import output
import longpollthread
import selector
from vk.exceptions import VkAuthError
from vk_api.exceptions import LoginRequired, VkApiError
from requests.exceptions import ConnectionError
from pubsub import pub
from mysc.repeating_timer import RepeatingTimer
from mysc.thread_utils import call_threaded
from mysc import localization
from sessionmanager import session
from sessionmanager import session, utils, renderers
from wxUI import (mainWindow, commonMessages)
from wxUI.dialogs import search as searchDialogs
from wxUI.dialogs import timeline, creation
@@ -61,43 +63,61 @@ class Controller(object):
self.buffers.append(posts_)
# Translators: Name for the posts tab in the tree view.
self.window.add_buffer(posts_.tab, _(u"Posts"))
home = buffers.baseBuffer(parent=self.window.tb, name="home_timeline", session=self.session, composefunc="compose_new", endpoint="newsfeed", count=self.session.settings["buffers"]["count_for_wall_buffers"])
home = buffers.baseBuffer(parent=self.window.tb, name="home_timeline", session=self.session, composefunc="render_newsfeed_item", endpoint="newsfeed", count=self.session.settings["buffers"]["count_for_wall_buffers"])
self.buffers.append(home)
# Translators: Newsfeed's name in the tree view.
self.window.insert_buffer(home.tab, _(u"Home"), self.window.search("posts"))
self.repeatedUpdate = RepeatingTimer(180, self.update_all_buffers)
self.repeatedUpdate.start()
self.readMarker = RepeatingTimer(120, self.mark_as_read)
self.readMarker.start()
feed = buffers.feedBuffer(parent=self.window.tb, name="me_feed", composefunc="compose_status", session=self.session, endpoint="get", parent_endpoint="wall", extended=1, count=self.session.settings["buffers"]["count_for_wall_buffers"])
feed = buffers.feedBuffer(parent=self.window.tb, name="me_feed", composefunc="render_status", session=self.session, endpoint="get", parent_endpoint="wall", extended=1, count=self.session.settings["buffers"]["count_for_wall_buffers"])
self.buffers.append(feed)
# Translators: Own user's wall name in the tree view.
self.window.insert_buffer(feed.tab, _(u"My wall"), self.window.search("posts"))
### Disabled audio stuff for now.
audios = buffers.empty(parent=self.window.tb, name="audios")
self.buffers.append(audios)
# Translators: name for the music category in the tree view.
self.window.add_buffer(audios.tab, _(u"Music"))
audio = buffers.audioBuffer(parent=self.window.tb, name="me_audio", composefunc="compose_audio", session=self.session, endpoint="get", parent_endpoint="audio", full_list=True, count=self.session.settings["buffers"]["count_for_audio_buffers"])
audio = buffers.audioBuffer(parent=self.window.tb, name="me_audio", composefunc="render_audio", session=self.session, endpoint="get", parent_endpoint="audio")
self.buffers.append(audio)
self.window.insert_buffer(audio.tab, _(u"My audios"), self.window.search("audios"))
p_audio = buffers.audioBuffer(parent=self.window.tb, name="popular_audio", composefunc="compose_audio", session=self.session, endpoint="getPopular", parent_endpoint="audio", full_list=True, count=self.session.settings["buffers"]["count_for_audio_buffers"])
self.buffers.append(p_audio)
self.window.insert_buffer(p_audio.tab, _(u"Populars"), self.window.search("audios"))
r_audio = buffers.audioBuffer(parent=self.window.tb, name="recommended_audio", composefunc="compose_audio", session=self.session, endpoint="getRecommendations", parent_endpoint="audio", full_list=True, count=self.session.settings["buffers"]["count_for_audio_buffers"])
self.buffers.append(r_audio)
self.window.insert_buffer(r_audio.tab, _(u"Recommendations"), self.window.search("audios"))
# p_audio = buffers.audioBuffer(parent=self.window.tb, name="popular_audio", composefunc="render_audio", session=self.session, endpoint="getPopular", parent_endpoint="audio", full_list=True, count=self.session.settings["buffers"]["count_for_audio_buffers"])
# self.buffers.append(p_audio)
# self.window.insert_buffer(p_audio.tab, _(u"Populars"), self.window.search("audios"))
# r_audio = buffers.audioBuffer(parent=self.window.tb, name="recommended_audio", composefunc="render_audio", session=self.session, endpoint="getRecommendations", parent_endpoint="audio", full_list=True, count=self.session.settings["buffers"]["count_for_audio_buffers"])
# self.buffers.append(r_audio)
# self.window.insert_buffer(r_audio.tab, _(u"Recommendations"), self.window.search("audios"))
albums = buffers.empty(parent=self.window.tb, name="albums")
self.buffers.append(albums)
self.window.insert_buffer(albums.tab, _(u"Albums"), self.window.search("audios"))
videos = buffers.empty(parent=self.window.tb, name="videos")
self.buffers.append(videos)
# Translators: name for the videos category in the tree view.
self.window.add_buffer(videos.tab, _(u"Video"))
my_videos = buffers.videoBuffer(parent=self.window.tb, name="me_video", composefunc="render_video", session=self.session, endpoint="get", parent_endpoint="video", count=self.session.settings["buffers"]["count_for_video_buffers"])
self.buffers.append(my_videos)
self.window.insert_buffer(my_videos.tab, _(u"My videos"), self.window.search("videos"))
video_albums = buffers.empty(parent=self.window.tb, name="video_albums")
self.buffers.append(video_albums)
self.window.insert_buffer(video_albums.tab, _(u"Albums"), self.window.search("videos"))
people = buffers.empty(parent=self.window.tb, name="people")
self.buffers.append(people)
self.window.add_buffer(people.tab, _(u"People"))
friends = buffers.peopleBuffer(parent=self.window.tb, name="friends_", composefunc="compose_person", session=self.session, endpoint="get", parent_endpoint="friends", count=5000, fields="uid, first_name, last_name, last_seen")
friends = buffers.peopleBuffer(parent=self.window.tb, name="friends_", composefunc="render_person", session=self.session, endpoint="get", parent_endpoint="friends", count=5000, fields="uid, first_name, last_name, last_seen")
self.buffers.append(friends)
self.window.insert_buffer(friends.tab, _(u"Friends"), self.window.search("people"))
requests_ = buffers.empty(parent=self.window.tb, name="requests")
self.buffers.append(requests_)
self.window.insert_buffer(requests_.tab, _(u"Friendship requests"), self.window.search("people"))
incoming_requests = buffers.requestsBuffer(parent=self.window.tb, name="friend_requests", composefunc="render_person", session=self.session, count=1000)
self.buffers.append(incoming_requests)
self.window.insert_buffer(incoming_requests.tab, _(u"Pending requests"), self.window.search("requests"))
outgoing_requests = buffers.requestsBuffer(parent=self.window.tb, name="friend_requests_sent", composefunc="render_person", session=self.session, count=1000, out=1)
self.buffers.append(outgoing_requests)
self.window.insert_buffer(outgoing_requests.tab, _(u"I follow"), self.window.search("requests"))
chats = buffers.empty(parent=self.window.tb, name="chats")
self.buffers.append(chats)
self.window.add_buffer(chats.tab, _(u"Chats"))
@@ -116,20 +136,38 @@ class Controller(object):
pub.subscribe(self.update_status_bar, "update-status-bar")
pub.subscribe(self.chat_from_id, "new-chat")
pub.subscribe(self.authorisation_failed, "authorisation-failed")
pub.subscribe(self.user_profile, "user-profile")
pub.subscribe(self.user_online, "user-online")
pub.subscribe(self.user_offline, "user-offline")
pub.subscribe(self.notify, "notify")
pub.subscribe(self.handle_longpoll_read_timeout, "longpoll-read-timeout")
widgetUtils.connect_event(self.window, widgetUtils.CLOSE_EVENT, self.exit)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.update_buffer, menuitem=self.window.update_buffer)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.check_for_updates, menuitem=self.window.check_for_updates)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.window.about_dialog, menuitem=self.window.about)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.search_audios, menuitem=self.window.search_audios)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.search_videos, menuitem=self.window.search_videos)
widgetUtils.connect_event(self.window, widgetUtils.MENU,self.remove_buffer, menuitem=self.window.remove_buffer_)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.get_more_items, menuitem=self.window.load_previous_items)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.changelog, menuitem=self.window.changelog)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.configuration, menuitem=self.window.settings_dialog)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.new_timeline, menuitem=self.window.timeline)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.create_audio_album, menuitem=self.window.audio_album)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.delete_audio_album, menuitem=self.window.delete_audio_album)
# widgetUtils.connect_event(self.window, widgetUtils.MENU, self.create_audio_album, menuitem=self.window.audio_album)
# widgetUtils.connect_event(self.window, widgetUtils.MENU, self.delete_audio_album, menuitem=self.window.delete_audio_album)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.create_video_album, menuitem=self.window.video_album)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.delete_video_album, menuitem=self.window.delete_video_album)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.check_documentation, menuitem=self.window.documentation)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.menu_play_pause, menuitem=self.window.player_play)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.menu_play_next, menuitem=self.window.player_next)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.menu_play_previous, menuitem=self.window.player_previous)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.menu_play_all, menuitem=self.window.player_play_all)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.menu_stop, menuitem=self.window.player_stop)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.menu_volume_down, menuitem=self.window.player_volume_down)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.menu_volume_up, menuitem=self.window.player_volume_up)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.menu_mute, menuitem=self.window.player_mute)
pub.subscribe(self.get_chat, "order-sent-message")
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.view_my_profile, menuitem=self.window.view_profile)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.view_my_profile_in_browser, menuitem=self.window.open_in_browser)
def disconnect_events(self):
log.debug("Disconnecting some events...")
@@ -140,6 +178,9 @@ class Controller(object):
pub.unsubscribe(self.play_audios, "play-audios")
pub.unsubscribe(self.view_post, "open-post")
pub.unsubscribe(self.update_status_bar, "update-status-bar")
pub.unsubscribe(self.user_online, "user-online")
pub.unsubscribe(self.user_offline, "user-offline")
pub.unsubscribe(self.notify, "notify")
def authorisation_failed(self):
commonMessages.bad_authorisation()
@@ -154,13 +195,22 @@ class Controller(object):
self.window.change_status(_(u"Loading items for {0}").format(i.name,))
i.get_items()
self.window.change_status(_(u"Ready"))
self.longpool = longpoolthread.worker(self.session)
self.longpool.start()
self.status_setter = RepeatingTimer(900, self.set_online)
self.create_longpoll_thread()
self.status_setter = RepeatingTimer(280, self.set_online)
self.status_setter.start()
self.set_online()
self.create_unread_messages()
wx.CallAfter(self.get_audio_albums, self.session.user_id)
wx.CallAfter(self.get_video_albums, self.session.user_id)
def create_longpoll_thread(self, notify=False):
try:
self.longpoll = longpollthread.worker(self.session)
self.longpoll.start()
if notify:
self.notify(message=_(u"Chat server reconnected"))
except ConnectionError:
pub.sendMessage("longpoll-read-timeout")
def in_post(self, buffer):
buffer = self.search(buffer)
@@ -184,7 +234,7 @@ class Controller(object):
call_threaded(player.player.play, audio_object)
def play_audios(self, audios):
player.player.play_all(audios)
player.player.play_all(audios, shuffle=self.window.player_shuffle.IsChecked())
def view_post(self, post_object, controller_):
p = getattr(posts, controller_)(self.session, post_object)
@@ -193,6 +243,7 @@ class Controller(object):
def exit(self, *args, **kwargs):
log.debug("Receibed an exit signal. closing...")
self.set_offline()
self.disconnect_events()
self.window.Destroy()
wx.GetApp().ExitMainLoop()
@@ -214,17 +265,30 @@ class Controller(object):
dlg = searchDialogs.searchAudioDialog()
if dlg.get_response() == widgetUtils.OK:
q = dlg.get("term").encode("utf-8")
count = 300
auto_complete = dlg.get_checkable("auto_complete")
lyrics = dlg.get_checkable("lyrics")
performer_only = dlg.get_checkable("artist_only")
sort = dlg.get_sort_order()
newbuff = buffers.audioBuffer(parent=self.window.tb, name=u"{0}_audiosearch".format(q.decode("utf-8"),), session=self.session, composefunc="compose_audio", parent_endpoint="audio", endpoint="search", q=q, count=count, auto_complete=auto_complete, lyrics=lyrics, performer_only=performer_only, sort=sort)
newbuff = buffers.audioBuffer(parent=self.window.tb, name=u"{0}_audiosearch".format(q.decode("utf-8"),), session=self.session, composefunc="render_audio", parent_endpoint="audio", endpoint="search", q=q)
self.buffers.append(newbuff)
call_threaded(newbuff.get_items)
# Translators: {0} will be replaced with the search term.
self.window.insert_buffer(newbuff.tab, _(u"Search for {0}").format(q.decode("utf-8"),), self.window.search("audios"))
def search_videos(self, *args, **kwargs):
dlg = searchDialogs.searchVideoDialog()
if dlg.get_response() == widgetUtils.OK:
params = {}
params["q"] = dlg.get("term").encode("utf-8")
params["count"] = 200
hd = dlg.get_checkable("hd")
if hd != 0:
params["hd"] = 1
params["adult"] = dlg.get_checkable("safe_search")
params["sort"] = dlg.get_sort_order()
params["filters"] = "youtube, vimeo, short, long"
newbuff = buffers.videoBuffer(parent=self.window.tb, name=u"{0}_videosearch".format(params["q"].decode("utf-8"),), session=self.session, composefunc="render_video", parent_endpoint="video", endpoint="search", **params)
self.buffers.append(newbuff)
call_threaded(newbuff.get_items)
# Translators: {0} will be replaced with the search term.
self.window.insert_buffer(newbuff.tab, _(u"Search for {0}").format(params["q"].decode("utf-8"),), self.window.search("videos"))
def update_status_bar(self, status):
self.window.change_status(status)
@@ -269,17 +333,16 @@ class Controller(object):
if user_id == None:
commonMessages.no_user_exist()
return
print user_id
if buffertype == "audio":
buffer = buffers.audioBuffer(parent=self.window.tb, name="{0}_audio".format(user_id,), composefunc="compose_audio", session=self.session, endpoint="get", parent_endpoint="audio", full_list=True, count=self.session.settings["buffers"]["count_for_audio_buffers"], owner_id=user_id)
buffer = buffers.audioBuffer(parent=self.window.tb, name="{0}_audio".format(user_id,), composefunc="render_audio", session=self.session, endpoint="get", parent_endpoint="audio", owner_id=user_id)
# Translators: {0} will be replaced with an user.
name_ = _(u"{0}'s audios").format(self.session.get_user_name(user_id, "gen"),)
elif buffertype == "wall":
buffer = buffers.feedBuffer(parent=self.window.tb, name="{0}_feed".format(user_id,), composefunc="compose_status", session=self.session, endpoint="get", parent_endpoint="wall", extended=1, count=self.session.settings["buffers"]["count_for_wall_buffers"], owner_id=user_id)
buffer = buffers.feedBuffer(parent=self.window.tb, name="{0}_feed".format(user_id,), composefunc="render_status", session=self.session, endpoint="get", parent_endpoint="wall", extended=1, count=self.session.settings["buffers"]["count_for_wall_buffers"], owner_id=user_id)
# Translators: {0} will be replaced with an user.
name_ = _(u"{0}'s wall posts").format(self.session.get_user_name(user_id, "gen"),)
elif buffertype == "friends":
buffer = buffers.peopleBuffer(parent=self.window.tb, name="friends_{0}".format(user_id,), composefunc="compose_person", session=self.session, endpoint="get", parent_endpoint="friends", count=5000, fields="uid, first_name, last_name, last_seen", user_id=user_id)
buffer = buffers.peopleBuffer(parent=self.window.tb, name="friends_{0}".format(user_id,), composefunc="render_person", session=self.session, endpoint="get", parent_endpoint="friends", count=5000, fields="uid, first_name, last_name, last_seen", user_id=user_id)
# Translators: {0} will be replaced with an user.
name_ = _(u"{0}'s friends").format(self.session.get_user_name(user_id, "friends"),)
self.buffers.append(buffer)
@@ -308,7 +371,7 @@ class Controller(object):
self.window.change_buffer(pos)
return b.tab.text.SetFocus()
return
buffer = buffers.chatBuffer(parent=self.window.tb, name="{0}_messages".format(user_id,), composefunc="compose_message", session=self.session, count=200, user_id=user_id, rev=1)
buffer = buffers.chatBuffer(parent=self.window.tb, name="{0}_messages".format(user_id,), composefunc="render_message", session=self.session, count=200, user_id=user_id, rev=0)
self.buffers.append(buffer)
# Translators: {0} will be replaced with an user.
self.window.insert_buffer(buffer.tab, _(u"Chat with {0}").format(self.session.get_user_name(user_id, "ins")), self.window.search("chats"))
@@ -319,38 +382,85 @@ class Controller(object):
if setfocus: buffer.tab.text.SetFocus()
return True
def user_online(self, event):
if self.session.settings["chat"]["notify_online"] == False:
return
user_name = self.session.get_user_name(event.user_id, "nom")
msg = _(u"{0} is online.").format(user_name,)
sound = "friend_online.ogg"
self.notify(msg, sound, self.session.settings["chat"]["notifications"])
def user_offline(self, event):
if self.session.settings["chat"]["notify_offline"] == False:
return
user_name = self.session.get_user_name(event.user_id, "nom")
msg = _(u"{0} is offline.").format(user_name,)
sound = "friend_offline.ogg"
self.notify(msg, sound, self.session.settings["chat"]["notifications"])
def get_chat(self, obj=None):
""" Searches or creates a chat buffer with the id of the user that is sending or receiving a message.
obj vk.longpool.event: an event wich defines some data from the vk's longpool server."""
# Set user_id to the id of the friend wich is receiving or sending the message.
obj.user_id = obj.from_id
buffer = self.search_chat_buffer(obj.user_id)
obj vk_api.longpoll.EventType: an event wich defines some data from the vk's long poll server."""
# If someone else sends a message to the current user.
if obj.to_me:
buffer = self.search_chat_buffer(obj.user_id)
uid = obj.user_id
# If the current user sends a message to someone else.
else:
buffer = self.search_chat_buffer(obj.peer_id)
uid = obj.peer_id
# If there is no buffer, we must create one in a wxThread so it will not crash.
if buffer == None:
wx.CallAfter(self.chat_from_id, obj.user_id)
self.session.soundplayer.play("chat.ogg")
wx.CallAfter(self.chat_from_id, uid, setfocus=self.session.settings["chat"]["automove_to_conversations"])
self.session.soundplayer.play("conversation_opened.ogg")
return
# If the chat already exists, let's create a dictionary wich will contains data of the received message.
message = {"id": obj.message_id, "user_id": obj.user_id, "date": obj.timestamp, "body": obj.text, "attachments": obj.attachments}
# If outbox it's true, it means that message["from_id"] should be the current user. If not, the obj.user_id should be taken.
if obj.message_flags.has_key("outbox") == True:
message = {"id": obj.message_id, "user_id": uid, "date": obj.timestamp, "body": obj.text, "attachments": obj.attachments}
# if attachments is true, let's request for the full message with attachments formatted in a better way.
# Todo: code improvements. We shouldn't need to request the same message again just for these attachments.
if len(message["attachments"]) != 0:
message_ids = message["id"]
results = self.session.vk.client.messages.getById(message_ids=message_ids)
message = results["items"][0]
if obj.from_me:
message["from_id"] = self.session.user_id
else:
message["from_id"] = obj.from_id
message["from_id"] = obj.user_id
data = [message]
# Let's add this to the buffer.
# ToDo: Clean this code and test how is the database working with this set to True.
num = self.session.order_buffer(buffer.name, data, True)
buffer.insert(self.session.db[buffer.name]["items"][-1], False)
self.session.soundplayer.play("chat.ogg")
self.session.soundplayer.play("message_received.ogg")
# Check if we have to read the message aloud
if buffer == self.get_current_buffer():
rendered_message = renderers.render_message(message, self.session)
output.speak(rendered_message[0])
def set_online(self):
try:
r = self.session.vk.client.account.setOnline()
except:
log.error("Error in setting online for the current user")
self.window.notify("Socializer", "online now!")
def set_offline(self):
try:
r = self.session.vk.client.account.setOffline()
except:
log.error("Error in setting offline status for the current user")
def create_unread_messages(self):
msgs = self.session.vk.client.messages.getDialogs(count=200, unread=1)
if self.session.settings["chat"]["open_unread_conversations"] == False:
return
try:
log.debug("Getting possible unread messages.")
msgs = self.session.vk.client.messages.getDialogs(count=200, unread=1)
except VkApiError as ex:
if ex.code == 6:
log.exception("Something went wrong when getting messages. Waiting a second to retry")
time.sleep(2)
return self.create_unread_messages()
for i in msgs["items"]:
wx.CallAfter(self.chat_from_id, i["message"]["user_id"], setfocus=False)
@@ -365,10 +475,19 @@ class Controller(object):
response = self.session.vk.client.messages.markAsRead(message_ids=ids)
def get_audio_albums(self, user_id=None):
albums = self.session.vk.client.audio.getAlbums(owner_id=user_id)
self.session.audio_albums = albums["items"]
for i in albums["items"]:
buffer = buffers.audioAlbum(parent=self.window.tb, name="{0}_audio_album".format(i["id"],), composefunc="compose_audio", session=self.session, endpoint="get", parent_endpoint="audio", full_list=True, count=self.session.settings["buffers"]["count_for_audio_buffers"], user_id=user_id, album_id=i["id"])
try:
log.debug("Create audio albums...")
albums = self.session.vk.client_audio.get_albums(owner_id=user_id)
except VkApiError as ex:
if ex.code == 6:
log.exception("Something went wrong when getting albums. Waiting a second to retry")
time.sleep(2)
return self.get_audio_albums(user_id=user_id)
elif ex.code == 10:
return
self.session.audio_albums = albums
for i in albums:
buffer = buffers.audioAlbum(parent=self.window.tb, name="{0}_audio_album".format(i["id"],), composefunc="render_audio", session=self.session, endpoint="get", parent_endpoint="audio", owner_id=user_id, album_id=i["id"])
buffer.can_get_items = False
# Translators: {0} Will be replaced with an audio album's title.
name_ = _(u"Album: {0}").format(i["title"],)
@@ -376,6 +495,28 @@ class Controller(object):
self.window.insert_buffer(buffer.tab, name_, self.window.search("albums"))
buffer.get_items()
# inserts a pause of 1 second here, so we'll avoid errors 6 in VK.
time.sleep(0.3)
def get_video_albums(self, user_id=None):
try:
log.debug("Create video albums...")
albums = self.session.vk.client.video.getAlbums(owner_id=user_id)
except VkApiError as ex:
if ex.code == 6:
log.exception("Something went wrong when getting albums. Waiting a second to retry")
time.sleep(2)
return self.get_audio_albums(user_id=user_id)
self.session.video_albums = albums["items"]
for i in albums["items"]:
buffer = buffers.videoAlbum(parent=self.window.tb, name="{0}_video_album".format(i["id"],), composefunc="render_video", session=self.session, endpoint="get", parent_endpoint="video", count=self.session.settings["buffers"]["count_for_video_buffers"], user_id=user_id, album_id=i["id"])
buffer.can_get_items = False
# Translators: {0} Will be replaced with a video album's title.
name_ = _(u"Album: {0}").format(i["title"],)
self.buffers.append(buffer)
self.window.insert_buffer(buffer.tab, name_, self.window.search("video_albums"))
buffer.get_items()
# inserts a pause of 1 second here, so we'll avoid errors 6 in VK.
time.sleep(0.3)
def create_audio_album(self, *args, **kwargs):
d = creation.audio_album()
@@ -383,7 +524,7 @@ class Controller(object):
response = self.session.vk.client.audio.addAlbum(title=d.get("title"))
if response.has_key("album_id") == False: return
album_id = response["album_id"]
buffer = buffers.audioAlbum(parent=self.window.tb, name="{0}_audio_album".format(album_id,), composefunc="compose_audio", session=self.session, endpoint="get", parent_endpoint="audio", full_list=True, count=self.session.settings["buffers"]["count_for_audio_buffers"], user_id=self.session.user_id, album_id=album_id)
buffer = buffers.audioAlbum(parent=self.window.tb, name="{0}_audio_album".format(album_id,), composefunc="render_audio", session=self.session, endpoint="get", parent_endpoint="audio", full_list=True, count=self.session.settings["buffers"]["count_for_audio_buffers"], user_id=self.session.user_id, album_id=album_id)
buffer.can_get_items = False
# Translators: {0} will be replaced with an audio album's title.
name_ = _(u"Album: {0}").format(d.get("title"),)
@@ -393,7 +534,7 @@ class Controller(object):
self.session.audio_albums = self.session.vk.client.audio.getAlbums(owner_id=self.session.user_id)["items"]
def delete_audio_album(self, *args, **kwargs):
answer = selector.audioAlbum(_(u"Select the album you want to delete"), self.session)
answer = selector.album(_(u"Select the album you want to delete"), self.session)
if answer.item == None:
return
response = commonMessages.delete_audio_album()
@@ -406,8 +547,106 @@ class Controller(object):
del buffer
self.session.audio_albums = self.session.vk.client.audio.getAlbums(owner_id=self.session.user_id)["items"]
def create_video_album(self, *args, **kwargs):
d = creation.audio_album()
if d.get_response() == widgetUtils.OK and d.get("title") != "":
response = self.session.vk.client.video.addAlbum(title=d.get("title"))
if response.has_key("album_id") == False: return
album_id = response["album_id"]
buffer = buffers.videoAlbum(parent=self.window.tb, name="{0}_video_album".format(album_id,), composefunc="render_video", session=self.session, endpoint="get", parent_endpoint="video", count=self.session.settings["buffers"]["count_for_video_buffers"], user_id=self.session.user_id, album_id=album_id)
buffer.can_get_items = False
# Translators: {0} will be replaced with a video album's title.
name_ = _(u"Album: {0}").format(d.get("title"),)
self.buffers.append(buffer)
self.window.insert_buffer(buffer.tab, name_, self.window.search("video_albums"))
buffer.get_items()
self.session.video_albums = self.session.vk.client.video.getAlbums(owner_id=self.session.user_id)["items"]
def delete_video_album(self, *args, **kwargs):
answer = selector.album(_(u"Select the album you want to delete"), self.session, "video_albums")
if answer.item == None:
return
response = commonMessages.delete_audio_album()
if response != widgetUtils.YES: return
removal = self.session.vk.client.video.deleteAlbum(album_id=answer.item)
buffer = self.search("{0}_video_album".format(answer.item,))
buff = self.window.search(buffer.name)
self.window.remove_buffer(buff)
self.buffers.remove(buffer)
del buffer
self.session.video_albums = self.session.vk.client.video.getAlbums(owner_id=self.session.user_id)["items"]
def check_documentation(self, *args, **kwargs):
lang = localization.get("documentation")
os.chdir("documentation/%s" % (lang,))
webbrowser.open("manual.html")
os.chdir("../../")
def menu_play_pause(self, *args, **kwargs):
if player.player.check_is_playing() != False:
return player.player.pause()
b = self.get_current_buffer()
if hasattr(b, "play_next"):
b.play_audio()
else:
b = self.search("me_audio")
b.play_audio()
def menu_play_next(self, *args, **kwargs):
b = self.get_current_buffer()
if hasattr(b, "play_next"):
b.play_next()
else:
self.search("me_audio").play_next()
def menu_play_previous(self, *args, **kwargs):
b = self.get_current_buffer()
if hasattr(b, "play_previous"):
b.play_previous()
else:
self.search("me_audio").play_previous()
def menu_play_all(self, *args, **kwargs):
b = self.get_current_buffer()
if hasattr(b, "play_all"):
b.play_all()
else:
self.search("me_audio").play_all()
def menu_stop(self, *args, **kwargs):
player.player.stop()
def menu_volume_down(self, *args, **kwargs):
player.player.volume = player.player.volume-5
def menu_volume_up(self, *args, **kwargs):
player.player.volume = player.player.volume+5
def menu_mute(self, *args, **kwargs):
player.player.volume = 0
def user_profile(self, person):
p = profiles.userProfile(self.session, person)
def view_my_profile(self, *args, **kwargs):
self.user_profile(self.session.user_id)
def view_my_profile_in_browser(self, *args, **kwargs):
webbrowser.open_new_tab("https://vk.com/id{id}".format(id=self.session.user_id,))
def notify(self, message="", sound="", type="native"):
if type == "native":
self.window.notify(_("Socializer"), message)
else:
if sound != "":
self.session.soundplayer.play(sound)
if message != "":
output.speak(message)
def handle_longpoll_read_timeout(self):
if hasattr(self, "longpoll"):
self.notify(message=_(u"Chat disconnected. Trying to connect in 60 seconds"))
time.sleep(60)
if hasattr(self, "longpoll"):
del self.longpoll
self.create_longpoll_thread(notify=True)

View File

@@ -1,19 +1,25 @@
# -*- coding: utf-8 -*-
import time
import widgetUtils
import output
from pubsub import pub
import attach
from wxUI.dialogs import message
from wxUI.dialogs import message, selector
from extra import SpellChecker, translator
from logging import getLogger
log = getLogger("controller.message")
class post(object):
def __init__(self, title, caption, text, post_type="post"):
def __init__(self, session, title, caption, text, post_type="post"):
super(post, self).__init__()
self.session = session
self.title = title
self.message = getattr(message, post_type)(title, caption, text)
self.message.set_title(title)
widgetUtils.connect_event(self.message.spellcheck, widgetUtils.BUTTON_PRESSED, self.spellcheck)
widgetUtils.connect_event(self.message.translateButton, widgetUtils.BUTTON_PRESSED, self.translate)
widgetUtils.connect_event(self.message.mention, widgetUtils.BUTTON_PRESSED, self.mention)
self.images = []
if hasattr(self.message, "attach"):
widgetUtils.connect_event(self.message.attach, widgetUtils.BUTTON_PRESSED, self.show_attach_dialog)
@@ -26,13 +32,31 @@ class post(object):
privacy = 1
return privacy
def mention(self, *args, **kwargs):
try:
fields = "id, first_name, last_name"
friends = self.session.vk.client.friends.get(count=5000, fields=fields)
except AttributeError:
time.sleep(2)
log.exception("Error retrieving friends...")
return self.mention(*args, **kwargs)
users = []
for i in friends["items"]:
users.append(u"{0} {1}".format(i["first_name"], i["last_name"]))
select = selector.selectPeople(users)
if select.get_response() == widgetUtils.OK and select.users.GetCount() > 0:
self.tagged_people = []
tagged_users = select.get_all_users()
for i in tagged_users:
self.tagged_people.append(u"[id%s|%s]" % (str(friends["items"][i]["id"]), friends["items"][i]["first_name"]))
self.message.text.SetValue(self.message.text.GetValue()+ u", ".join(self.tagged_people))
def translate(self, *args, **kwargs):
dlg = translator.gui.translateDialog()
if dlg.get_response() == widgetUtils.OK:
text_to_translate = self.message.get_text()
source = [x[0] for x in translator.translator.available_languages()][dlg.get("source_lang")]
dest = [x[0] for x in translator.translator.available_languages()][dlg.get("dest_lang")]
msg = translator.translator.translate(text_to_translate, source, dest)
msg = translator.translator.translate(text_to_translate, dest)
self.message.set_text(msg)
self.message.text_focus()
output.speak(_(u"Translated"))
@@ -46,11 +70,11 @@ class post(object):
checker.clean()
def show_attach_dialog(self, *args, **kwargs):
a = attach.attach()
a = attach.attachFromLocal()
if len(a.attachments) != 0:
self.attachments = a.attachments
class comment(post):
def __init__(self, title, caption, text):
super(comment, self).__init__(title, caption, text, "comment")
def __init__(self, session, title, caption, text):
super(comment, self).__init__(session, title, caption, text, "comment")
self.message.set_title(_(u"New comment"))

View File

@@ -1,11 +1,16 @@
# -*- coding: utf-8 -*-
import random
import output
import sound_lib
import logging
from sound_lib.stream import URLStream
from sound_lib.main import BassError
from mysc.repeating_timer import RepeatingTimer
from pubsub import pub
player = None
log = logging.getLogger("player")
def setup():
global player
@@ -22,9 +27,13 @@ class audioPlayer(object):
self.queue = []
self.stopped = True
def play(self, url):
def play(self, url, set_info=True):
if self.stream != None and self.stream.is_playing == True:
self.stream.stop()
try:
self.stream.stop()
except BassError:
log.exception("error when stopping the file")
self.stream = None
self.stopped = True
if hasattr(self, "worker") and self.worker != None:
self.worker.cancel()
@@ -33,10 +42,15 @@ class audioPlayer(object):
# Make sure that there are no other sounds trying to be played.
if self.is_working == False:
self.is_working = True
self.stream = URLStream(url=url["url"])
try:
self.stream = URLStream(url=url["url"])
except BassError:
log.debug("Error when playing the file %r") % (url,)
return
# Translators: {0} will be replaced with a song's title and {1} with the artist.
msg = _(u"Playing {0} by {1}").format(url["title"], url["artist"])
pub.sendMessage("update-status-bar", status=msg)
if set_info:
msg = _(u"Playing {0} by {1}").format(url["title"], url["artist"])
pub.sendMessage("update-status-bar", status=msg)
self.stream.volume = self.vol/100.0
self.stream.play()
self.stopped = False
@@ -57,8 +71,11 @@ class audioPlayer(object):
self.stream.pause()
self.stopped = True
else:
self.stream.play()
self.stopped = False
try:
self.stream.play()
self.stopped = False
except BassError:
pass
@property
def volume(self):
@@ -72,9 +89,11 @@ class audioPlayer(object):
if self.stream != None:
self.stream.volume = self.vol/100.0
def play_all(self, list_of_urls):
def play_all(self, list_of_urls, shuffle=False):
self.stop()
self.queue = list_of_urls
if shuffle:
random.shuffle(self.queue)
self.play(self.queue[0])
self.queue.remove(self.queue[0])
self.worker = RepeatingTimer(5, self.player_function)
@@ -87,3 +106,12 @@ class audioPlayer(object):
return
self.play(self.queue[0])
self.queue.remove(self.queue[0])
def check_is_playing(self):
if self.stream == None:
return False
if self.stream != None and self.stream.is_playing == False:
return False
else:
return True

View File

@@ -1,17 +1,21 @@
# -*- coding: utf-8 -*-
import re
import os
import cStringIO
import threading
import arrow
import messages
import requests
import languageHandler
import widgetUtils
import output
import wx
import webbrowser
import utils
import logging
from sessionmanager import session # We'll use some functions from there
from sessionmanager import utils
from pubsub import pub
from wxUI.dialogs import postDialogs, urlList
from wxUI.dialogs import postDialogs, urlList, profiles
from extra import SpellChecker, translator
from mysc.thread_utils import call_threaded
from wxUI import menus
@@ -23,31 +27,9 @@ def get_user(id, profiles):
for i in profiles:
if i["id"] == id:
return u"{0} {1}".format(i["first_name"], i["last_name"])
# Translators: This string is user when socializer can't find the right user information.
# Translators: This string is used when socializer can't find the right user information.
return _(u"Unknown username")
def add_attachment(attachment):
msg = u""
tpe = ""
if attachment["type"] == "link":
msg = u"{0}: {1}".format(attachment["link"]["title"], attachment["link"]["url"])
tpe = _(u"Link")
elif attachment["type"] == "photo":
tpe = _(u"Photo")
msg = attachment["photo"]["text"]
if msg == "":
msg = _(u"no description available")
elif attachment["type"] == "video":
msg = u"{0}".format(attachment["video"]["title"],)
tpe = _(u"Video")
elif attachment["type"] == "audio":
msg = u"{0}".format(" ".join(session.compose_audio(attachment["audio"])))
tpe = _(u"Audio")
elif attachment["type"] == "doc":
msg = u"{0}".format(attachment["doc"]["title"])
tpe = _(u"{0} file").format(attachment["doc"]["ext"])
return [tpe, msg]
def get_message(status):
message = ""
if status.has_key("text"):
@@ -55,6 +37,8 @@ def get_message(status):
return message
class postController(object):
""" Base class for post representation."""
def __init__(self, session, postObject):
super(postController, self).__init__()
self.session = session
@@ -79,29 +63,43 @@ class postController(object):
widgetUtils.connect_event(self.dialog.repost, widgetUtils.BUTTON_PRESSED, self.post_repost)
# self.dialog.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.show_menu, self.dialog.comments.list)
# self.dialog.Bind(wx.EVT_LIST_KEY_DOWN, self.show_menu_by_key, self.dialog.comments.list)
call_threaded(self.load_all_components)
# if self.post.has_key("attachments"): print self.post["attachments"]
self.worker = threading.Thread(target=self.load_all_components)
self.worker.finished = threading.Event()
self.worker.start()
self.attachments = []
self.load_images = False
# We'll put images here, so it will be easier to work with them.
self.images = []
self.imageIndex = 0
def get_comments(self):
""" Get comments and insert them in a list."""
user = self.post[self.user_identifier]
id = self.post[self.post_identifier]
self.comments = self.session.vk.client.wall.getComments(owner_id=user, post_id=id, need_likes=1, count=100, extended=1, preview_length=0)
comments_ = []
for i in self.comments["items"]:
# If comment has a "deleted" key it should not be displayed, obviously.
if "deleted" in i:
continue
from_ = get_user(i["from_id"], self.comments["profiles"])
if i.has_key("reply_to_user"):
extra_info = get_user(i["reply_to_user"], self.comments["profiles"])
from_ = _(u"{0} Has replied to {1}").format(from_, extra_info)
if len(i["text"]) > 140:
text = i["text"][:141]
from_ = _(u"{0} > {1}").format(from_, extra_info)
# As we set the comment reply properly in the from_ field, let's remove the first username from here if it exists.
fixed_text = re.sub("^\[id\d+\|\D+\], ", "", i["text"])
if len(fixed_text) > 140:
text = fixed_text[:141]
else:
text = i["text"]
text = fixed_text
original_date = arrow.get(i["date"])
created_at = original_date.humanize(locale=languageHandler.getLanguage())
likes = str(i["likes"]["count"])
comments_.append((from_, text, created_at, likes))
self.dialog.insert_comments(comments_)
try:
self.dialog.insert_comments(comments_)
except wx.PyDeadObjectError:
pass
def get_post_information(self):
from_ = self.session.get_user_name(self.post[self.user_identifier])
@@ -110,7 +108,7 @@ class postController(object):
title = _(u"repost from {0}").format(from_,)
else:
if self.post.has_key("from_id") and self.post.has_key("owner_id"):
# Translators: {0} will be replaced with the user who is posting, and {2} with the wall owner.
# Translators: {0} will be replaced with the user who is posting, and {1} with the wall owner.
title = _(u"Post from {0} in the {1}'s wall").format(self.session.get_user_name(self.post["from_id"]), self.session.get_user_name(self.post["owner_id"]))
else:
title = _(u"Post from {0}").format(from_,)
@@ -125,6 +123,7 @@ class postController(object):
message += nm
self.dialog.set_post(message)
self.get_attachments(self.post)
self.check_image_load()
def get_attachments(self, post):
attachments = []
@@ -133,24 +132,78 @@ class postController(object):
# We don't need the photos_list attachment, so skip it.
if i["type"] == "photos_list":
continue
attachments.append(add_attachment(i))
if i["type"] == "photo":
if self.load_images == False: self.load_images = True
self.images.append(i)
attachments.append(utils.add_attachment(i))
self.attachments.append(i)
# Links in text are not treated like normal attachments, so we'll have to catch and add those to the list without title
# We can't get a title because title is provided by the VK API and it will not work for links as simple text.
urls = utils.find_urls_in_text(self.dialog.get("post_view"))
print urls
if len(urls) > 0:
links = []
for i in urls:
links.append({"link": {"title": _(U"Untitled link"), "url": i}, "type": "link"})
for i in links:
attachments.append(add_attachment(i))
attachments.append(utils.add_attachment(i))
self.attachments.append(i)
if len(self.attachments) > 0:
self.dialog.attachments.list.Enable(True)
self.dialog.attachments.list.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.open_attachment)
self.dialog.insert_attachments(attachments)
def check_image_load(self):
if self.load_images and len(self.images) > 0 and self.session.settings["general"]["load_images"]:
self.dialog.image.Enable(True)
nav = False # Disable navigation controls in photos
if len(self.images) > 1:
nav = True
widgetUtils.connect_event(self.dialog.previous_photo, widgetUtils.BUTTON_PRESSED, self.set_previous_image)
widgetUtils.connect_event(self.dialog.next_photo, widgetUtils.BUTTON_PRESSED, self.set_next_image)
self.dialog.enable_photo_controls(navigation=nav)
self.set_image(0)
def set_next_image(self, *args, **kwargs):
if self.imageIndex < -1 or self.imageIndex == len(self.images)-1:
self.imageIndex = -1
if len(self.images) <= self.imageIndex+1:
self.imageIndex = 0
else:
self.imageIndex = self.imageIndex + 1
self.set_image(self.imageIndex)
def set_previous_image(self, *args, **kwargs):
if self.imageIndex <= 0:
self.imageIndex = len(self.images)
self.imageIndex = self.imageIndex - 1
self.set_image(self.imageIndex)
def set_image(self, index):
if len(self.images) < index-1:
log.exception("Error in loading image {0} in a list with {1} images".format(index, len(self.images)))
return
# Get's photo URL.
url = self.get_photo_url(self.images[index]["photo"], "x")
if url != "":
img = requests.get(url)
image = wx.Image(stream=cStringIO.StringIO(requests.get(url).content))
try:
self.dialog.image.SetBitmap(wx.Bitmap(image))
except NameError:
return
self.dialog.SetClientSize(self.dialog.sizer.CalcMin())
# Translators: {0} is the number of the current photo and {1} is the total number of photos.
output.speak(_(u"Loaded photo {0} of {1}").format(index+1, len(self.images)))
return
def get_photo_url(self, photo, size="x"):
url = ""
for i in photo["sizes"]:
if i["type"] == size:
url = i["url"]
break
return url
def load_all_components(self):
self.get_post_information()
self.get_likes()
@@ -192,19 +245,25 @@ class postController(object):
def post_repost(self, *args, **kwargs):
object_id = "wall{0}_{1}".format(self.post[self.user_identifier], self.post[self.post_identifier])
p = messages.post(title=_(u"Repost"), caption=_(u"Add your comment here"), text="")
p = messages.post(session=self.session, title=_(u"Repost"), caption=_(u"Add your comment here"), text="")
if p.message.get_response() == widgetUtils.OK:
msg = p.message.get_text().encode("utf-8")
self.session.vk.client.wall.repost(object=object_id, message=msg)
def get_likes(self):
self.dialog.set_likes(self.post["likes"]["count"])
try:
self.dialog.set_likes(self.post["likes"]["count"])
except wx.PyDeadObjectError:
pass
def get_reposts(self):
self.dialog.set_shares(self.post["reposts"]["count"])
try:
self.dialog.set_shares(self.post["reposts"]["count"])
except wx.PyDeadObjectError:
pass
def add_comment(self, *args, **kwargs):
comment = messages.comment(title=_(u"Add a comment"), caption="", text="")
comment = messages.comment(session=self.session, title=_(u"Add a comment"), caption="", text="")
if comment.message.get_response() == widgetUtils.OK:
msg = comment.message.get_text().encode("utf-8")
try:
@@ -216,7 +275,7 @@ class postController(object):
self.clear_comments_list()
self.get_comments()
except Exception as msg:
print msg
log.error(msg)
def clear_comments_list(self):
self.dialog.comments.clear()
@@ -258,9 +317,8 @@ class postController(object):
dlg = translator.gui.translateDialog()
if dlg.get_response() == widgetUtils.OK:
text_to_translate = self.dialog.post_view.GetValue().encode("utf-8")
source = [x[0] for x in translator.translator.available_languages()][dlg.get("source_lang")]
dest = [x[0] for x in translator.translator.available_languages()][dlg.get("dest_lang")]
msg = translator.translator.translate(text_to_translate, source, dest)
msg = translator.translator.translate(text_to_translate, target=dest)
self.dialog.post_view.ChangeValue(msg)
output.speak(_(u"Translated"))
else:
@@ -272,22 +330,6 @@ class postController(object):
if hasattr(checker, "fixed_text"):
self.dialog.post_view.ChangeValue(checker.fixed_text)
def open_url(self, *args, **kwargs):
text = self.dialog.post_view.GetValue()
urls = find_urls(text)
url = None
if len(urls) == 0: return
if len(urls) == 1:
url = urls[0]
elif len(urls) > 1:
url_list = urlList.urlList()
url_list.populate_list(urls)
if url_list.get_response() == widgetUtils.OK:
url = urls[url_list.get_item()]
if url != None:
output.speak(_(u"Opening URL..."), True)
webbrowser.open_new_tab(url)
def open_attachment(self, *args, **kwargs):
index = self.dialog.attachments.get_selected()
attachment = self.attachments[index]
@@ -321,13 +363,16 @@ class postController(object):
for i in possible_sizes:
if attachment["photo"].has_key("photo_{0}".format(i,)):
url = attachment["photo"]["photo_{0}".format(i,)]
break
if url != "":
webbrowser.open_new_tab(url)
else:
print attachment["photo"].keys()
else:
log.debug("Unhandled attachment: %r" % (attachment,))
def __del__(self):
if hasattr(self, "worker"):
self.worker.finished.set()
class comment(object):
def __init__(self, session, comment_object):
super(comment, self).__init__()
@@ -462,3 +507,107 @@ class friendship(object):
def set_friends_list(self, friendslist):
for i in friendslist:
self.dialog.friends.insert_item(False, *[i])
class userProfile(object):
def __init__(self, session, user_id):
self.person = None
self.session = session
self.user_id = user_id
self.dialog = profiles.userProfile(title=_(u"Profile"))
self.dialog.create_controls("main_info")
self.dialog.realice()
self.get_basic_information()
if self.person != None:
self.dialog.get_response()
def get_basic_information(self):
""" Gets and inserts basic user information.
See https://vk.com/dev/users.get"""
fields = "first_name, last_name, bdate, city, country, home_town, photo_200_orig, online, site, status, last_seen, occupation, relation, relatives, personal, connections, activities, interests, music, movies, tv, books, games, about, quotes, can_write_private_message"
person = self.session.vk.client.users.get(user_ids=self.user_id, fields=fields)
if len(person) == 0:
return output.speak(_(u"Information for groups is not supported, yet."))
person = person[0]
print person
# Gets full name.
n = u"{0} {1}".format(person["first_name"], person["last_name"])
# Gets birthdate.
if person.has_key("bdate") and person["bdate"] != "":
self.dialog.main_info.enable("bdate")
if len(person["bdate"]) <= 5:
d = arrow.get(person["bdate"], "D.m")
self.dialog.main_info.set("bdate", d.format(_(u"MMMM D"), locale=languageHandler.getLanguage()))
else:
d = arrow.get(person["bdate"], "D.M.YYYY")
self.dialog.main_info.set("bdate", d.format(_(u"MMMM D, YYYY"), locale=languageHandler.getLanguage()))
# Gets current city and home town
city = ""
if person.has_key("home_town") and person["home_town"] != "":
home_town = person["home_town"]
self.dialog.main_info.enable("home_town")
self.dialog.main_info.set("home_town", home_town)
if person.has_key("city") and len(person["city"]) > 0:
city = person["city"]["title"]
if person.has_key("country") and person["country"] != "":
if city != "":
city = city+u", {0}".format(person["country"]["title"])
else:
city = person["country"]["title"]
self.dialog.main_info.enable("city")
self.dialog.main_info.set("city", city)
self.dialog.main_info.set("name", n)
self.dialog.SetTitle(_(u"{name}'s profile").format(name=n,))
# Gets website
if person.has_key("site") and person["site"] != "":
self.dialog.main_info.enable("website")
self.dialog.main_info.set("website", person["site"])
self.dialog.main_info.enable("go_site")
widgetUtils.connect_event(self.dialog.main_info.go_site, widgetUtils.BUTTON_PRESSED, self.visit_website)
if person.has_key("status") and person["status"] != "":
self.dialog.main_info.enable("status")
self.dialog.main_info.set("status", person["status"])
if person.has_key("occupation") and person["occupation"] != None:
if person["occupation"]["type"] == "work": c1 = _(u"Work ")
elif person["occupation"]["type"] == "school": c1 = _(u"Student ")
elif person["occupation"]["type"] == "university": c1 = _(u"Student ")
if person["occupation"].has_key("name") and person["occupation"]["name"] != "":
c2 = _(u"In {0}").format(person["occupation"]["name"],)
else:
c2 = ""
self.dialog.main_info.enable("occupation")
self.dialog.main_info.set("occupation", c1+c2)
if person.has_key("relation") and person["relation"] != 0:
print person["relation"]
if person["relation"] == 1:
r = _(u"Single")
elif person["relation"] == 2:
if person.has_key("relation_partner"):
r = _(u"Dating with {0} {1}").format(person["relation_partner"]["first_name"], person["relation_partner"]["last_name"])
else:
r = _(u"Dating")
elif person["relation"] == 3:
r = _(u"Engaged with {0} {1}").format(person["relation_partner"]["first_name"], person["relation_partner"]["last_name"])
elif person["relation"] == 4:
r = _(u"Married with {0} {1}").format(person["relation_partner"]["first_name"], person["relation_partner"]["last_name"])
elif person["relation"] == 5:
r = _(u"It's complicated")
elif person["relation"] == 6:
r = _(u"Actively searching")
elif person["relation"] == 7:
r = _(u"In love")
self.dialog.main_info.enable("relation")
self.dialog.main_info.relation.SetLabel(_(u"Relationship: ")+r)
if person.has_key("last_seen") and person["last_seen"] != False:
original_date = arrow.get(person["last_seen"]["time"])
# Translators: This is the date of last seen
last_seen = _(u"{0}").format(original_date.humanize(locale=languageHandler.getLanguage()),)
self.dialog.main_info.enable("last_seen")
self.dialog.main_info.set("last_seen", last_seen)
log.info("getting info...")
self.person = person
self.dialog.SetClientSize(self.dialog.sizer.CalcMin())
def visit_website(self, *args, **kwargs):
output.speak(_(u"Opening website..."))
webbrowser.open_new_tab(self.person["site"])

161
src/controller/profiles.py Normal file
View File

@@ -0,0 +1,161 @@
# -*- coding: utf-8 -*-
""" A profile viewer and editor for VK user objects."""
import cStringIO
import webbrowser
import logging
import arrow
import requests
import languageHandler
import widgetUtils
import output
import wx
from wxUI.dialogs import urlList, profiles
from sessionmanager import utils
log = logging.getLogger("controller.profiles")
class userProfile(object):
""" Main controller to view an user profile. This controller will retrieve needed data from the VK website and display it appropiately."""
def __init__(self, session, user_id):
""" Default constructor:
@session vk.session: The main session object, capable of calling VK methods.
@user_id integer: User ID to retrieve information of.
At the current time, only users (and not communities) are supported.
"""
# self.person will hold a reference to the user object when retrieved from VK.
self.person = None
self.session = session
self.user_id = user_id
self.dialog = profiles.userProfile(title=_(u"Profile"))
self.dialog.create_controls("main_info")
self.dialog.realice()
self.get_basic_information()
if self.person != None:
self.dialog.get_response()
def get_basic_information(self):
""" Gets and inserts basic user information.
See https://vk.com/dev/users.get"""
# List of fields (information) to retrieve. For a list of fields available for user objects,
# see https://vk.com/dev/fields
fields = "first_name, last_name, bdate, city, country, home_town, photo_200_orig, online, site, status, last_seen, occupation, relation, relatives, personal, connections, activities, interests, music, movies, tv, books, games, about, quotes, can_write_private_message"
# ToDo: this method supports multiple user IDS, I'm not sure if this may be of any help for profile viewer.
person = self.session.vk.client.users.get(user_ids=self.user_id, fields=fields)
# If VK does not return anything it is very likely we have found a community.
if len(person) == 0:
return output.speak(_(u"Information for groups is not supported, yet."))
person = person[0]
# toDo: remove this print when I will be done with creation of profile viewer logic.
print(person)
# From this part we will format data from VK so users will see it in the GUI control.
# Format full name.
n = u"{0} {1}".format(person["first_name"], person["last_name"])
# Format birthdate.
if person.has_key("bdate") and person["bdate"] != "":
self.dialog.main_info.enable("bdate")
# VK can display dd.mm or dd.mm.yyyy birthdates. So let's compare the string lenght to handle both cases accordingly.
if len(person["bdate"]) <= 5: # dd.mm
d = arrow.get(person["bdate"], "D.M")
self.dialog.main_info.set("bdate", d.format(_(u"MMMM D"), locale=languageHandler.getLanguage()))
else: # mm.dd.yyyy
d = arrow.get(person["bdate"], "D.M.YYYY")
self.dialog.main_info.set("bdate", d.format(_(u"MMMM D, YYYY"), locale=languageHandler.getLanguage()))
# Format current city and home town
city = ""
if person.has_key("home_town") and person["home_town"] != "":
home_town = person["home_town"]
self.dialog.main_info.enable("home_town")
self.dialog.main_info.set("home_town", home_town)
if person.has_key("city") and len(person["city"]) > 0:
city = person["city"]["title"]
if person.has_key("country") and person["country"] != "":
if city != "":
city = city+u", {0}".format(person["country"]["title"])
else:
city = person["country"]["title"]
self.dialog.main_info.enable("city")
self.dialog.main_info.set("city", city)
self.dialog.main_info.set("name", n)
self.dialog.SetTitle(_(u"{name}'s profile").format(name=n,))
# Format website (or websites, if there are multiple of them).
if person.has_key("site") and person["site"] != "":
self.dialog.main_info.enable("website")
self.dialog.main_info.set("website", person["site"])
self.dialog.main_info.enable("go_site")
widgetUtils.connect_event(self.dialog.main_info.go_site, widgetUtils.BUTTON_PRESSED, self.visit_website)
# Format status message.
if person.has_key("status") and person["status"] != "":
self.dialog.main_info.enable("status")
self.dialog.main_info.set("status", person["status"])
# Format occupation.
# toDo: Research in this field is needed. Sometimes it returns university information even if users have active work places.
if person.has_key("occupation") and person["occupation"] != None:
if person["occupation"]["type"] == "work": c1 = _(u"Work ")
elif person["occupation"]["type"] == "school": c1 = _(u"Student ")
elif person["occupation"]["type"] == "university": c1 = _(u"Student ")
if person["occupation"].has_key("name") and person["occupation"]["name"] != "":
c2 = _(u"In {0}").format(person["occupation"]["name"],)
else:
c2 = ""
self.dialog.main_info.enable("occupation")
self.dialog.main_info.set("occupation", c1+c2)
# format relationship status.
# ToDo: When dating someone, the button associated to the information should point to the profile of the user.
if person.has_key("relation") and person["relation"] != 0:
if person["relation"] == 1:
r = _(u"Single")
elif person["relation"] == 2:
if person.has_key("relation_partner"):
r = _(u"Dating with {0} {1}").format(person["relation_partner"]["first_name"], person["relation_partner"]["last_name"])
else:
r = _(u"Dating")
elif person["relation"] == 3:
r = _(u"Engaged with {0} {1}").format(person["relation_partner"]["first_name"], person["relation_partner"]["last_name"])
elif person["relation"] == 4:
r = _(u"Married with {0} {1}").format(person["relation_partner"]["first_name"], person["relation_partner"]["last_name"])
elif person["relation"] == 5:
r = _(u"It's complicated")
elif person["relation"] == 6:
r = _(u"Actively searching")
elif person["relation"] == 7:
r = _(u"In love")
self.dialog.main_info.enable("relation")
self.dialog.main_info.relation.SetLabel(_(u"Relationship: ")+r)
# format last seen.
if person.has_key("last_seen") and person["last_seen"] != False:
original_date = arrow.get(person["last_seen"]["time"])
# Translators: This is the date of last seen
last_seen = _(u"{0}").format(original_date.humanize(locale=languageHandler.getLanguage()),)
self.dialog.main_info.enable("last_seen")
self.dialog.main_info.set("last_seen", last_seen)
self.person = person
# Adds photo to the dialog.
# ToDo: Need to ask if this has a visible effect in the dialog.
if person.has_key("photo_200_orig"):
img = requests.get(person["photo_200_orig"])
image = wx.Image(stream=cStringIO.StringIO(requests.get(person["photo_200_orig"]).content))
try:
self.dialog.image.SetBitmap(wx.Bitmap(image))
except ValueError:
return
self.dialog.panel.Layout()
def visit_website(self, *args, **kwargs):
""" Allows to visit an user's website. """
text = self.person["site"]
# Let's search for URLS with a regexp, as there are users with multiple websites in their profiles.
urls = utils.find_urls_in_text(text)
if len(urls) == 0:
output.speak(_(u"No URL addresses were detected."))
return
elif len(urls) == 1:
selected_url = urls[0]
else:
dialog = urlList.urlList()
dialog.populate_list(urls)
if dialog.get_response() != widgetUtils.OK:
return
selected_url = urls[dialog.get_item()]
output.speak(_(u"Opening URL..."))
webbrowser.open_new_tab(selected_url)

View File

@@ -2,22 +2,26 @@
import widgetUtils
from wxUI.dialogs import selector as gui
class audioAlbum(object):
class album(object):
def __init__(self, title, session):
super(audioAlbum, self).__init__()
def __init__(self, title, session, album_type="audio_albums"):
super(album, self).__init__()
self.item = None
self.session = session
if not hasattr(self.session, album_type):
return
self.albums = getattr(self.session, album_type)
self.dialog = gui.selectAlbum(title=title, albums=self.get_albums_as_string())
response = self.dialog.get_response()
if response == widgetUtils.OK:
self.item = self.search_item(self.dialog.get_string())
def get_albums_as_string(self):
return [i["title"] for i in self.session.audio_albums]
return [i["title"] for i in self.albums]
def search_item(self, item):
for i in self.session.audio_albums:
for i in self.albums:
if i["title"] == item:
return i["id"]
return None

View File

@@ -1,11 +1,13 @@
# -*- coding: utf-8 -*-
from microsofttranslator import Translator
def translate(text="", source="auto", target="en"):
t = Translator("twblue", "4KZA26GYIfmVAqQA/z16Hlucbg64hVSDTIpRjT2FqIU=")
return t.translate(text, target)
from yandex_translate import YandexTranslate
def translate(text="", target="en"):
t = YandexTranslate("trnsl.1.1.20161012T134532Z.d01b9c75fc39aa74.7d1be75a5166a80583eeb020e10f584168da6bf7")
vars = dict(text=text, lang=target)
return t.translate(**vars)["text"][0]
supported_langs = None
d = None
languages = {
"af": _(u"Afrikaans"),
"sq": _(u"Albanian"),
@@ -71,7 +73,7 @@ languages = {
"ps": _(u"Pashto"),
"fa": _(u"Persian"),
"pl": _(u"Polish"),
"pt-PT": _(u"Portuguese"),
"pt": _(u"Portuguese"),
"pa": _(u"Punjabi"),
"ro": _(u"Romanian"),
"ru": _(u"Russian"),
@@ -101,8 +103,11 @@ languages = {
}
def available_languages():
l = languages.keys()
d = languages.values()
l.insert(0, '')
d.insert(0, _(u"autodetect"))
return sorted(zip(l, d))
global supported_langs, d
if supported_langs == None and d == None:
t = YandexTranslate("trnsl.1.1.20161012T134532Z.d01b9c75fc39aa74.7d1be75a5166a80583eeb020e10f584168da6bf7")
supported_langs = t.langs
d = []
for i in supported_langs:
d.append(languages[i])
return sorted(zip(supported_langs, d))

View File

@@ -18,28 +18,26 @@
############################################################
import translator
import wx
import widgetUtils
class translateDialog(widgetUtils.BaseDialog):
def __init__(self):
super(translateDialog, self).__init__(None, -1, title=_(u"Translate message"))
panel = wx.Panel(self)
sizer = wx.BoxSizer(wx.VERTICAL)
staticSource = wx.StaticText(panel, -1, _(u"&Source language"))
self.source_lang = wx.ComboBox(panel, -1, choices=[x[1] for x in translator.available_languages()], style = wx.CB_READONLY)
self.source_lang.SetFocus()
staticDest = wx.StaticText(panel, -1, _(u"&Target language"))
self.source_lang.SetSelection(0)
self.dest_lang = wx.ComboBox(panel, -1, choices=[x[1] for x in translator.available_languages()], style = wx.CB_READONLY)
listSizer = wx.BoxSizer(wx.HORIZONTAL)
listSizer.Add(staticSource)
listSizer.Add(self.source_lang)
listSizer.Add(staticDest)
listSizer.Add(self.dest_lang)
ok = wx.Button(panel, wx.ID_OK)
ok.SetDefault()
cancel = wx.Button(panel, wx.ID_CANCEL)
self.SetEscapeId(wx.ID_CANCEL)
class translateDialog(wx.Dialog):
def __init__(self):
super(translateDialog, self).__init__(None, -1, title=_(u"Translate message"))
panel = wx.Panel(self)
sizer = wx.BoxSizer(wx.VERTICAL)
staticDest = wx.StaticText(panel, -1, _(u"Target language"))
self.dest_lang = wx.ComboBox(panel, -1, choices=[x[1] for x in translator.available_languages()], style = wx.CB_READONLY)
self.dest_lang.SetFocus()
self.dest_lang.SetSelection(0)
listSizer = wx.BoxSizer(wx.HORIZONTAL)
listSizer.Add(staticDest)
listSizer.Add(self.dest_lang)
ok = wx.Button(panel, wx.ID_OK)
ok.SetDefault()
cancel = wx.Button(panel, wx.ID_CANCEL)
self.SetEscapeId(wx.ID_CANCEL)
def get(self, control):
return getattr(self, control).GetSelection()
def get(self, control):
return getattr(self, control).GetSelection()
def get_response(self):
return self.ShowModal()

View File

@@ -1,9 +1,13 @@
# -*- coding: utf-8 -*-
import sys
import fix_requests
import fix_win32com
from . import fix_requests
if hasattr(sys, "frozen"):
from . import fix_win32com
from . import fix_libloader
def setup():
fix_requests.fix()
if hasattr(sys, "frozen"):
fix_win32com.fix()
fix_libloader.fix()
fix_win32com.fix()

View File

@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
import win32com
import paths
win32com.__gen_path__=paths.com_path()
import sys
import os
sys.path.append(os.path.join(win32com.__gen_path__, "."))
from win32com.client import gencache
from pywintypes import com_error
from libloader import com
fixed=False
def patched_getmodule(modname):
mod=__import__(modname)
return sys.modules[modname]
def load_com(*names):
global fixed
if fixed==False:
gencache._GetModule=patched_getmodule
com.prepare_gencache()
fixed=True
result = None
for name in names:
try:
result = gencache.EnsureDispatch(name)
break
except com_error:
continue
if result is None:
raise com_error("Unable to load any of the provided com objects.")
return result
def fix():
com.load_com = load_com

View File

@@ -1,7 +0,0 @@
from .libloader import *
__version__ = 0.1
__author__ = 'Christopher Toth <q@q-continuum.net>'
__doc__ = """
Quickly and easily load shared libraries from various platforms. Also includes a libloader.com module for loading com modules on Windows.
"""

View File

@@ -1,40 +0,0 @@
from pywintypes import com_error
import win32com
import paths
win32com.__gen_path__=paths.com_path()
import sys
import os
sys.path.append(os.path.join(win32com.__gen_path__, "."))
from win32com.client import gencache
fixed=False
def prepare_gencache():
gencache.is_readonly = False
gencache.GetGeneratePath()
def patched_getmodule(modname):
mod=__import__(modname)
return sys.modules[modname]
def load_com(*names):
global fixed
if fixed==False:
gencache._GetModule=patched_getmodule
fixed=True
result = None
for name in names:
try:
result = gencache.EnsureDispatch(name)
break
except com_error:
continue
if result is None:
raise com_error("Unable to load any of the provided com objects.")
return result
def preexec():
global fixed
if fixed==False:
gencache._GetModule=patched_getmodule
fixed=True

View File

@@ -1,56 +0,0 @@
import ctypes
import collections
import platform
import os
TYPES = {
'Linux': {
'loader': ctypes.CDLL,
'functype': ctypes.CFUNCTYPE,
'prefix': 'lib',
'extension': '.so'
},
'Darwin': {
'loader': ctypes.CDLL,
'functype': ctypes.CFUNCTYPE,
'prefix': 'lib',
'extension': '.dylib'
},
}
if platform.system() == 'Windows':
TYPES['Windows'] = {
'loader': ctypes.WinDLL,
'functype': ctypes.WINFUNCTYPE,
'prefix': "",
'extension': '.dll'
}
class LibraryLoadError(OSError): pass
def load_library(library, x86_path='.', x64_path='.', *args, **kwargs):
lib = find_library_path(library, x86_path=x86_path, x64_path=x64_path)
loaded = _do_load(lib, *args, **kwargs)
if loaded is not None:
return loaded
raise LibraryLoadError('unable to load %r. Provided library path: %r' % (library, lib))
def _do_load(file, *args, **kwargs):
loader = TYPES[platform.system()]['loader']
return loader(file, *args, **kwargs)
def find_library_path(libname, x86_path='.', x64_path='.'):
libname = '%s%s' % (TYPES[platform.system()]['prefix'], libname)
if platform.architecture()[0] == '64bit':
path = os.path.join(x64_path, libname)
else:
path = os.path.join(x86_path, libname)
ext = get_library_extension()
path = '%s%s' % (path, ext)
return os.path.abspath(path)
def get_functype():
return TYPES[platform.system()]['functype']
def get_library_extension():
return TYPES[platform.system()]['extension']

View File

@@ -37,4 +37,4 @@ def setup():
call_threaded(r.login)
app.run()
setup()
setup()

View File

@@ -1,41 +0,0 @@
import _winreg
import os
import sys
from platform_utils import paths
RUN_REGKEY = ur"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
def is_installed(app_subkey):
"""Checks if the currently running copy is installed or portable variant. Requires the name of the application subkey found under the uninstall section in Windows registry."""
try:
key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\%s" % app_subkey)
inst_dir = _winreg.QueryValueEx(key,"InstallLocation")[0]
except WindowsError:
return False
_winreg.CloseKey(key)
try:
return os.stat(inst_dir) == os.stat(paths.app_path())
except WindowsError:
return False
def getAutoStart(app_name):
"""Queries if the automatic startup should be set for the application or not, depending on it's current state."""
try:
key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, RUN_REGKEY)
val = _winreg.QueryValueEx(key, unicode(app_name))[0]
return os.stat(val) == os.stat(sys.argv[0])
except (WindowsError, OSError):
return False
def setAutoStart(app_name, enable=True):
"""Configures automatic startup for the application, if the enable argument is set to True. If set to False, deletes the application AutoStart value."""
if getAutoStart(app_name) == enable:
return
key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, RUN_REGKEY, 0, _winreg.KEY_WRITE)
if enable:
_winreg.SetValueEx(key, unicode(app_name), None, _winreg.REG_SZ, sys.argv[0])
else:
_winreg.DeleteValue(key, unicode(app_name))

View File

@@ -1,16 +0,0 @@
# Replacement for py2exe distributed module
# Avoids the use of the standard py2exe console.
# Just import this file and it should go away
import sys
if hasattr(sys,"frozen"): # true only if we are running as a py2exe app
class Blackhole(object):
def write(self,text):
pass
def flush(self):
pass
sys.stdout = Blackhole()
sys.stderr = Blackhole()
del Blackhole
del sys

View File

@@ -1,51 +0,0 @@
import ctypes
import collections
import platform
import os
TYPES = {
'Linux': {
'loader': ctypes.CDLL,
'functype': ctypes.CFUNCTYPE,
'prefix': 'lib',
'extension': '.so'
},
'Darwin': {
'loader': ctypes.CDLL,
'functype': ctypes.CFUNCTYPE,
'prefix': 'lib',
'extension': '.dylib'
},
}
if platform.system() == 'Windows':
TYPES['Windows'] = {
'loader': ctypes.WinDLL,
'functype': ctypes.WINFUNCTYPE,
'prefix': "",
'extension': '.dll'
}
class LibraryLoadError(Exception): pass
def load_library(library, x86_path='.', x64_path='.', *args, **kwargs):
lib = find_library_path(library, x86_path=x86_path, x64_path=x64_path)
loaded = _do_load(lib, *args, **kwargs)
if loaded is not None:
return loaded
raise LibraryLoadError('unable to load %r. Provided library path: %r' % (library, path))
def _do_load(file, *args, **kwargs):
loader = TYPES[platform.system()]['loader']
return loader(file, *args, **kwargs)
def find_library_path(libname, x86_path='.', x64_path='.'):
libname = '%s%s' % (TYPES[platform.system()]['prefix'], libname)
if platform.machine() == 'x86_64':
path = os.path.join(x64_path, libname)
else:
path = os.path.join(x86_path, libname)
ext = TYPES[platform.system()]['extension']
return '%s%s' % (path, ext)
def get_functype():
return TYPES[platform.system()]['functype']

View File

@@ -1,114 +0,0 @@
import inspect
import platform
import os
import subprocess
import sys
import string
import unicodedata
def app_data_path(app_name=None):
"""Cross-platform method for determining where to put application data."""
"""Requires the name of the application"""
plat = platform.system()
if plat == 'Windows':
import winpaths
path = winpaths.get_appdata()
elif plat == 'Darwin':
path = os.path.join(os.path.expanduser('~'), 'Library', 'Application Support')
elif plat == 'Linux':
path = os.path.expanduser('~')
app_name = '.%s' % app_name.replace(' ', '_')
return os.path.join(path, app_name)
def prepare_app_data_path(app_name):
"""Creates the application's data directory, given its name."""
dir = app_data_path(app_name)
return ensure_path(dir)
def embedded_data_path():
if platform.system() == 'Darwin' and is_frozen():
return os.path.abspath(os.path.join(executable_directory(), '..', 'Resources'))
return app_path()
def is_frozen():
"""Return a bool indicating if application is compressed"""
import imp
return hasattr(sys, 'frozen') or imp.is_frozen("__main__")
def get_executable():
"""Returns the full executable path/name if frozen, or the full path/name of the main module if not."""
if is_frozen():
if platform.system() != 'Darwin':
return sys.executable
#On darwin, sys.executable points to python. We want the full path to the exe we ran.
exedir = os.path.abspath(os.path.dirname(sys.executable))
items = os.listdir(exedir)
items.remove('python')
return os.path.join(exedir, items[0])
#Not frozen
try:
import __main__
return os.path.abspath(__main__.__file__)
except AttributeError:
return sys.argv[0]
def get_module(level=2):
"""Hacky method for deriving the caller of this function's module."""
return inspect.getmodule(inspect.stack()[level][0]).__file__
def executable_directory():
"""Always determine the directory of the executable, even when run with py2exe or otherwise frozen"""
executable = get_executable()
path = os.path.abspath(os.path.dirname(executable))
return path
def app_path():
"""Return the root of the application's directory"""
path = executable_directory()
if is_frozen() and platform.system() == 'Darwin':
path = os.path.abspath(os.path.join(path, '..', '..'))
return path
def module_path(level=2):
return os.path.abspath(os.path.dirname(get_module(level)))
def documents_path():
"""On windows, returns the path to My Documents. On OSX, returns the user's Documents folder. For anything else, returns the user's home directory."""
plat = platform.system()
if plat == 'Windows':
import winpaths
path = winpaths.get_my_documents()
elif plat == 'Darwin':
path = os.path.join(os.path.expanduser('~'), 'Documents')
else:
path = os.path.expanduser('~')
return path
def safe_filename(filename):
"""Given a filename, returns a safe version with no characters that would not work on different platforms."""
SAFE_FILE_CHARS = "'-_.()[]{}!@#$%^&+=`~ "
filename = unicode(filename)
new_filename = ''.join(c for c in filename if c in SAFE_FILE_CHARS or c.isalnum())
#Windows doesn't like directory names ending in space, macs consider filenames beginning with a dot as hidden, and windows removes dots at the ends of filenames.
return new_filename.strip(' .')
def ensure_path(path):
if not os.path.exists(path):
os.makedirs(path)
return path
def start_file(path):
if platform.system() == 'Windows':
os.startfile(path)
else:
subprocess.Popen(['open', path])
def get_applications_path():
"""Return the directory where applications are commonly installed on the system."""
plat = platform.system()
if plat == 'Windows':
import winpaths
return winpaths.get_program_files()
elif plat == 'Darwin':
return '/Applications'

View File

@@ -1,27 +0,0 @@
import platform
import ctypes
import os
import signal
def kill_windows_process(pid):
PROCESS_TERMINATE = 1
SYNCHRONIZE=1048576
handle = ctypes.windll.kernel32.OpenProcess(PROCESS_TERMINATE | SYNCHRONIZE, False, pid)
ctypes.windll.kernel32.TerminateProcess(handle, -1)
ctypes.windll.kernel32.WaitForSingleObject(handle, 1000)
ctypes.windll.kernel32.CloseHandle(handle)
def kill_unix_process(pid):
try:
os.kill(pid, signal.SIGKILL)
except OSError:
pass
def kill_process(pid):
if pid < 0:
return
if platform.system() == 'Windows':
kill_windows_process(pid)
else:
kill_unix_process(pid)

View File

@@ -1,10 +0,0 @@
import _winreg
SHELL_REGKEY = ur"Directory\shell"
def context_menu_integrate(item_key_name, item_display_text, item_command):
app_menu_key = _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, SHELL_REGKEY, 0, _winreg.KEY_WRITE)
menu_item_key = _winreg.CreateKey(app_menu_key, item_key_name)
_winreg.SetValueEx(menu_item_key, None, None, _winreg.REG_SZ, item_display_text)
item_command_key = _winreg.CreateKey(menu_item_key, 'command')
_winreg.SetValueEx(item_command_key, None, None, _winreg.REG_SZ, item_command)

View File

@@ -1,9 +0,0 @@
import platform
import webbrowser
def open(url):
if platform.system() == 'Windows':
browser = webbrowser.get('windows-default')
else:
browser = webbrowser
browser.open_new_tab(url)

View File

@@ -2,16 +2,25 @@
user = string(default="")
password = string(default="")
token = string(default="")
[general]
reverse_timelines = boolean(default=False)
load_images = boolean(default=True)
[buffers]
count_for_audio_buffers = integer(default=100)
count_for_wall_buffers = integer(default=100)
count_for_video_buffers = integer(default=200)
[sound]
volume = float(default=1.0)
input_device = string(default="Default")
output_device = string(default="Default")
session_mute = boolean(default=False)
current_soundpack = string(default="default")
current_soundpack = string(default="default")
[chat]
notify_online = boolean(default=True)
notify_offline = boolean(default=True)
open_unread_conversations = boolean(default=True)
automove_to_conversations = boolean(default=True)
notifications = string(default="custom")

View File

@@ -0,0 +1,184 @@
# -*- coding: utf-8 -*-
""" this module contains everything used to render different kind of posts (posts in the home buffer,
Chat messages, audios, videos, photos, comments in posts, etc)"""
import arrow
import languageHandler
import logging
import utils
log = logging.getLogger(__file__)
### Some util funtions
def extract_attachment(attachment):
""" Adds information about attachment files in posts. It only adds the text, I mean, no attachment file is added here.
This will produce a result like:
'website: http://url.com'.
'photo: A forest'."""
msg = u""
if attachment["type"] == "link":
msg = u"{0}: {1}".format(attachment["link"]["title"], attachment["link"]["url"])
elif attachment["type"] == "photo":
msg = attachment["photo"]["text"]
if msg == "":
return _(u"photo with no description available")
elif attachment["type"] == "video":
msg = _(u"video: {0}").format(attachment["video"]["title"],)
return msg
def short_text(status):
""" This shorts the text to 140 characters for displaying it in the list control of buffers."""
message = ""
# copy_story indicates that the post is a shared repost.
if status.has_key("copy_history"):
txt = status["copy_history"][0]["text"]
else:
txt = status["text"]
if len(txt) < 140:
message = utils.clean_text(txt)
else:
message = utils.clean_text(txt[:139])
return message
def clean_audio(audio):
""" Remove unavailable songs due to different reasons. This is used to clean the audio list when people adds audios and need to be displayed in the buffer."""
for i in audio["items"][:]:
if type(i) == bool:
audio["items"].remove(i)
audio["count"] = audio["count"] -1
return audio
### Render functions
def render_person(status, session):
""" Render users in people buffers such as everything related to friendships or buffers created with only people.
Example result: ["John Doe", "An hour ago"]
Reference: https://vk.com/dev/fields"""
if status.has_key("last_seen"):
original_date = arrow.get(status["last_seen"]["time"])
# Translators: This is the date of last seen
last_seen = _(u"{0}").format(original_date.humanize(locale=languageHandler.curLang[:2]),)
# Account suspended or deleted.
elif status.has_key("last_seen") == False and status.has_key("deactivated"):
last_seen = _(u"Account deactivated")
return [u"{0} {1}".format(status["first_name"], status["last_name"]), last_seen]
def render_newsfeed_item(status, session):
""" This me☻thod is used to render an item of the news feed.
References:
https://vk.com/dev/newsfeed.get
https://vk.com/dev/post_source
https://vk.com/dev/post
"""
user = session.get_user_name(status["source_id"], case_name="nom")
# See if this is a post or repost.
if status.has_key("copy_history"):
user = _(u"{0} has shared the {1}'s post").format(user, session.get_user_name(status["copy_history"][0]["owner_id"]))
message = ""
original_date = arrow.get(status["date"])
created_at = original_date.humanize(locale=languageHandler.curLang[:2])
# handle status updates.
if status["type"] == "post":
message += short_text(status)
if status.has_key("attachment") and len(status["attachment"]) > 0:
message += extract_attachment(status["attachment"])
# If there is no message after adding text, it's because a pphoto with no description has been found.
# so let's manually add the "no description" tag here.
if message == "":
message = "no description available"
# Handle audio rendering.
elif status["type"] == "audio":
# removes deleted audios.
status["audio"] = clean_audio(status["audio"])
if status["audio"]["count"] == 1:
message = _(u"{0} has added an audio: {1}").format(user, u", ".join(render_audio(status["audio"]["items"][0], session)),)
else:
prem = ""
for i in xrange(0, status["audio"]["count"]):
composed_audio = render_audio(status["audio"]["items"][i], session)
prem += u"{0} - {1}, ".format(composed_audio[0], composed_audio[1])
message = _(u"{0} has added {1} audios: {2}").format(user, status["audio"]["count"], prem)
# handle new friends for people in the news buffer.
elif status["type"] == "friend":
msg_users = u""
if status.has_key("friends"):
for i in status["friends"]["items"]:
msg_users = msg_users + u"{0}, ".format(session.get_user_name(i["user_id"], "nom"))
else:
print status.keys()
message = _(u"{0} added friends: {1}").format(user, msg_users)
elif status["type"] == "video":
if status["video"]["count"] == 1:
message = _(u"{0} has added a video: {1}").format(user, u", ".join(render_video(status["video"]["items"][0], session)),)
else:
prem = ""
for i in xrange(0, status["video"]["count"]):
composed_video = render_video(status["video"]["items"][i], session)
prem += u"{0} - {1}, ".format(composed_video[0], composed_video[1])
message = _(u"{0} has added {1} videos: {2}").format(user, status["video"]["count"], prem)
else:
if status["type"] != "post": print status
return [user, message, created_at]
def render_message(message, session):
""" Render a message posted in a private conversation.
Reference: https://vk.com/dev/message"""
user = session.get_user_name(message["from_id"], "nom")
original_date = arrow.get(message["date"])
now = arrow.now()
original_date = original_date.to(now.tzinfo)
# Format the date here differently depending in if this is the same day for both dates or not.
if original_date.day == now.day:
created_at = original_date.format(_(u"H:mm."), locale=languageHandler.curLang[:2])
else:
created_at = original_date.format(_(u"H:mm. dddd, MMMM D, YYYY"), locale=languageHandler.curLang[:2])
# No idea why some messages send "text" instead "body"
if message.has_key("body"):
body = message["body"]
else:
body = message["text"]
return [u"{2}, {0} {1}".format(body, created_at, user)]
def render_status(status, session):
""" Render a wall post (shown in user's wall, not in newsfeed).
Reference: https://vk.com/dev/post"""
user = session.get_user_name(status["from_id"], "nom")
if status.has_key("copy_history"):
user = _(u"{0} has shared the {1}'s post").format(user, session.get_user_name(status["copy_history"][0]["owner_id"]))
message = ""
original_date = arrow.get(status["date"])
created_at = original_date.humanize(locale=languageHandler.curLang[:2])
if status.has_key("copy_owner_id"):
user = _(u"{0} has shared the {1}'s post").format(user, session.get_user_name(status["copy_owner_id"]))
if status["post_type"] == "post" or status["post_type"] == "copy":
message += short_text(status)
if status.has_key("attachment") and len(status["attachment"]) > 0:
message += extract_attachment(status["attachment"])
if message == "":
message = "no description available"
return [user, message, created_at]
def render_audio(audio, session=None):
""" Render audio files added to VK.
Example result:
["Song title", "Artist", "03:15"]
reference: https://vk.com/dev/audio_object"""
if audio == False: return [_(u"Audio removed from library"), "", ""]
return [audio["title"], audio["artist"], utils.seconds_to_string(audio["duration"])]
def render_video(video, session=None):
""" Render a video file from VK.
Example result:
["Video title", "Video description", "01:30:28"]
Reference: https://vk.com/dev/video_object"""
if video == False:
return [_(u"Video not available"), "", ""]
return [video["title"], video["description"], utils.seconds_to_string(video["duration"])]
def render_audio_message(audio_message, session=None):
""" Render a voice message from VK
Example result:
["Voice message", "01:30:28"]"""
if audio_message == False:
return [_(u"Voice message not available"), "", ""]
return [utils.seconds_to_string(audio_message["duration"])]

View File

@@ -1,14 +1,12 @@
# -*- coding: utf-8 -*-
import time
import arrow
import logging
import languageHandler
import paths
import vkSessionHandler
import logging
import utils
import sound
from config_utils import Configuration, ConfigurationResetException
from pubsub import pub
from vk_api.exceptions import LoginRequired, VkApiError
log = logging.getLogger("session")
@@ -36,124 +34,6 @@ def find_item(list, item):
return True
return False
def add_attachment(attachment):
""" Adds information about attachment files in posts. It only adds the text, I mean, no attachment file is added here.
This will produce a result like 'Title of a web page: http://url.xxx', etc."""
msg = u""
if attachment["type"] == "link":
msg = u"{0}: {1}".format(attachment["link"]["title"], attachment["link"]["url"])
elif attachment["type"] == "photo":
msg = attachment["photo"]["text"]
if msg == "":
return _(u"photo with no description available")
elif attachment["type"] == "video":
msg = _(u"video: {0}").format(attachment["video"]["title"],)
return msg
def add_text(status):
""" This shorts the text to 140 characters for displaying it in the list control."""
message = ""
if status.has_key("copy_history"):
txt = status["copy_history"][0]["text"]
else:
txt = status["text"]
if len(txt) < 140:
message = utils.clean_text(txt)
else:
message = utils.clean_text(txt[:139])
return message
def compose_person(status, session):
if status.has_key("last_seen"):
original_date = arrow.get(status["last_seen"]["time"])
# Translators: This is the date of last seen
last_seen = _(u"{0}").format(original_date.humanize(locale=languageHandler.getLanguage()),)
elif status.has_key("last_seen") == False and status.has_key("deactivated"):
last_seen = _(u"Account deactivated")
return [u"{0} {1}".format(status["first_name"], status["last_name"]), last_seen]
def compose_new(status, session):
""" This method is used to compose an item of the news feed."""
user = session.get_user_name(status["source_id"], case_name="nom")
if status.has_key("copy_history"):
user = _(u"{0} has shared the {1}'s post").format(user, session.get_user_name(status["copy_history"][0]["owner_id"]))
message = ""
original_date = arrow.get(status["date"])
created_at = original_date.humanize(locale=languageHandler.getLanguage())
if status["type"] == "post":
message += add_text(status)
if status.has_key("attachment") and len(status["attachment"]) > 0:
message += add_attachment(status["attachment"])
if message == "":
message = "no description available"
elif status["type"] == "audio":
# removes deleted audios.
status["audio"] = clean_audio(status["audio"])
if status["audio"]["count"] == 1:
message = _(u"{0} has added an audio: {1}").format(user, u", ".join(compose_audio(status["audio"]["items"][0], session)),)
else:
prem = ""
for i in xrange(0, status["audio"]["count"]):
composed_audio = compose_audio(status["audio"]["items"][i], session)
prem += u"{0} - {1}, ".format(composed_audio[0], composed_audio[1])
message = _(u"{0} has added {1} audios: {2}").format(user, status["audio"]["count"], prem)
elif status["type"] == "friend":
msg_users = u""
for i in status["friends"]["items"]:
msg_users = msg_users + u"{0}, ".format(session.get_user_name(i["user_id"], "nom"))
message = _(u"{0} hadded friends: {1}").format(user, msg_users)
elif status["type"] == "video":
if status["video"]["count"] == 1:
message = _(u"{0} has added a video: {1}").format(user, u", ".join(compose_video(status["video"]["items"][0], session)),)
else:
prem = ""
for i in xrange(0, status["video"]["count"]):
composed_video = compose_video(status["video"]["items"][i], session)
prem += u"{0} - {1}, ".format(composed_video[0], composed_video[1])
message = _(u"{0} has added {1} videos: {2}").format(user, status["video"]["count"], prem)
else:
if status["type"] != "post": print status
return [user, message, created_at]
def clean_audio(audio):
for i in audio["items"][:]:
if type(i) == bool:
audio["items"].remove(i)
audio["count"] = audio["count"] -1
return audio
def compose_message(message, session):
user = session.get_user_name(message["from_id"], "nom")
original_date = arrow.get(message["date"])
created_at = original_date.format(_(u"dddd, MMMM D, YYYY H:m:s"), locale=languageHandler.getLanguage())
body = message["body"]
return [u"{2}, {0} {1}".format(body, created_at, user)]
def compose_status(status, session):
user = session.get_user_name(status["from_id"], "nom")
if status.has_key("copy_history"):
user = _(u"{0} has shared the {1}'s post").format(user, session.get_user_name(status["copy_history"][0]["owner_id"]))
message = ""
original_date = arrow.get(status["date"])
created_at = original_date.humanize(locale=languageHandler.getLanguage())
if status.has_key("copy_owner_id"):
user = _(u"{0} has shared the {1}'s post").format(user, session.get_user_name(status["copy_owner_id"]))
if status["post_type"] == "post" or status["post_type"] == "copy":
message += add_text(status)
if status.has_key("attachment") and len(status["attachment"]) > 0:
message += add_attachment(status["attachment"])
if message == "":
message = "no description available"
return [user, message, created_at]
def compose_audio(audio, session=None):
if audio == False: return [_(u"Audio removed from library"), "", ""]
return [audio["title"], audio["artist"], utils.seconds_to_string(audio["duration"])]
def compose_video(video, session=None):
if video == False: return [_(u"Audio removed from library"), "", ""]
return [video["title"], utils.seconds_to_string(video["duration"])]
class vkSession(object):
def order_buffer(self, name, data, show_nextpage):
@@ -210,26 +90,13 @@ class vkSession(object):
# log.exception("The session configuration has failed.")
def login(self):
""" Login using credentials from settings.
if the user account isn't authorised, it'll call self.authorise() before login.
If the access_token has expired, it will call authorise() too, for getting a new access token."""
if self.settings["vk"]["token"] != None:
result = self.vk.login_access_token(self.settings["vk"]["token"])
self.logged = True
log.debug("Logged.")
if result == False:
self.authorise()
else:
self.authorise()
self.get_my_data()
def authorise(self):
try:
self.vk.login(self.settings["vk"]["user"], self.settings["vk"]["password"])
self.vk.login(self.settings["vk"]["user"], self.settings["vk"]["password"], filename=paths.config_path(self.session_id+"/vkconfig.json"))
self.settings["vk"]["token"] = self.vk.client._session.access_token
self.settings.write()
except:
self.logged = True
self.get_my_data()
except ValueError:
self.settings["vk"]["user"] = ""
self.settings["vk"]["password"] = ""
self.settings.write()
@@ -260,10 +127,19 @@ class vkSession(object):
def get_page(self, name="", show_nextpage=False, endpoint="", *args, **kwargs):
data = None
if "audio" in endpoint:
c = self.vk.client_audio
else:
c = self.vk.client
if kwargs.has_key("parent_endpoint"):
p = kwargs["parent_endpoint"]
if "audio" in p:
c = self.vk.client_audio
kwargs.pop("parent_endpoint")
p = getattr(self.vk.client, p)
try:
p = getattr(c, p)
except AttributeError:
p = c
log.debug("Calling endpoint %s with params %r" % (p, kwargs,))
data = getattr(p, endpoint)(*args, **kwargs)
if data != None:
@@ -282,6 +158,7 @@ class vkSession(object):
def get_messages(self, name="", *args, **kwargs):
data = self.vk.client.messages.getHistory(*args, **kwargs)
data["items"].reverse()
if data != None:
num = self.order_buffer(name, data["items"], False)
return num
@@ -343,4 +220,3 @@ class vkSession(object):
log.debug("Getting user identifier...")
user = self.vk.client.users.get(fields="uid, first_name, last_name")
self.user_id = user[0]["id"]
# self.db["users"][self.user_id] = u"{0} {1}".format(user[0]["first_name"], user[0]["last_name"])

View File

@@ -4,6 +4,7 @@ import os
import requests
import re
import logging
from sessionmanager import renderers
log = logging.getLogger("utils")
url_re = re.compile("(?:\w+://|www\.)[^ ,.?!#%=+][^ ]*")
bad_chars = '\'\\.,[](){}:;"'
@@ -58,4 +59,32 @@ def clean_text(text):
""" Replaces all HTML entities and put the plain text equivalent if it's possible."""
text = text.replace("<br>", "\n")
text = text.replace("\\n", "\n")
return text
return text
def add_attachment(attachment):
msg = u""
tpe = ""
if attachment["type"] == "link":
msg = u"{0}: {1}".format(attachment["link"]["title"], attachment["link"]["url"])
tpe = _(u"Link")
elif attachment["type"] == "photo":
tpe = _(u"Photo")
msg = attachment["photo"]["text"]
if msg == "":
msg = _(u"no description available")
elif attachment["type"] == "video":
msg = u"{0}".format(attachment["video"]["title"],)
tpe = _(u"Video")
elif attachment["type"] == "audio":
msg = u"{0}".format(" ".join(renderers.render_audio(attachment["audio"])))
tpe = _(u"Audio")
elif attachment["type"] == "doc":
msg = u"{0}".format(attachment["doc"]["title"])
tpe = _(u"{0} file").format(attachment["doc"]["ext"])
elif attachment["type"] == "audio_message":
msg = u"{0}".format(" ".join(renderers.render_audio_message(attachment["audio_message"])))
tpe = _(u"Voice message")
else:
print attachment
return [tpe, msg]

View File

@@ -1,25 +1,23 @@
#!/usr/bin/python
import keys
import logging
from vk import API, AuthSession, Session
import vk_api
from vk_api.audio import VkAudio
log = logging.getLogger("vkSessionHandler")
class vkObject(object):
def __init__(self):
self.api_key = keys.keyring.get_api_key()
self.api_version = 5.52
log.debug("Created vkSession using VK API Version %s" % (self.api_version,))
def login(self, user, password):
def login(self, user, password, filename):
log.debug("Logging in vk using user/password authentication")
s = AuthSession(app_id=self.api_key, user_login=user, user_password=password, scope="wall, notify, friends, photos, audio, video, docs, notes, pages, status, groups, messages, notifications, stats")
self.client = API(s, v=self.api_version)
self.session_object = vk_api.VkApi(app_id=self.api_key, login=user, password=password, scope="wall, notify, friends, photos, audio, video, docs, notes, pages, status, groups, messages, notifications, stats", config_filename=filename)
self.session_object.auth()
self.client = self.session_object.get_api()
# self.client = API(s, v=self.api_version)
log.debug("Getting tokens for 24 hours...")
self.client.account.getProfileInfo()
def login_access_token(self, token):
log.debug("Logging in VK using stored tokens...")
s = Session(access_token=token)
self.client = API(s, v=self.api_version)
return self.client.account.getProfileInfo()
# Add session data to the application statistics.
self.client.stats.trackVisitor()
self.client_audio = VkAudio(self.session_object)

View File

@@ -88,7 +88,7 @@ options = {
'py2exe': {
'optimize':2,
'packages': ["pubsub", "pubsub.core", "pubsub.core.kwargs"],
'dll_excludes': ["MPR.dll", "api-ms-win-core-apiquery-l1-1-0.dll", "api-ms-win-core-console-l1-1-0.dll", "api-ms-win-core-delayload-l1-1-1.dll", "api-ms-win-core-errorhandling-l1-1-1.dll", "api-ms-win-core-file-l1-2-0.dll", "api-ms-win-core-handle-l1-1-0.dll", "api-ms-win-core-heap-obsolete-l1-1-0.dll", "api-ms-win-core-libraryloader-l1-1-1.dll", "api-ms-win-core-localization-l1-2-0.dll", "api-ms-win-core-processenvironment-l1-2-0.dll", "api-ms-win-core-processthreads-l1-1-1.dll", "api-ms-win-core-profile-l1-1-0.dll", "api-ms-win-core-registry-l1-1-0.dll", "api-ms-win-core-synch-l1-2-0.dll", "api-ms-win-core-sysinfo-l1-2-0.dll", "api-ms-win-security-base-l1-2-0.dll", "api-ms-win-core-heap-l1-2-0.dll", "api-ms-win-core-interlocked-l1-2-0.dll", "api-ms-win-core-localization-obsolete-l1-1-0.dll", "api-ms-win-core-string-l1-1-0.dll", "api-ms-win-core-string-obsolete-l1-1-0.dll", "WLDAP32.dll", "MSVCP90.dll"],
'dll_excludes': ["MPR.dll", "api-ms-win-core-apiquery-l1-1-0.dll", "api-ms-win-core-console-l1-1-0.dll", "api-ms-win-core-delayload-l1-1-1.dll", "api-ms-win-core-errorhandling-l1-1-1.dll", "api-ms-win-core-file-l1-2-0.dll", "api-ms-win-core-handle-l1-1-0.dll", "api-ms-win-core-heap-obsolete-l1-1-0.dll", "api-ms-win-core-libraryloader-l1-1-1.dll", "api-ms-win-core-localization-l1-2-0.dll", "api-ms-win-core-processenvironment-l1-2-0.dll", "api-ms-win-core-processthreads-l1-1-1.dll", "api-ms-win-core-profile-l1-1-0.dll", "api-ms-win-core-registry-l1-1-0.dll", "api-ms-win-core-synch-l1-2-0.dll", "api-ms-win-core-sysinfo-l1-2-0.dll", "api-ms-win-security-base-l1-2-0.dll", "api-ms-win-core-heap-l1-2-0.dll", "api-ms-win-core-interlocked-l1-2-0.dll", "api-ms-win-core-localization-obsolete-l1-1-0.dll", "api-ms-win-core-string-l1-1-0.dll", "api-ms-win-core-string-obsolete-l1-1-0.dll", "WLDAP32.dll", "MSVCP90.dll", "CRYPT32.dll"],
# 'skip_archive': False
},
},

View File

@@ -9,6 +9,7 @@ import sound_lib
import output
from mysc.repeating_timer import RepeatingTimer
from mysc.thread_utils import call_threaded
from sound_lib import output, input
import glob
class soundSystem(object):
@@ -32,8 +33,8 @@ class soundSystem(object):
self.config = soundConfig
# Set the output and input default devices.
try:
self.output = sound_lib.output.Output()
self.input = sound_lib.input.Input()
self.output = output.Output()
self.input = input.Input()
except:
pass
# Try to use the selected device from the configuration. It can fail if the machine does not has a mic.

View File

@@ -1,25 +0,0 @@
import output, input, recording, stream
__author__ = 'Christopher Toth'
__version__ = 0.73
def find_datafiles():
from glob import glob
import os
import platform
import sound_lib
path = os.path.join(sound_lib.__path__[0], 'lib')
system = platform.system()
if system == 'Windows':
file_ext = '*.dll'
elif system == 'Darwin':
file_ext = '*.dylib'
else:
file_ext = '*.so'
if platform.architecture()[0] == '32bit' or platform.system() == 'Darwin':
arch = 'x86'
else:
arch = 'x64'
dest_dir = os.path.join('sound_lib', 'lib', arch)
source = glob(os.path.join(path, arch, file_ext))
return [(dest_dir, source)]

View File

@@ -1,285 +0,0 @@
from __future__ import absolute_import
from .external.pybass import *
from .main import bass_call, bass_call_0, BassError, update_3d_system, FlagObject
from ctypes import pointer, c_float, c_long, c_ulong, c_buffer
class Channel (FlagObject):
"""A "channel" can be a sample playback channel (HCHANNEL), a sample stream (HSTREAM), a MOD music (HMUSIC), or a recording (HRECORD). Each "Channel" function can be used with one or more of these channel types."""
def __init__ (self, handle):
self.handle = handle
self.attribute_mapping = {
'eaxmix': BASS_ATTRIB_EAXMIX,
'frequency': BASS_ATTRIB_FREQ,
'pan': BASS_ATTRIB_PAN,
'volume': BASS_ATTRIB_VOL
}
def add_attributes_to_mapping(self, **attrs):
self.attribute_mapping.update(**attrs)
def play (self, restart=False):
"""Starts (or resumes) playback of a sample, stream, MOD music, or recording."""
return bass_call(BASS_ChannelPlay, self.handle, restart)
def play_blocking(self, restart=False):
self.play(restart=restart)
while self.is_playing:
pass
def pause (self):
return bass_call(BASS_ChannelPause, self.handle)
def is_active (self):
"Checks if a sample, stream, or MOD music is active (playing) or stalled. Can also check if a recording is in progress."""
return bass_call_0(BASS_ChannelIsActive, self.handle)
@property
def is_playing(self):
return self.is_active() == BASS_ACTIVE_PLAYING
@property
def is_paused(self):
return self.is_active() == BASS_ACTIVE_PAUSED
@property
def is_stopped(self):
return self.is_active() == BASS_ACTIVE_STOPPED
@property
def is_stalled(self):
return self.is_active() == BASS_ACTIVE_STALLED
def get_position (self, mode=BASS_POS_BYTE):
"""Retrieves the playback position of a sample, stream, or MOD music. Can also be used with a recording channel."""
return bass_call_0(BASS_ChannelGetPosition, self.handle, mode)
def set_position (self, pos, mode=BASS_POS_BYTE):
"""Sets the playback position of a sample, MOD music, or stream."""
return bass_call(BASS_ChannelSetPosition, self.handle, pos, mode)
position = property(get_position, set_position)
def stop (self):
"""Stops a sample, stream, MOD music, or recording."""
return bass_call(BASS_ChannelStop, self.handle)
def update (self, length=0):
"""Updates the playback buffer of a stream or MOD music."""
return bass_call(BASS_ChannelUpdate, self.handle, length)
def get_length (self, mode=BASS_POS_BYTE):
return bass_call_0(BASS_ChannelGetLength, self.handle, mode)
__len__ = get_length
def __bool__(self):
return True
def get_device(self):
"""Retrieves the device that a channel is using."""
return bass_call_0( BASS_ChannelGetDevice, self.handle)
def set_device (self, device):
"""Changes the device that a stream, MOD music or sample is using."""
bass_call(BASS_ChannelSetDevice, self.handle, device)
device = property(get_device, set_device)
def set_fx(self, type, priority=0):
"""Sets an effect on a stream, MOD music, or recording channel."""
return SoundEffect(bass_call(BASS_ChannelSetFX, type, priority))
def bytes_to_seconds(self, position=None):
"""Translates a byte position into time (seconds), based on a channel's format."""
position = position or self.position
return bass_call_0(BASS_ChannelBytes2Seconds, self.handle, position)
def length_in_seconds(self):
return self.bytes_to_seconds(self.get_length())
def seconds_to_bytes(self, position):
"""Translates a time (seconds) position into bytes, based on a channel's format."""
return bass_call_0(BASS_ChannelSeconds2Bytes, self.handle, position)
def get_attribute(self, attribute):
"""Retrieves the value of a channel's attribute."""
value = pointer(c_float())
if attribute in self.attribute_mapping:
attribute = self.attribute_mapping[attribute]
bass_call(BASS_ChannelGetAttribute, self.handle, attribute, value)
return value.contents.value
def set_attribute(self, attribute, value):
"""Sets the value of a channel's attribute."""
if attribute in self.attribute_mapping:
attribute = self.attribute_mapping[attribute]
return bass_call(BASS_ChannelSetAttribute, self.handle, attribute, value)
def slide_attribute(self, attribute, value, time):
"""Slides a channel's attribute from its current value to a new value."""
if attribute in self.attribute_mapping:
attribute = self.attribute_mapping[attribute]
return bass_call(BASS_ChannelSlideAttribute, self.handle, attribute, value, time*1000)
def is_sliding (self, attribute=None):
"""Checks if an attribute (or any attribute) of a sample, stream, or MOD music is sliding."""
return bass_call_0(BASS_ChannelIsSliding, self.handle, attribute)
def get_info(self):
"""Retrieves information on a channel."""
value = pointer(BASS_CHANNELINFO())
bass_call(BASS_ChannelGetInfo, self.handle, value)
return value[0]
def get_level(self):
"""Retrieves the level (peak amplitude) of a stream, MOD music or recording channel."""
return bass_call_0(BASS_ChannelGetLevel, self.handle)
def lock(self):
"""Locks a stream, MOD music or recording channel to the current thread."""
return bass_call(BASS_ChannelLock, self.handle, True)
def unlock(self):
"""Unlocks a stream, MOD music or recording channel from the current thread."""
return bass_call(BASS_ChannelLock, self.handle, False)
def get_3d_attributes(self):
"""Retrieves the 3D attributes of a sample, stream, or MOD music channel with 3D functionality."""
answer = dict(mode=c_ulong(), min=c_float(), max=c_float(), iangle=c_ulong(), oangle=c_ulong(), outvol=c_float())
bass_call(BASS_ChannelGet3DAttributes, self.handle, pointer(answer['mode']), pointer(answer['min']), pointer(answer['max']), pointer(answer['iangle']), pointer(answer['oangle']), pointer(answer['outvol']))
for k in answer:
answer[k] = answer[k].value()
return answer
@update_3d_system
def set_3d_attributes(self, mode=-1, min=0.0, max=0.0, iangle=-1, oangle=-1, outvol=-1):
"""Sets the 3D attributes of a sample, stream, or MOD music channel with 3D functionality."""
return bass_call(BASS_ChannelSet3DAttributes, self.handle, mode, min, max, iangle, oangle, outvol)
def get_3d_position(self):
"""Retrieves the 3D position of a sample, stream, or MOD music channel with 3D functionality."""
answer = dict(position=BASS_3DVECTOR(), orientation=BASS_3DVECTOR(), velocity=BASS_3DVECTOR())
bass_call(BASS_ChannelGet3DPosition, self.handle, pointer(answer['position']), pointer(answer['orientation']), pointer(answer['velocity']))
return answer
@update_3d_system
def set_3d_position(self, position=None, orientation=None, velocity=None):
"""Sets the 3D position of a sample, stream, or MOD music channel with 3D functionality."""
if position:
position = pointer(position)
if orientation:
orientation = pointer(orientation)
if velocity:
velocity = pointer(velocity)
return bass_call(BASS_ChannelSet3DPosition, self.handle, position, orientation, velocity)
def set_link(self, handle):
"""Links two MOD music or stream channels together."""
bass_call(BASS_ChannelSetLink, self.handle, handle)
def remove_link(self, handle):
"""Removes a link between two MOD music or stream channels."""
return bass_call(BASS_ChannelRemoveLink, self.handle, handle)
def __iadd__(self, other):
"""Convenience method to link this channel to another. Calls set_link on the passed in item's handle"""
self.set_link(other.handle)
return self
def __isub__(self, other):
"""Convenience method to unlink this channel from another. Calls remove_link on the passed in item's handle"""
self.remove_link(other.handle)
return self
def get_frequency(self):
return self.get_attribute(BASS_ATTRIB_FREQ )
def set_frequency(self, frequency):
self.set_attribute(BASS_ATTRIB_FREQ, frequency)
frequency = property(fget=get_frequency, fset=set_frequency)
def get_pan(self):
return self.get_attribute(BASS_ATTRIB_PAN)
def set_pan(self, pan):
return self.set_attribute(BASS_ATTRIB_PAN, pan)
pan = property(fget=get_pan, fset=set_pan)
def get_volume(self):
return self.get_attribute(BASS_ATTRIB_VOL)
def set_volume(self, volume):
self.set_attribute(BASS_ATTRIB_VOL, volume)
volume = property(fget=get_volume, fset=set_volume)
def get_data(self, length=16384):
buf = c_buffer(length)
bass_call_0(BASS_ChannelGetData, self.handle, pointer(buf), length)
return buf
#This is less and less of a one-to-one mapping,
#But I feel that it's better to be consistent with ourselves
#Than with the library. We won't punish ourselves
#For their bad decisions
def get_looping(self):
return bass_call_0(BASS_ChannelFlags, self.handle, BASS_SAMPLE_LOOP, 0) == 20
def set_looping(self, looping):
if looping:
return bass_call_0(BASS_ChannelFlags, self.handle, BASS_SAMPLE_LOOP, BASS_SAMPLE_LOOP)
return bass_call_0(BASS_ChannelFlags, self.handle, 0, BASS_SAMPLE_LOOP)
looping = property(fget=get_looping, fset=set_looping)
def __del__(self):
try:
self.free()
except:
pass
def get_x(self):
return self.get_3d_position()['position'].x
def set_x(self, val):
pos = self.get_3d_position()
pos['position'].x = val
self.set_3d_position(**pos)
x = property(fget=get_x, fset=set_x)
def get_y(self):
return self.get_3d_position()['position'].y
def set_y(self, val):
pos = self.get_3d_position()
pos['position'].y = val
self.set_3d_position(**pos)
y = property(fget=get_y, fset=set_y)
def get_z(self):
return self.get_3d_position()['position'].z
def set_z(self, val):
pos = self.get_3d_position()
pos['position'].z = val
self.set_3d_position(**pos)
z = property(fget=get_z, fset=set_z)
def get_attributes(self):
"""Retrieves all values of all attributes from this object and displays them in a dictionary whose keys are determined by this object's attribute_mapping"""
res = {}
for k in self.attribute_mapping:
try:
res[k] = self.get_attribute(k)
except BassError:
pass
return res

View File

@@ -1,57 +0,0 @@
import collections
import ctypes
from sound_lib.external import pybass
from sound_lib.main import bass_call, bass_call_0
class BassConfig(collections.Mapping):
config_map = {
'3d_algorithm': pybass.BASS_CONFIG_3DALGORITHM,
'buffer': pybass.BASS_CONFIG_BUFFER ,
'curve_vol': pybass.BASS_CONFIG_CURVE_VOL,
'curve_pan': pybass.BASS_CONFIG_CURVE_PAN,
'dev_buffer': pybass.BASS_CONFIG_DEV_BUFFER,
'dev_default': pybass.BASS_CONFIG_DEV_DEFAULT,
'float_dsp': pybass.BASS_CONFIG_FLOATDSP,
'gvol_music': pybass.BASS_CONFIG_GVOL_MUSIC,
'gvol_sample': pybass.BASS_CONFIG_GVOL_SAMPLE,
'gvol_stream': pybass.BASS_CONFIG_GVOL_STREAM,
'music_virtual': pybass.BASS_CONFIG_MUSIC_VIRTUAL,
'net_agent': pybass.BASS_CONFIG_NET_AGENT,
'net_buffer': pybass.BASS_CONFIG_NET_BUFFER,
'net_passive': pybass.BASS_CONFIG_NET_PASSIVE,
'net_playlist': pybass.BASS_CONFIG_NET_PLAYLIST,
'net_prebuf': pybass.BASS_CONFIG_NET_PREBUF,
'net_proxy': pybass.BASS_CONFIG_NET_PROXY,
'net_read_timeout': pybass.BASS_CONFIG_NET_READTIMEOUT,
'net_timeout': pybass.BASS_CONFIG_NET_TIMEOUT,
'pause_no_play': pybass.BASS_CONFIG_PAUSE_NOPLAY,
'rec_buffer': pybass.BASS_CONFIG_REC_BUFFER,
'src': pybass.BASS_CONFIG_SRC,
'src_sample': pybass.BASS_CONFIG_SRC_SAMPLE,
'unicode': pybass.BASS_CONFIG_UNICODE,
'update_period': pybass.BASS_CONFIG_UPDATEPERIOD,
'update_threads': pybass.BASS_CONFIG_UPDATETHREADS,
'verify': pybass.BASS_CONFIG_VERIFY,
'vista_speakers': pybass.BASS_CONFIG_VISTA_SPEAKERS,
}
ptr_config = (pybass.BASS_CONFIG_NET_AGENT, pybass.BASS_CONFIG_NET_PROXY)
def __getitem__(self, key):
key = self.config_map.get(key, key)
if key in self.ptr_config:
return ctypes.string_at(bass_call(pybass.BASS_GetConfigPtr, key))
return bass_call_0(pybass.BASS_GetConfig, key)
def __setitem__(self, key, val):
key = self.config_map.get(key, key)
if key in self.ptr_config:
return bass_call(pybass.BASS_SetConfigPtr, key, ctypes.create_string_buffer(val))
return bass_call(pybass.BASS_SetConfig, key, val)
def __iter__(self):
for key in self.config_map.keys():
yield key
def __len__(self):
return len(self.config_map)

View File

@@ -1 +0,0 @@
from .tempo import Tempo

View File

@@ -1,39 +0,0 @@
from __future__ import absolute_import
from sound_lib.external import pybass
from .effect import SoundEffect
class Chorus(SoundEffect):
effect_type = pybass.BASS_FX_DX8_CHORUS
struct = pybass.BASS_DX8_CHORUS
class Echo(SoundEffect):
effect_type = pybass.BASS_FX_DX8_ECHO
struct = pybass.BASS_DX8_ECHO
class Compressor(SoundEffect):
effect_type = pybass.BASS_FX_DX8_COMPRESSOR
struct = pybass.BASS_DX8_COMPRESSOR
class Reverb(SoundEffect):
effect_type = pybass.BASS_FX_DX8_REVERB
struct = pybass.BASS_DX8_REVERB
class Distortion(SoundEffect):
effect_type = pybass.BASS_FX_DX8_DISTORTION
struct = pybass.BASS_DX8_DISTORTION
class Flanger(SoundEffect):
effect_type = pybass.BASS_FX_DX8_FLANGER
struct = pybass.BASS_DX8_FLANGER
class Gargle(SoundEffect):
effect_type = pybass.BASS_FX_DX8_GARGLE
struct = pybass.BASS_DX8_GARGLE
class I3DL2Reverb(SoundEffect):
effect_type = pybass.BASS_FX_DX8_I3DL2REVERB
struct = pybass.BASS_DX8_I3DL2REVERB
class ParamEq(SoundEffect):
effect_type = pybass.BASS_FX_DX8_PARAMEQ
struct = pybass.BASS_DX8_PARAMEQ

View File

@@ -1,14 +0,0 @@
from __future__ import absolute_import
from sound_lib.external import pybass_fx
from .effect import SoundEffect
class Volume(SoundEffect):
effect_type = pybass_fx.BASS_FX_BFX_VOLUME
struct = pybass_fx.BASS_BFX_VOLUME
class PeakEq(SoundEffect):
effect_type = pybass_fx.BASS_FX_BFX_PEAKEQ
struct = pybass_fx.BASS_BFX_PEAKEQ
class DAmp(SoundEffect):
effect_type = pybass_fx.BASS_FX_BFX_DAMP
struct = pybass_fx.BASS_BFX_DAMP

View File

@@ -1,71 +0,0 @@
from future.builtins import object
from sound_lib.main import bass_call
import ctypes
from sound_lib.external import pybass
import string #for the alphabet!
class SoundEffect(object):
def __init__(self, channel, type=None, priority=0):
self.original_channel = channel
if hasattr(channel, 'handle'):
channel = channel.handle
if type is None:
type = self.effect_type
self.effect_type = type
self.priority = priority
self.handle = bass_call(pybass.BASS_ChannelSetFX, channel, type, priority)
def get_parameters(self):
"""Retrieves the parameters of an effect."""
res = {}
params = self.struct()
bass_call(pybass.BASS_FXGetParameters, self.handle, ctypes.pointer(params))
for f in params._fields_:
res[f[0]] = getattr(params, f[0])
return res
def set_parameters(self, parameters):
params = self.struct()
for p, v in parameters.items():
setattr(params, p, v)
bass_call(pybass.BASS_FXSetParameters, self.handle, ctypes.pointer(params))
def __dir__(self):
res = dir(self.__class__)
return res + self._get_pythonic_effect_fields()
def _get_effect_fields(self):
return [i[0] for i in self.struct._fields_]
def _get_pythonic_effect_fields(self):
return [self._bass_to_python(i) for i in self._get_effect_fields() if not i.startswith('_') ]
def _bass_to_python(self, func):
for c in string.ascii_lowercase:
func = func.replace(c.upper(), '_%s' % c)
if func.startswith('_'):
func = func[1:]
return func[2:]
def _python_to_bass(self, func):
for c in string.ascii_lowercase:
func = func.replace('_%s' % c, c.upper())
func = '%s%s' % (func[0].upper(), func[1:])
for f in self._get_effect_fields():
if f.endswith(func):
func = f
return func
def __getattr__(self, attr):
return self.get_parameters()[self._python_to_bass(attr)]
def __setattr__(self, attr, val):
if attr not in self._get_pythonic_effect_fields():
return super(SoundEffect, self).__setattr__(attr, val)
params = self.get_parameters()
key = self._python_to_bass(attr)
if key not in params:
raise AttributeError('Unable to set attribute, suspect issue with base name-munging code')
params[key] = val
self.set_parameters(params)

View File

@@ -1,65 +0,0 @@
import ctypes
from sound_lib.external import pybass, pybass_fx
from sound_lib.stream import BaseStream
from sound_lib.channel import Channel
from sound_lib.main import bass_call, bass_call_0
class Tempo(BaseStream):
def __init__(self, channel, flags=0, loop=False, software=False, three_d=False, sample_fx=False, autofree=False, decode=False, free_source=False):
flags = flags | self.flags_for(loop=False, software=False, three_d=False, sample_fx=False, autofree=False, decode=False, free_source=False)
self.channel = channel
if isinstance(channel, Channel):
channel = channel.handle
handle = bass_call(pybass_fx.BASS_FX_TempoCreate, channel, flags)
super(Tempo, self).__init__(handle)
self.add_attributes_to_mapping(
tempo=pybass_fx.BASS_ATTRIB_TEMPO,
tempo_pitch=pybass_fx.BASS_ATTRIB_TEMPO_PITCH,
tempo_freq=pybass_fx.BASS_ATTRIB_TEMPO_FREQ,
)
@property
def tempo(self):
"""The tempo of a channel."""
return self.get_attribute(pybass_fx.BASS_ATTRIB_TEMPO)
@tempo.setter
def tempo(self, val):
self.set_attribute('tempo', val)
@property
def tempo_pitch(self):
return self.get_attribute('tempo_pitch')
@tempo_pitch.setter
def tempo_pitch(self, val):
self.set_attribute('tempo_pitch', val)
@property
def tempo_freq(self):
return self.get_attribute('tempo_freq')
@tempo_freq.setter
def tempo_freq(self, val):
self.set_attribute('tempo_freq', val)
def setup_flag_mapping(self):
super(Tempo, self).setup_flag_mapping()
self.flag_mapping.update({
'free_source': pybass_fx.BASS_FX_FREESOURCE,
})
def get_source(self):
source = pybass_fx.BASS_FX_TempoGetSource(self.handle)
if source == self.channel.handle:
source = self.channel
return source
source = property(fget=get_source)
def get_rate_ratio(self):
return bass_call(pybass_fx.BASS_FX_TempoGetRateRatio, self.handle)
rate_ratio = property(fget=get_rate_ratio)

View File

@@ -1,81 +0,0 @@
from __future__ import absolute_import
from .external import pybass, pybassenc
from .main import bass_call, bass_call_0, FlagObject
class Encoder(FlagObject):
def setup_flag_mapping(self):
#super(Encoder, self).setup_flag_mapping()
self.flag_mapping = {
'pcm': pybassenc.BASS_ENCODE_PCM,
'no_header': pybassenc.BASS_ENCODE_NOHEAD,
'rf64': pybassenc.BASS_ENCODE_RF64,
'big_endian': pybassenc.BASS_ENCODE_BIGEND,
'fp_8bit': pybassenc.BASS_ENCODE_FP_8BIT,
'fp_16bit': pybassenc.BASS_ENCODE_FP_16BIT,
'fp_24bit': pybassenc.BASS_ENCODE_FP_24BIT,
'fp_32bit': pybassenc.BASS_ENCODE_FP_32BIT,
'queue': pybassenc.BASS_ENCODE_QUEUE,
'limit': pybassenc.BASS_ENCODE_LIMIT,
'no_limit': pybassenc.BASS_ENCODE_CAST_NOLIMIT,
'pause': pybassenc.BASS_ENCODE_PAUSE,
'autofree': pybassenc.BASS_ENCODE_AUTOFREE,
'unicode': pybass.BASS_UNICODE,
}
def __init__(self, source, command_line, pcm=False, no_header=False, rf64=False, big_endian=False, fp_8bit=False, fp_16bit=False, fp_24bit=False, fp_32bit=False, queue=False, limit=False, no_limit=False, pause=True, autofree=False, callback=None, user=None):
self.setup_flag_mapping()
flags = self.flags_for(pcm=pcm, no_header=no_header, rf64=rf64, big_endian=big_endian, fp_8bit=fp_8bit, fp_16bit=fp_16bit, fp_24bit=fp_24bit, fp_32bit=fp_32bit, queue=queue, limit=limit, no_limit=no_limit, pause=pause, autofree=autofree) #fwiw!
self.source = source
source_handle = source.handle
if callback is None:
callback = lambda *a: None
callback = pybassenc.ENCODEPROC(callback)
self.callback = callback
self.handle = bass_call(pybassenc.BASS_Encode_Start, source_handle, command_line, flags, callback, user)
@property
def paused(self):
return bass_call_0(pybassenc.BASS_Encode_IsActive, self.handle) == pybass.BASS_ACTIVE_PAUSED
@paused.setter
def paused(self, paused):
return bass_call(pybassenc.BASS_Encode_SetPaused, self.handle, paused)
def is_stopped(self):
return bass_call_0(pybassenc.BASS_Encode_IsActive, self.handle) == pybass.BASS_ACTIVE_STOPPED
def stop(self):
return bass_call(pybassenc.BASS_Encode_Stop, self.handle)
class BroadcastEncoder(Encoder):
def __init__(self, source_encoder, server, password, content, name=None, url=None, genre=None, description=None, headers=None, bitrate=0, public=False):
contents = {
'mp3': pybassenc.BASS_ENCODE_TYPE_MP3,
'ogg': pybassenc.BASS_ENCODE_TYPE_OGG,
'aac': pybassenc.BASS_ENCODE_TYPE_AAC
}
if content in contents:
content = contents[content]
self.source_encoder = source_encoder
handle = source_encoder.handle
self.server = server
self.password = password
self.status = bass_call(pybassenc.BASS_Encode_CastInit, handle, server, password, content, name, url, genre, description, headers, bitrate, public)
def set_title(self, title=None, url=None):
return bass_call(pybassenc.BASS_Encode_CastSetTitle, self.source_encoder.handle, title, url)
def get_stats(self, type, password=None):
types = {
'shoutcast': pybassenc.BASS_ENCODE_STATS_SHOUT,
'icecast': pybassenc.BASS_ENCODE_STATS_ICE,
'icecast_server': pybassenc.BASS_ENCODE_STATS_ICESERV,
}
if type in types:
type = types[type]
if password is None:
password = self.password
return bass_call(pybassenc.BASS_Encode_CastGetStats, self.handle, type, password)

View File

@@ -1,9 +0,0 @@
import platform
#if platform.system() == 'Windows':
# import sound_lib.external.pybasswma
if platform.system() != 'Darwin':
import sound_lib.external.pybass_aac
import sound_lib.external.pybass_alac
import sound_lib.external.pybassopus
import sound_lib.external.pybassflac
import sound_lib.external.pybassmidi

View File

@@ -1,9 +0,0 @@
import os
from platform_utils.paths import module_path, is_frozen, embedded_data_path
if is_frozen():
x86_path = os.path.join(embedded_data_path(), 'sound_lib', 'lib', 'x86')
x64_path = os.path.join(embedded_data_path(), 'sound_lib', 'lib', 'x64')
else:
x86_path = os.path.join(module_path(), '..', 'lib', 'x86')
x64_path = os.path.join(module_path(), '..', 'lib', 'x64')

File diff suppressed because it is too large Load Diff

View File

@@ -1,54 +0,0 @@
from __future__ import absolute_import
# Copyright(c) Max Kolosov 2009 maxkolosov@inbox.ru
# http://vosolok2008.narod.ru
# BSD license
__version__ = '0.1'
__versionTime__ = '2009-11-15'
__author__ = 'Max Kolosov <maxkolosov@inbox.ru>'
__doc__ = '''
pybass_aac.py - is ctypes python module for
BASS_AAC - extension to the BASS audio library that enables the playback
of Advanced Audio Coding and MPEG-4 streams (http://www.maresweb.de).
'''
import os, sys, ctypes
from . import pybass
from .paths import x86_path, x64_path
import libloader
bass_aac_module = libloader.load_library('bass_aac', x86_path=x86_path, x64_path=x64_path)
func_type = libloader.get_functype()
#Register the plugin with the Bass plugin system.
pybass.BASS_PluginLoad(libloader.find_library_path('bass_aac', x86_path=x86_path, x64_path=x64_path), 0)
QWORD = pybass.QWORD
HSTREAM = pybass.HSTREAM
DOWNLOADPROC = pybass.DOWNLOADPROC
BASS_FILEPROCS = pybass.BASS_FILEPROCS
# Additional BASS_SetConfig options
BASS_CONFIG_MP4_VIDEO = 0x10700 # play the audio from MP4 videos
# Additional tags available from BASS_StreamGetTags (for MP4 files)
BASS_TAG_MP4 = 7 # MP4/iTunes metadata
BASS_AAC_STEREO = 0x400000 # downmatrix to stereo
# BASS_CHANNELINFO type
BASS_CTYPE_STREAM_AAC = 0x10b00 # AAC
BASS_CTYPE_STREAM_MP4 = 0x10b01 # MP4
#HSTREAM BASSAACDEF(BASS_AAC_StreamCreateFile)(BOOL mem, const void *file, QWORD offset, QWORD length, DWORD flags);
BASS_AAC_StreamCreateFile = func_type(HSTREAM, ctypes.c_byte, ctypes.c_void_p, QWORD, QWORD, ctypes.c_ulong)(('BASS_AAC_StreamCreateFile', bass_aac_module))
#HSTREAM BASSAACDEF(BASS_AAC_StreamCreateURL)(const char *url, DWORD offset, DWORD flags, DOWNLOADPROC *proc, void *user);
BASS_AAC_StreamCreateURL = func_type(HSTREAM, ctypes.c_char_p, ctypes.c_ulong, ctypes.c_ulong, DOWNLOADPROC, ctypes.c_void_p)(('BASS_AAC_StreamCreateURL', bass_aac_module))
#HSTREAM BASSAACDEF(BASS_AAC_StreamCreateFileUser)(DWORD system, DWORD flags, const BASS_FILEPROCS *procs, void *user);
BASS_AAC_StreamCreateFileUser = func_type(HSTREAM, ctypes.c_ulong, ctypes.c_ulong, ctypes.POINTER(BASS_FILEPROCS), ctypes.c_void_p)(('BASS_AAC_StreamCreateFileUser', bass_aac_module))
#HSTREAM BASSAACDEF(BASS_MP4_StreamCreateFile)(BOOL mem, const void *file, QWORD offset, QWORD length, DWORD flags);
BASS_MP4_StreamCreateFile = func_type(HSTREAM, ctypes.c_byte, ctypes.c_void_p, QWORD, QWORD, ctypes.c_ulong)(('BASS_MP4_StreamCreateFile', bass_aac_module))
#HSTREAM BASSAACDEF(BASS_MP4_StreamCreateFileUser)(DWORD system, DWORD flags, const BASS_FILEPROCS *procs, void *user);
BASS_MP4_StreamCreateFileUser = func_type(HSTREAM, ctypes.c_ulong, ctypes.c_ulong, ctypes.POINTER(BASS_FILEPROCS), ctypes.c_void_p)(('BASS_MP4_StreamCreateFileUser', bass_aac_module))

View File

@@ -1,24 +0,0 @@
from __future__ import absolute_import
"BASS_ALAC wrapper by Christopher Toth"""
import ctypes
import os
from . import pybass
from .paths import x86_path, x64_path
import libloader
bass_fx_module = libloader.load_library('bass_alac', x86_path=x86_path, x64_path=x64_path)
func_type = libloader.get_functype()
pybass.BASS_PluginLoad(libloader.find_library_path('bass_alac', x86_path=x86_path, x64_path=x64_path), 0)
BASS_TAG_MP4 = 7
BASS_CTYPE_STREAM_ALAC = 0x10e00
#HSTREAM BASSALACDEF(BASS_ALAC_StreamCreateFile)(BOOL mem, const void *file, QWORD offset, QWORD length, DWORD flags);
BASS_ALAC_StreamCreateFile = func_type(pybass.HSTREAM, ctypes.c_byte, ctypes.c_void_p, pybass.QWORD, pybass.QWORD, ctypes.c_ulong)
#HSTREAM BASSALACDEF(BASS_ALAC_StreamCreateFileUser)(DWORD system, DWORD flags, const BASS_FILEPROCS *procs, void *user);
BASS_ALAC_StreamCreateFileUser = func_type(pybass.HSTREAM, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_void_p, ctypes.c_void_p)

View File

@@ -1,384 +0,0 @@
from __future__ import absolute_import
from future.builtins import range
"BASS_FX wrapper by Christopher Toth"""
import ctypes
import os
from . import pybass
from .paths import x86_path, x64_path
import libloader
bass_fx_module = libloader.load_library('bass_fx', x86_path=x86_path, x64_path=x64_path)
func_type = libloader.get_functype()
#Error codes returned by BASS_ErrorGetCode
BASS_ERROR_FX_NODECODE = 4000
BASS_ERROR_FX_BPMINUSE = 4001
#Tempo / Reverse / BPM / Beat flag
BASS_FX_FREESOURCE = 0x10000
#BASS_FX Version
BASS_FX_GetVersion = func_type(ctypes.c_ulong)(('BASS_FX_GetVersion', bass_fx_module))
"""D S P (Digital Signal Processing)"""
"""
Multi-channel order of each channel is as follows:
3 channels left-front, right-front, center.
4 channels left-front, right-front, left-rear/side, right-rear/side.
6 channels (5.1) left-front, right-front, center, LFE, left-rear/side, right-rear/side.
8 channels (7.1) left-front, right-front, center, LFE, left-rear/side, right-rear/side, left-rear center, right-rear center.
"""
#DSP channels flags
BASS_BFX_CHANALL = -1 #all channels at once (as by default)
BASS_BFX_CHANNONE = 0 #disable an effect for all channels
BASS_BFX_CHAN1 = 1 #left-front channel
BASS_BFX_CHAN2 = 2 #right-front channel
BASS_BFX_CHAN3 = 4 #see above info
BASS_BFX_CHAN4 = 8 #see above info
BASS_BFX_CHAN5 = 16
BASS_BFX_CHAN6 = 32
BASS_BFX_CHAN7 = 64
BASS_BFX_CHAN8 = 128
#DSP effects
(
BASS_FX_BFX_ROTATE,
BASS_FX_BFX_ECHO,
BASS_FX_BFX_FLANGER,
BASS_FX_BFX_VOLUME,
BASS_FX_BFX_PEAKEQ,
BASS_FX_BFX_REVERB,
BASS_FX_BFX_LPF,
BASS_FX_BFX_MIX,
BASS_FX_BFX_DAMP,
BASS_FX_BFX_AUTOWAH,
BASS_FX_BFX_ECHO2,
BASS_FX_BFX_PHASER,
BASS_FX_BFX_ECHO3,
BASS_FX_BFX_CHORUS,
BASS_FX_BFX_APF,
BASS_FX_BFX_COMPRESSOR,
BASS_FX_BFX_DISTORTION,
BASS_FX_BFX_COMPRESSOR2,
BASS_FX_BFX_VOLUME_ENV,
BASS_FX_BFX_BQF,
) = range(0x10000, 0x10000+20)
#BiQuad filters
(
BASS_BFX_BQF_LOWPASS,
BASS_BFX_BQF_HIGHPASS,
BASS_BFX_BQF_BANDPASS, #constant 0 dB peak gain
BASS_BFX_BQF_BANDPASS_Q, #constant skirt gain, peak gain = Q
BASS_BFX_BQF_NOTCH,
BASS_BFX_BQF_ALLPASS,
BASS_BFX_BQF_PEAKINGEQ,
BASS_BFX_BQF_LOWSHELF,
BASS_BFX_BQF_HIGHSHELF,
) = range(9)
#Echo
class BASS_BFX_ECHO(ctypes.Structure):
_fields_ = [
('fLevel', ctypes.c_float), #[0....1....n] linear
('lDelay', ctypes.c_int), #[1200..30000]
]
#Flanger
class BASS_BFX_FLANGER(ctypes.Structure):
_fields_ = [
('fWetDry', ctypes.c_float), #[0....1....n] linear
('fSpeed', ctypes.c_float), #[0......0.09]
('lChannel', ctypes.c_int), #BASS_BFX_CHANxxx flag/s
]
#volume
class BASS_BFX_VOLUME(ctypes.Structure):
_fields_ = [
('lChannel', ctypes.c_int), #BASS_BFX_CHANxxx flag/s or 0 for global volume control
('fVolume', ctypes.c_float), #[0....1....n] linear
]
#Peaking Equalizer
class BASS_BFX_PEAKEQ(ctypes.Structure):
_fields_ = [
('lBand', ctypes.c_int), #[0...............n] more bands means more memory & cpu usage
('fBandwidth', ctypes.c_float), #[0.1...........<10] in octaves - fQ is not in use (Bandwidth has a priority over fQ)
('fQ', ctypes.c_float), #[0...............1] the EE kinda definition (linear) (if Bandwidth is not in use)
('fCenter', ctypes.c_float), #[1Hz..<info.freq/2] in Hz
('fGain', ctypes.c_float), #[-15dB...0...+15dB] in dB
('lChannel', ctypes.c_float), #BASS_BFX_CHANxxx flag/s
]
#Reverb
class BASS_BFX_REVERB(ctypes.Structure):
_fields_ = [
('fLevel', ctypes.c_float), #[0....1....n] linear
('lDelay', ctypes.c_int), #[1200..10000]
]
#Low Pass Filter
class BASS_BFX_LPF(ctypes.Structure):
_fields_ = [
('fResonance', ctypes.c_float), #[0.01...........10]
('fCutOffFreq', ctypes.c_float), #[1Hz...info.freq/2] cutoff frequency
('lChannel', ctypes.c_int), #BASS_BFX_CHANxxx flag/s
]
#Swap, remap and mix
class BASS_BFX_MIX(ctypes.Structure):
_fields_ = [
('lChannel', ctypes.c_int), #an array of channels to mix using BASS_BFX_CHANxxx flag/s (lChannel[0] is left channel...)
]
#Dynamic Amplification
class BASS_BFX_DAMP(ctypes.Structure):
_fields_ = [
('fTarget', ctypes.c_float), #target volume level [0<......1] linear
('fQuiet', ctypes.c_float), #quiet volume level [0.......1] linear
('fRate', ctypes.c_float), #amp adjustment rate [0.......1] linear
('fGain', ctypes.c_float), #amplification level [0...1...n] linear
('fDelay', ctypes.c_float), #delay in seconds before increasing level [0.......n] linear
('lChannel', ctypes.c_int), #BASS_BFX_CHANxxx flag/s
]
#Auto WAH
class BASS_BFX_AUTOWAH(ctypes.Structure):
_fields_ = [
('fDryMix', ctypes.c_float), #dry (unaffected) signal mix [-2......2]
('fWetMix', ctypes.c_float), #wet (affected) signal mix [-2......2]
('fFeedback', ctypes.c_float), #feedback [-1......1]
('fRate', ctypes.c_float), #rate of sweep in cycles per second [0<....<10]
('fRange', ctypes.c_float), #sweep range in octaves [0<....<10]
('fFreq', ctypes.c_float), #base frequency of sweep Hz [0<...1000]
('lChannel', ctypes.c_int), #BASS_BFX_CHANxxx flag/s
]
#Echo 2
class BASS_BFX_ECHO2(ctypes.Structure):
_fields_ = [
('fDryMix', ctypes.c_float), #dry (unaffected) signal mix [-2......2]
('fWetMix', ctypes.c_float), #wet (affected) signal mix [-2......2]
('fFeedback', ctypes.c_float), #feedback [-1......1]
('fDelay', ctypes.c_float), #delay sec [0<......n]
('lChannel', ctypes.c_int), #BASS_BFX_CHANxxx flag/s
]
#Phaser
class BASS_BFX_PHASER(ctypes.Structure):
_fields_ = [
('fDryMix', ctypes.c_float), #dry (unaffected) signal mix [-2......2]
('fWetMix', ctypes.c_float), #wet (affected) signal mix [-2......2]
('fFeedback', ctypes.c_float), #feedback [-1......1]
('fRate', ctypes.c_float), #rate of sweep in cycles per second [0<....<10]
('fRange', ctypes.c_float), #sweep range in octaves [0<....<10]
('fFreq', ctypes.c_float), #base frequency of sweep [0<...1000]
('lChannel', ctypes.c_int), #BASS_BFX_CHANxxx flag/s
]
#Echo 3
class BASS_BFX_ECHO3(ctypes.Structure):
_fields_ = [
('fDryMix', ctypes.c_float), #dry (unaffected) signal mix [-2......2]
('fWetMix', ctypes.c_float), #wet (affected) signal mix [-2......2]
('fDelay', ctypes.c_float), #delay sec [0<......n]
('lChannel', ctypes.c_int), #BASS_BFX_CHANxxx flag/s
]
#Chorus
class BASS_BFX_CHORUS(ctypes.Structure):
_fields_ = [
('fDryMix', ctypes.c_float), #dry (unaffected) signal mix [-2......2]
('fWetMix', ctypes.c_float), #wet (affected) signal mix [-2......2]
('fFeedback', ctypes.c_float), #feedback [-1......1]
('fMinSweep', ctypes.c_float), #minimal delay ms [0<...6000]
('fMaxSweep', ctypes.c_float), #maximum delay ms [0<...6000]
('fRate', ctypes.c_float), #rate ms/s [0<...1000]
('lChannel', ctypes.c_int), #BASS_BFX_CHANxxx flag/s
]
#All Pass Filter
class BASS_BFX_APF(ctypes.Structure):
_fields_ = [
('fGain', ctypes.c_float), #reverberation time [-1=<..<=1]
('fDelay', ctypes.c_float), #delay sec [0<....<=n]
('lChannel', ctypes.c_int), #BASS_BFX_CHANxxx flag/s
]
#Compressor
class BASS_BFX_COMPRESSOR(ctypes.Structure):
_fields_ = [
('fThreshold', ctypes.c_float), #compressor threshold [0<=...<=1]
('fAttacktime', ctypes.c_float), #attack time ms [0<.<=1000]
('fReleasetime', ctypes.c_float), #release time ms [0<.<=5000]
('lChannel', ctypes.c_int), #BASS_BFX_CHANxxx flag/s
]
#Distortion
class BASS_BFX_DISTORTION(ctypes.Structure):
_fields_ = [
('fDrive', ctypes.c_float), #distortion drive [0<=...<=5]
('fDryMix', ctypes.c_float), #dry (unaffected) signal mix [-5<=..<=5]
('fWetMix', ctypes.c_float), #wet (affected) signal mix [-5<=..<=5]
('fFeedback', ctypes.c_float), #feedback [-1<=..<=1]
('fVolume', ctypes.c_float), #distortion volume [0=<...<=2]
('lChannel', ctypes.c_int), #BASS_BFX_CHANxxx flag/s
]
#Compressor 2
class BASS_BFX_COMPRESSOR2(ctypes.Structure):
_fields_ = [
('fGain', ctypes.c_float), #output gain of signal after compression [-60....60] in dB
('fThreshold', ctypes.c_float), #point at which compression begins [-60.....0] in dB
('fRatio', ctypes.c_float), #compression ratio [1.......n]
('fAttack', ctypes.c_float), #attack time in ms [0.01.1000]
('fRelease', ctypes.c_float), #release time in ms [0.01.5000]
('lChannel', ctypes.c_int), #BASS_BFX_CHANxxx flag/s
]
class BASS_BFX_ENV_NODE(ctypes.Structure):
_fields_ = [
('pos', ctypes.c_long), #node position in seconds (1st envelope node must be at position 0)
('val', ctypes.c_float), #node value
]
#Volume envelope
class BASS_BFX_VOLUME_ENV(ctypes.Structure):
_fields_ = [
('lChannel', ctypes.c_int), #BASS_BFX_CHANxxx flag/s
('lNodeCount', ctypes.c_int), #number of nodes
('pNodes', BASS_BFX_ENV_NODE), #the nodes
('bFollow', ctypes.c_bool), #follow source position
]
#BiQuad Filters
class BASS_BFX_BQF(ctypes.Structure):
_fields_ = [
('lFilter', ctypes.c_int), #BASS_BFX_BQF_xxx filter types
('fCenter', ctypes.c_float), #[1Hz..<info.freq/2] Cutoff (central) frequency in Hz
('fGain', ctypes.c_float), #[-15dB...0...+15dB] Used only for PEAKINGEQ and Shelving filters in dB
('fBandwidth', ctypes.c_float), #[0.1...........<10] Bandwidth in octaves (fQ is not in use (fBandwidth has a priority over fQ))
#(between -3 dB frequencies for BANDPASS and NOTCH or between midpoint
#(fGgain/2) gain frequencies for PEAKINGEQ)
('fQ', ctypes.c_float), #[0.1.............1] The EE kinda definition (linear) (if fBandwidth is not in use)
('fS', ctypes.c_float), #[0.1.............1] A "shelf slope" parameter (linear) (used only with Shelving filters)
#when fS = 1, the shelf slope is as steep as you can get it and remain monotonically
#increasing or decreasing gain with frequency.
('lChannel', ctypes.c_int), #BASS_BFX_CHANxxx flag/s
]
"""TEMPO / PITCH SCALING / SAMPLERATE"""
"""NOTES: 1. Supported only - mono / stereo - channels
2. Enable Tempo supported flags in BASS_FX_TempoCreate and the others to source handle.
tempo attributes (BASS_ChannelSet/GetAttribute)"""
(
BASS_ATTRIB_TEMPO,
BASS_ATTRIB_TEMPO_PITCH,
BASS_ATTRIB_TEMPO_FREQ,
) = range(0x10000, 0x10000+3)
#tempo attributes options
#[option] [value]
(
BASS_ATTRIB_TEMPO_OPTION_USE_AA_FILTER, #TRUE (default) / FALSE
BASS_ATTRIB_TEMPO_OPTION_AA_FILTER_LENGTH, #32 default (8 .. 128 taps)
BASS_ATTRIB_TEMPO_OPTION_USE_QUICKALGO, #TRUE / FALSE (default)
BASS_ATTRIB_TEMPO_OPTION_SEQUENCE_MS, #82 default, 0 = automatic
BASS_ATTRIB_TEMPO_OPTION_SEEKWINDOW_MS, #28 default, 0 = automatic
BASS_ATTRIB_TEMPO_OPTION_OVERLAP_MS, #8 default
BASS_ATTRIB_TEMPO_OPTION_PREVENT_CLICK, #TRUE / FALSE (default)
) = range(0x10000, 0x10000+7)
#HSTREAM BASS_FXDEF(BASS_FX_TempoCreate)(DWORD chan, DWORD flags);
BASS_FX_TempoCreate = func_type(pybass.HSTREAM, ctypes.c_ulong, ctypes.c_ulong)(('BASS_FX_TempoCreate', bass_fx_module))
#DWORD BASS_FXDEF(BASS_FX_TempoGetSource)(HSTREAM chan);
BASS_FX_TempoGetSource = func_type(ctypes.c_ulong, pybass.HSTREAM)(('BASS_FX_TempoGetSource', bass_fx_module))
#float BASS_FXDEF(BASS_FX_TempoGetRateRatio)(HSTREAM chan);
BASS_FX_TempoGetRateRatio = func_type(ctypes.c_float, pybass.HSTREAM)(('BASS_FX_TempoGetRateRatio', bass_fx_module))
"""R E V E R S E"""
"""NOTES: 1. MODs won't load without BASS_MUSIC_PRESCAN flag.
2. Enable Reverse supported flags in BASS_FX_ReverseCreate and the others to source handle."""
#reverse attribute (BASS_ChannelSet/GetAttribute)
BASS_ATTRIB_REVERSE_DIR = 0x11000
#playback directions
BASS_FX_RVS_REVERSE = -1
BASS_FX_RVS_FORWARD = 1
#HSTREAM BASS_FXDEF(BASS_FX_ReverseCreate)(DWORD chan, float dec_block, DWORD flags);
BASS_FX_ReverseCreate = func_type(pybass.HSTREAM, ctypes.c_ulong, ctypes.c_float, ctypes.c_ulong)(('BASS_FX_ReverseCreate', bass_fx_module))
#DWORD BASS_FXDEF(BASS_FX_ReverseGetSource)(HSTREAM chan);
BASS_FX_ReverseGetSource = func_type(ctypes.c_ulong, pybass.HSTREAM)(('BASS_FX_ReverseGetSource', bass_fx_module))
"""B P M (Beats Per Minute)"""
#bpm flags
BASS_FX_BPM_BKGRND = 1 #if in use, then you can do other processing while detection's in progress. Not available in MacOSX yet. (BPM/Beat)
BASS_FX_BPM_MULT2 = 2 #if in use, then will auto multiply bpm by 2 (if BPM < minBPM*2)
#translation options
(
BASS_FX_BPM_TRAN_X2, #multiply the original BPM value by 2 (may be called only once & will change the original BPM as well!)
BASS_FX_BPM_TRAN_2FREQ, #BPM value to Frequency
BASS_FX_BPM_TRAN_FREQ2, #Frequency to BPM value
BASS_FX_BPM_TRAN_2PERCENT, #BPM value to Percents
BASS_FX_BPM_TRAN_PERCENT2 , #Percents to BPM value
) = range(5)
#typedef void (CALLBACK BPMPROCESSPROC)(DWORD chan, float percent);
BPMPROCESSPROC = func_type(None, ctypes.c_float)
#typedef void (CALLBACK BPMPROC)(DWORD chan, float bpm, void *user);
BPMPROC = func_type(None, ctypes.c_long, ctypes.c_float, ctypes.c_void_p)
#float BASS_FXDEF(BASS_FX_BPM_DecodeGet)(DWORD chan, double startSec, double endSec, DWORD minMaxBPM, DWORD flags, BPMPROCESSPROC *proc);
BASS_FX_BPM_DecodeGet = func_type(ctypes.c_float, ctypes.c_ulong, ctypes.c_double, ctypes.c_double, ctypes.c_ulong, ctypes.c_ulong, BPMPROCESSPROC)(('BASS_FX_BPM_DecodeGet', bass_fx_module))
#BOOL BASS_FXDEF(BASS_FX_BPM_CallbackSet)(DWORD handle, BPMPROC *proc, double period, DWORD minMaxBPM, DWORD flags, void *user);
BASS_FX_BPM_CallbackSet = func_type(ctypes.c_bool, ctypes.c_ulong, BPMPROC, ctypes.c_double, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_void_p)(('BASS_FX_BPM_CallbackSet', bass_fx_module))
#BOOL BASS_FXDEF(BASS_FX_BPM_CallbackReset)(DWORD handle);
BASS_FX_BPM_CallbackReset = func_type(ctypes.c_bool, ctypes.c_ulong)(('BASS_FX_BPM_CallbackReset', bass_fx_module))
#float BASS_FXDEF(BASS_FX_BPM_Translate)(DWORD handle, float val2tran, DWORD trans);
BASS_FX_BPM_Translate = func_type(ctypes.c_float, ctypes.c_ulong, ctypes.c_float, ctypes.c_ulong)(('BASS_FX_BPM_Translate', bass_fx_module))
#BOOL BASS_FXDEF(BASS_FX_BPM_Free)(DWORD handle);
BASS_FX_BPM_Free = func_type(ctypes.c_bool, ctypes.c_ulong)(('BASS_FX_BPM_Free', bass_fx_module))
""" Beat """
#typedef void (CALLBACK BPMBEATPROC)(DWORD chan, double beatpos, void *user);
BPMBEATPROC = func_type(None, ctypes.c_ulong, ctypes.c_double, ctypes.c_void_p)
#BOOL BASS_FXDEF(BASS_FX_BPM_BeatCallbackSet)(DWORD handle, BPMBEATPROC *proc, void *user);
BASS_FX_BPM_BeatCallbackSet = func_type(ctypes.c_bool, ctypes.c_ulong, ctypes.c_void_p)(('BASS_FX_BPM_BeatCallbackSet', bass_fx_module))
#BOOL BASS_FXDEF(BASS_FX_BPM_BeatCallbackReset)(DWORD handle);
BASS_FX_BPM_BeatCallbackReset = func_type(ctypes.c_bool, ctypes.c_ulong)(('BASS_FX_BPM_BeatCallbackReset', bass_fx_module))
#BOOL BASS_FXDEF(BASS_FX_BPM_BeatDecodeGet)(DWORD chan, double startSec, double endSec, DWORD flags, BPMBEATPROC *proc, void *user);
BASS_FX_BPM_BeatDecodeGet = func_type(ctypes.c_bool, ctypes.c_ulong, ctypes.c_double, ctypes.c_double, ctypes.c_ulong, BPMBEATPROC, ctypes.c_void_p)(('BASS_FX_BPM_BeatDecodeGet', bass_fx_module))
#BOOL BASS_FXDEF(BASS_FX_BPM_BeatSetParameters)(DWORD handle, float bandwidth, float centerfreq, float beat_rtime);
BASS_FX_BPM_BeatSetParameters = func_type(ctypes.c_bool, ctypes.c_ulong, ctypes.c_float, ctypes.c_float, ctypes.c_float)(('BASS_FX_BPM_BeatSetParameters', bass_fx_module))
#BOOL BASS_FXDEF(BASS_FX_BPM_BeatGetParameters)(DWORD handle, float *bandwidth, float *centerfreq, float *beat_rtime);
BASS_FX_BPM_BeatGetParameters = func_type(ctypes.c_bool, ctypes.c_ulong, ctypes.c_float, ctypes.c_float, ctypes.c_float)(('BASS_FX_BPM_BeatGetParameters', bass_fx_module))
#BOOL BASS_FXDEF(BASS_FX_BPM_BeatFree)(DWORD handle);
BASS_FX_BPM_BeatFree = func_type(ctypes.c_bool, ctypes.c_ulong)(('BASS_FX_BPM_BeatFree', bass_fx_module))

View File

@@ -1,170 +0,0 @@
from __future__ import absolute_import
from future.builtins import range
"BASSENC wrapper by Christopher Toth"""
import ctypes
import os
import platform
from . import pybass
from .paths import x86_path, x64_path
import libloader
bassenc_module = libloader.load_library('bassenc', x86_path=x86_path, x64_path=x64_path)
func_type = libloader.get_functype()
HENCODE = ctypes.c_ulong #encoder handle
#Additional error codes returned by BASS_ErrorGetCode
BASS_ERROR_ACM_CANCEL = 2000 #ACM codec selection cancelled
pybass.error_descriptions[BASS_ERROR_ACM_CANCEL] = "ACM codec selection cancelled"
BASS_ERROR_CAST_DENIED = 2100 #access denied (invalid password)
pybass.error_descriptions[BASS_ERROR_CAST_DENIED] = "access denied (invalid password)"
#Additional BASS_SetConfig options
BASS_CONFIG_ENCODE_PRIORITY = 0x10300
BASS_CONFIG_ENCODE_QUEUE = 0x10301
BASS_CONFIG_ENCODE_CAST_TIMEOUT = 0x10310
#Additional BASS_SetConfigPtr options
BASS_CONFIG_ENCODE_CAST_PROXY = 0x10311
#BASS_Encode_Start flags
BASS_ENCODE_NOHEAD = 1 #don't send a WAV header to the encoder
BASS_ENCODE_FP_8BIT = 2 #convert floating-point sample data to 8-bit integer
BASS_ENCODE_FP_16BIT = 4 #convert floating-point sample data to 16-bit integer
BASS_ENCODE_FP_24BIT = 6#convert floating-point sample data to 24-bit integer
BASS_ENCODE_FP_32BIT = 8 #convert floating-point sample data to 32-bit integer
BASS_ENCODE_BIGEND = 16 #big-endian sample data
BASS_ENCODE_PAUSE = 32 #start encoding paused
BASS_ENCODE_PCM = 64 #write PCM sample data (no encoder)
BASS_ENCODE_RF64 = 128 #send an RF64 header
BASS_ENCODE_MONO = 256 #convert to mono (if not already)
BASS_ENCODE_QUEUE = 512 #queue data to feed encoder asynchronously
BASS_ENCODE_CAST_NOLIMIT = 0x1000 #don't limit casting data rate
BASS_ENCODE_LIMIT = 0x2000 #limit data rate to real-time
BASS_ENCODE_AUTOFREE = 0x40000 #free the encoder when the channel is freed
#BASS_Encode_GetACMFormat flags
BASS_ACM_DEFAULT = 1 #use the format as default selection
BASS_ACM_RATE = 2 #only list formats with same sample rate as the source channel
BASS_ACM_CHANS = 4 #only list formats with same number of channels (eg. mono/stereo)
BASS_ACM_SUGGEST = 8 #suggest a format (HIWORD=format tag)
#BASS_Encode_GetCount counts
(
BASS_ENCODE_COUNT_IN, #sent to encoder
BASS_ENCODE_COUNT_OUT, #received from encoder
BASS_ENCODE_COUNT_CAST, #sent to cast server
BASS_ENCODE_COUNT_QUEUE, #queued
BASS_ENCODE_COUNT_QUEUE_LIMIT, #queue limit
BASS_ENCODE_COUNT_QUEUE_FAIL, #failed to queue
) = range(6)
#BASS_Encode_CastInit content MIME types
BASS_ENCODE_TYPE_MP3 = "audio/mpeg"
BASS_ENCODE_TYPE_OGG = "application/ogg"
BASS_ENCODE_TYPE_AAC = "audio/aacp"
#BASS_Encode_CastGetStats types
BASS_ENCODE_STATS_SHOUT = 0 #Shoutcast stats
BASS_ENCODE_STATS_ICE = 1 #Icecast mount-point stats
BASS_ENCODE_STATS_ICESERV = 2 #Icecast server stats
#typedef void (CALLBACK ENCODEPROC)(HENCODE handle, DWORD channel, const void *buffer, DWORD length, void *user);
ENCODEPROC = func_type(None, HENCODE, ctypes.c_ulong, ctypes.c_void_p, ctypes.c_ulong, ctypes.c_void_p)
#typedef void (CALLBACK ENCODEPROCEX)(HENCODE handle, DWORD channel, const void *buffer, DWORD length, QWORD offset, void *user);
ENCODEPROCEX = func_type(None, HENCODE, ctypes.c_ulong, ctypes.c_void_p, ctypes.c_ulong, pybass.QWORD, ctypes.c_void_p)
#typedef BOOL (CALLBACK ENCODECLIENTPROC)(HENCODE handle, BOOL connect, const char *client, char *headers, void *user);
ENCODECLIENTPROC = func_type(ctypes.c_byte, HENCODE, ctypes.c_byte, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_void_p)
#typedef void (CALLBACK ENCODENOTIFYPROC)(HENCODE handle, DWORD status, void *user);
ENCODENOTIFYPROC = func_type(None, HENCODE, ctypes.c_ulong, ctypes.c_void_p)
#Encoder notifications
BASS_ENCODE_NOTIFY_ENCODER = 1 #encoder died
BASS_ENCODE_NOTIFY_CAST = 2 #cast server connection died
BASS_ENCODE_NOTIFY_CAST_TIMEOUT = 0x10000 #cast timeout
BASS_ENCODE_NOTIFY_QUEUE_FULL = 0x10001 #queue is out of space
#BASS_Encode_ServerInit flags
BASS_ENCODE_SERVER_NOHTTP = 1 #no HTTP headers
#DWORD BASSENCDEF(BASS_Encode_GetVersion)();
BASS_Encode_GetVersion = func_type(ctypes.c_ulong)(('BASS_Encode_GetVersion', bassenc_module))
#HENCODE BASSENCDEF(BASS_Encode_Start)(DWORD handle, const char *cmdline, DWORD flags, ENCODEPROC *proc, void *user);
BASS_Encode_Start = func_type(HENCODE, ctypes.c_ulong, ctypes.c_char_p, ctypes.c_ulong, ENCODEPROC, ctypes.c_void_p)(('BASS_Encode_Start', bassenc_module))
#HENCODE BASSENCDEF(BASS_Encode_StartLimit)(DWORD handle, const char *cmdline, DWORD flags, ENCODEPROC *proc, void *user, DWORD limit);
BASS_Encode_StartLimit = func_type(HENCODE, ctypes.c_ulong, ctypes.c_void_p, ctypes.c_ulong, ENCODEPROC, ctypes.c_void_p, ctypes.c_ulong)(('BASS_Encode_StartLimit', bassenc_module))
#BOOL BASSENCDEF(BASS_Encode_AddChunk)(HENCODE handle, const char *id, const void *buffer, DWORD length);
BASS_Encode_AddChunk = func_type(ctypes.c_byte, HENCODE, ctypes.c_char_p, ctypes.c_void_p, ctypes.c_ulong)(('BASS_Encode_AddChunk', bassenc_module))
#DWORD BASSENCDEF(BASS_Encode_IsActive)(DWORD handle);
BASS_Encode_IsActive = func_type(ctypes.c_ulong, ctypes.c_ulong)(('BASS_Encode_IsActive', bassenc_module))
#BOOL BASSENCDEF(BASS_Encode_Stop)(DWORD handle);
BASS_Encode_Stop = func_type(ctypes.c_byte, ctypes.c_ulong)(('BASS_Encode_Stop', bassenc_module))
#BOOL BASSENCDEF(BASS_Encode_StopEx)(DWORD handle, BOOL queue);
BASS_Encode_StopEx = func_type(ctypes.c_byte, ctypes.c_ulong, ctypes.c_byte)
#BOOL BASSENCDEF(BASS_Encode_SetPaused)(DWORD handle, BOOL paused);
BASS_Encode_SetPaused = func_type(ctypes.c_byte, ctypes.c_ulong, ctypes.c_byte)(('BASS_Encode_SetPaused', bassenc_module))
#BOOL BASSENCDEF(BASS_Encode_Write)(DWORD handle, const void *buffer, DWORD length);
BASS_Encode_Write = func_type(ctypes.c_byte, ctypes.c_ulong, ctypes.c_void_p, ctypes.c_ulong)(('BASS_Encode_Write', bassenc_module))
#BOOL BASSENCDEF(BASS_Encode_SetNotify)(DWORD handle, ENCODENOTIFYPROC *proc, void *user);
BASS_Encode_SetNotify = func_type(ctypes.c_byte, ctypes.c_ulong, ENCODENOTIFYPROC, ctypes.c_void_p)(('BASS_Encode_SetNotify', bassenc_module))
#QWORD BASSENCDEF(BASS_Encode_GetCount)(DWORD handle, DWORD count);
BASS_Encode_GetCount = func_type(pybass.QWORD, ctypes.c_ulong, ctypes.c_ulong)(('BASS_Encode_GetCount', bassenc_module))
#BOOL BASSENCDEF(BASS_Encode_SetChannel)(DWORD handle, DWORD channel);
BASS_Encode_SetChannel = func_type(ctypes.c_byte, ctypes.c_ulong, ctypes.c_ulong)
#DWORD BASSENCDEF(BASS_Encode_GetChannel)(HENCODE handle);
BASS_Encode_GetChannel = func_type(ctypes.c_ulong, HENCODE)(('BASS_Encode_GetChannel', bassenc_module))
if platform.system() == 'Windows':
#DWORD BASSENCDEF(BASS_Encode_GetACMFormat)(DWORD handle, void *form, DWORD formlen, const char *title, DWORD flags);
BASS_Encode_GetACMFormat = func_type(ctypes.c_ulong, ctypes.c_ulong, ctypes.c_void_p, ctypes.c_ulong, ctypes.c_char_p, ctypes.c_ulong)(('BASS_Encode_GetACMFormat', bassenc_module))
#HENCODE BASSENCDEF(BASS_Encode_StartACM)(DWORD handle, const void *form, DWORD flags, ENCODEPROC *proc, void *user);
BASS_Encode_StartACM = func_type(HENCODE, ctypes.c_ulong, ctypes.c_void_p, ctypes.c_ulong, ENCODEPROC, ctypes.c_void_p)(('BASS_Encode_StartACM', bassenc_module))
#HENCODE BASSENCDEF(BASS_Encode_StartACMFile)(DWORD handle, const void *form, DWORD flags, const char *file);
BASS_Encode_StartACMFile = func_type(HENCODE, ctypes.c_ulong, ctypes.c_void_p, ctypes.c_ulong, ctypes.c_char_p)(('BASS_Encode_StartACMFile', bassenc_module))
if platform.system() == 'Darwin':
#HENCODE BASSENCDEF(BASS_Encode_StartCA)(DWORD handle, DWORD ftype, DWORD atype, DWORD flags, DWORD bitrate, ENCODEPROCEX *proc, void *user);
BASS_Encode_StartCA = func_type(HENCODE, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong, ENCODEPROCEX, ctypes.c_void_p)(('ENCODEPROCEX ', bassenc_module))
#HENCODE BASSENCDEF(BASS_Encode_StartCAFile)(DWORD handle, DWORD ftype, DWORD atype, DWORD flags, DWORD bitrate, const char *file);
BASS_Encode_StartCAFile = func_type(HENCODE, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_char_p)(('BASS_Encode_StartCAFile', bassenc_module))
#Broadcasting
#BOOL BASSENCDEF(BASS_Encode_CastInit)(HENCODE handle, const char *server, const char *pass, const char *content, const char *name, const char *url, const char *genre, const char *desc, const char *headers, DWORD bitrate, BOOL pub);
BASS_Encode_CastInit = func_type(ctypes.c_byte, HENCODE, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_ulong, ctypes.c_byte)(('BASS_Encode_CastInit', bassenc_module))
#BOOL BASSENCDEF(BASS_Encode_CastSetTitle)(HENCODE handle, const char *title, const char *url);
BASS_Encode_CastSetTitle = func_type(ctypes.c_byte, HENCODE, ctypes.c_char_p, ctypes.c_char_p)(('BASS_Encode_CastSetTitle', bassenc_module))
#const char *BASSENCDEF(BASS_Encode_CastGetStats)(HENCODE handle, DWORD type, const char *pass);
BASS_Encode_CastGetStats = func_type(ctypes.c_char_p, HENCODE, ctypes.c_ulong, ctypes.c_char_p)(('BASS_Encode_CastGetStats', bassenc_module))
#Local audio server
#DWORD BASSENCDEF(BASS_Encode_ServerInit)(HENCODE handle, const char *port, DWORD buffer, DWORD burst, DWORD flags, ENCODECLIENTPROC *proc, void *user);
BASS_Encode_ServerInit = func_type(ctypes.c_ulong, HENCODE, ctypes.c_char_p, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong, ENCODECLIENTPROC, ctypes.c_void_p)(('BASS_Encode_ServerInit', bassenc_module))
#BOOL BASSENCDEF(BASS_Encode_ServerKick)(HENCODE handle, const char *client);
BASS_Encode_ServerKick = func_type(ctypes.c_byte, HENCODE, ctypes.c_char_p)(('BASS_Encode_ServerKick', bassenc_module))

View File

@@ -1,41 +0,0 @@
from __future__ import absolute_import
# Copyright(c) Max Kolosov 2009 maxkolosov@inbox.ru
# http://vosolok2008.narod.ru
# BSD license
__version__ = '0.1'
__versionTime__ = '2009-11-15'
__author__ = 'Max Kolosov <maxkolosov@inbox.ru>'
__doc__ = '''
pybassflac.py - is ctypes python module for
BASSFLAC - extension to the BASS audio library,
enabling the playing of FLAC (Free Lossless Audio Codec) encoded files.
'''
import os, sys, ctypes
from . import pybass
from .paths import x86_path, x64_path
import libloader
bassflac_module = libloader.load_library('bassflac', x86_path=x86_path, x64_path=x64_path)
func_type = libloader.get_functype()
#Register the plugin with the Bass plugin system.
pybass.BASS_PluginLoad(libloader.find_library_path('bassflac', x86_path=x86_path, x64_path=x64_path), 0)
QWORD = pybass.QWORD
HSTREAM = pybass.HSTREAM
DOWNLOADPROC = pybass.DOWNLOADPROC
BASS_FILEPROCS = pybass.BASS_FILEPROCS
# BASS_CHANNELINFO type
BASS_CTYPE_STREAM_FLAC = 0x10900
BASS_CTYPE_STREAM_FLAC_OGG = 0x10901
#HSTREAM BASSFLACDEF(BASS_FLAC_StreamCreateFile)(BOOL mem, const void *file, QWORD offset, QWORD length, DWORD flags);
BASS_FLAC_StreamCreateFile = func_type(HSTREAM, ctypes.c_byte, ctypes.c_void_p, QWORD, QWORD, ctypes.c_ulong)(('BASS_FLAC_StreamCreateFile', bassflac_module))
#HSTREAM BASSFLACDEF(BASS_FLAC_StreamCreateURL)(const char *url, DWORD offset, DWORD flags, DOWNLOADPROC *proc, void *user);
BASS_FLAC_StreamCreateURL = func_type(HSTREAM, ctypes.c_char_p, ctypes.c_ulong, ctypes.c_ulong, DOWNLOADPROC, ctypes.c_void_p)(('BASS_FLAC_StreamCreateURL', bassflac_module))
#HSTREAM BASSFLACDEF(BASS_FLAC_StreamCreateFileUser)(DWORD system, DWORD flags, const BASS_FILEPROCS *procs, void *user);
BASS_FLAC_StreamCreateFileUser = func_type(HSTREAM, ctypes.c_ulong, ctypes.c_ulong, ctypes.POINTER(BASS_FILEPROCS), ctypes.c_void_p)(('BASS_FLAC_StreamCreateFileUser', bassflac_module))

View File

@@ -1,204 +0,0 @@
from __future__ import absolute_import
# Copyright(c) Max Kolosov 2009 maxkolosov@inbox.ru
# http://vosolok2008.narod.ru
# BSD license
__version__ = '0.1'
__versionTime__ = '2009-11-15'
__author__ = 'Max Kolosov <maxkolosov@inbox.ru>'
__doc__ = '''
pybassmidi.py - is ctypes python module for
BASSMIDI - extension to the BASS audio library,
enabling the playing of MIDI files and real-time events,
using SF2 soundfonts to provide the sounds.
'''
import sys, ctypes, platform, os
from . import pybass
from .paths import x86_path, x64_path
import libloader
bassmidi_module = libloader.load_library('bassmidi', x86_path=x86_path, x64_path=x64_path)
func_type = libloader.get_functype()
#Register the plugin with the Bass plugin system.
pybass.BASS_PluginLoad(libloader.find_library_path('bassmidi', x86_path=x86_path, x64_path=x64_path), 0)
HSOUNDFONT = ctypes.c_ulong
QWORD = pybass.QWORD
HSTREAM = pybass.HSTREAM
DOWNLOADPROC = pybass.DOWNLOADPROC
BASS_FILEPROCS = pybass.BASS_FILEPROCS
# Additional BASS_SetConfig options
BASS_CONFIG_MIDI_COMPACT = 0x10400
BASS_CONFIG_MIDI_VOICES = 0x10401
BASS_CONFIG_MIDI_AUTOFONT = 0x10402
# Additional BASS_SetConfigPtr options
BASS_CONFIG_MIDI_DEFFONT = 0x10403
# Additional sync types
BASS_SYNC_MIDI_MARKER = 0x10000
BASS_SYNC_MIDI_CUE = 0x10001
BASS_SYNC_MIDI_LYRIC = 0x10002
BASS_SYNC_MIDI_TEXT = 0x10003
BASS_SYNC_MIDI_EVENT = 0x10004
BASS_SYNC_MIDI_TICK = 0x10005
BASS_SYNC_MIDI_TIMESIG = 0x10006
# Additional BASS_MIDI_StreamCreateFile/etc flags
BASS_MIDI_DECAYEND = 0x1000
BASS_MIDI_NOFX = 0x2000
BASS_MIDI_DECAYSEEK = 0x4000
class BASS_MIDI_FONT(ctypes.Structure):
_fields_ = [('font', HSOUNDFONT),#HSOUNDFONT font; // soundfont
('preset', ctypes.c_int),#int preset; // preset number (-1=all)
('bank', ctypes.c_int)#int bank;
]
class BASS_MIDI_FONTINFO(ctypes.Structure):
_fields_ = [('name', ctypes.c_char_p),#const char *name;
('copyright', ctypes.c_char_p),#const char *copyright;
('comment', ctypes.c_char_p),#const char *comment;
('presets', ctypes.c_ulong),#DWORD presets; // number of presets/instruments
('samsize', ctypes.c_ulong),#DWORD samsize; // total size (in bytes) of the sample data
('samload', ctypes.c_ulong),#DWORD samload; // amount of sample data currently loaded
('samtype', ctypes.c_ulong)#DWORD samtype; // sample format (CTYPE) if packed
]
class BASS_MIDI_MARK(ctypes.Structure):
_fields_ = [('track', ctypes.c_ulong),#DWORD track; // track containing marker
('pos', ctypes.c_ulong),#DWORD pos; // marker position (bytes)
('text', ctypes.c_char_p)#const char *text; // marker text
]
# Marker types
BASS_MIDI_MARK_MARKER = 0 # marker events
BASS_MIDI_MARK_CUE = 1 # cue events
BASS_MIDI_MARK_LYRIC = 2 # lyric events
BASS_MIDI_MARK_TEXT = 3 # text events
BASS_MIDI_MARK_TIMESIG = 4 # time signature
# MIDI events
MIDI_EVENT_NOTE = 1
MIDI_EVENT_PROGRAM = 2
MIDI_EVENT_CHANPRES = 3
MIDI_EVENT_PITCH = 4
MIDI_EVENT_PITCHRANGE = 5
MIDI_EVENT_DRUMS = 6
MIDI_EVENT_FINETUNE = 7
MIDI_EVENT_COARSETUNE = 8
MIDI_EVENT_MASTERVOL = 9
MIDI_EVENT_BANK = 10
MIDI_EVENT_MODULATION = 11
MIDI_EVENT_VOLUME = 12
MIDI_EVENT_PAN = 13
MIDI_EVENT_EXPRESSION = 14
MIDI_EVENT_SUSTAIN = 15
MIDI_EVENT_SOUNDOFF = 16
MIDI_EVENT_RESET = 17
MIDI_EVENT_NOTESOFF = 18
MIDI_EVENT_PORTAMENTO = 19
MIDI_EVENT_PORTATIME = 20
MIDI_EVENT_PORTANOTE = 21
MIDI_EVENT_MODE = 22
MIDI_EVENT_REVERB = 23
MIDI_EVENT_CHORUS = 24
MIDI_EVENT_CUTOFF = 25
MIDI_EVENT_RESONANCE = 26
MIDI_EVENT_RELEASE = 27
MIDI_EVENT_ATTACK = 28
MIDI_EVENT_REVERB_MACRO = 30
MIDI_EVENT_CHORUS_MACRO = 31
MIDI_EVENT_REVERB_TIME = 32
MIDI_EVENT_REVERB_DELAY = 33
MIDI_EVENT_REVERB_LOCUTOFF = 34
MIDI_EVENT_REVERB_HICUTOFF = 35
MIDI_EVENT_REVERB_LEVEL = 36
MIDI_EVENT_CHORUS_DELAY = 37
MIDI_EVENT_CHORUS_DEPTH = 38
MIDI_EVENT_CHORUS_RATE = 39
MIDI_EVENT_CHORUS_FEEDBACK = 40
MIDI_EVENT_CHORUS_LEVEL = 41
MIDI_EVENT_CHORUS_REVERB = 42
MIDI_EVENT_DRUM_FINETUNE = 50
MIDI_EVENT_DRUM_COARSETUNE = 51
MIDI_EVENT_DRUM_PAN = 52
MIDI_EVENT_DRUM_REVERB = 53
MIDI_EVENT_DRUM_CHORUS = 54
MIDI_EVENT_DRUM_CUTOFF = 55
MIDI_EVENT_DRUM_RESONANCE = 56
MIDI_EVENT_DRUM_LEVEL = 57
MIDI_EVENT_TEMPO = 62
MIDI_EVENT_MIXLEVEL = 0x10000
MIDI_EVENT_TRANSPOSE = 0x10001
class BASS_MIDI_EVENT(ctypes.Structure):
_fields_ = [('event', ctypes.c_ulong),#DWORD event; // MIDI_EVENT_xxx
('param', ctypes.c_ulong),#DWORD param;
('chan', ctypes.c_ulong),#DWORD chan;
('tick', ctypes.c_ulong),#DWORD tick; // event position (ticks)
('pos', ctypes.c_ulong)#DWORD pos; // event position (bytes)
]
# BASS_CHANNELINFO type
BASS_CTYPE_STREAM_MIDI = 0x10d00
# Additional attributes
BASS_ATTRIB_MIDI_PPQN = 0x12000
BASS_ATTRIB_MIDI_TRACK_VOL = 0x12100 # + track #
# Additional tag type
BASS_TAG_MIDI_TRACK = 0x11000 # + track #, track text : array of null-terminated ANSI strings
# BASS_ChannelGetLength/GetPosition/SetPosition mode
BASS_POS_MIDI_TICK = 2 # tick position
#HSTREAM BASSMIDIDEF(BASS_MIDI_StreamCreate)(DWORD channels, DWORD flags, DWORD freq);
BASS_MIDI_StreamCreate = func_type(HSTREAM, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong)(('BASS_MIDI_StreamCreate', bassmidi_module))
#HSTREAM BASSMIDIDEF(BASS_MIDI_StreamCreateFile)(BOOL mem, const void *file, QWORD offset, QWORD length, DWORD flags, DWORD freq);
BASS_MIDI_StreamCreateFile = func_type(HSTREAM, ctypes.c_byte, ctypes.c_void_p, QWORD, QWORD, ctypes.c_ulong, ctypes.c_ulong)(('BASS_MIDI_StreamCreateFile', bassmidi_module))
#HSTREAM BASSMIDIDEF(BASS_MIDI_StreamCreateURL)(const char *url, DWORD offset, DWORD flags, DOWNLOADPROC *proc, void *user, DWORD freq);
BASS_MIDI_StreamCreateURL = func_type(HSTREAM, ctypes.c_char_p, ctypes.c_ulong, ctypes.c_ulong, DOWNLOADPROC, ctypes.c_void_p, ctypes.c_ulong)(('BASS_MIDI_StreamCreateURL', bassmidi_module))
#HSTREAM BASSMIDIDEF(BASS_MIDI_StreamCreateFileUser)(DWORD system, DWORD flags, const BASS_FILEPROCS *procs, void *user, DWORD freq);
BASS_MIDI_StreamCreateFileUser = func_type(HSTREAM, ctypes.c_ulong, ctypes.c_ulong, ctypes.POINTER(BASS_FILEPROCS), ctypes.c_void_p, ctypes.c_ulong)(('BASS_MIDI_StreamCreateFileUser', bassmidi_module))
#BOOL BASSMIDIDEF(BASS_MIDI_StreamGetMark)(HSTREAM handle, DWORD type, DWORD index, BASS_MIDI_MARK *mark);
BASS_MIDI_StreamGetMark = func_type(ctypes.c_byte, HSTREAM, ctypes.c_ulong, ctypes.c_ulong, ctypes.POINTER(BASS_MIDI_MARK))(('BASS_MIDI_StreamGetMark', bassmidi_module))
#BOOL BASSMIDIDEF(BASS_MIDI_StreamSetFonts)(HSTREAM handle, const BASS_MIDI_FONT *fonts, DWORD count);
BASS_MIDI_StreamSetFonts = func_type(ctypes.c_byte, HSTREAM, ctypes.POINTER(BASS_MIDI_FONT), ctypes.c_ulong)(('BASS_MIDI_StreamSetFonts', bassmidi_module))
#DWORD BASSMIDIDEF(BASS_MIDI_StreamGetFonts)(HSTREAM handle, BASS_MIDI_FONT *fonts, DWORD count);
BASS_MIDI_StreamGetFonts = func_type(ctypes.c_ulong, HSTREAM, ctypes.POINTER(BASS_MIDI_FONT), ctypes.c_ulong)(('BASS_MIDI_StreamGetFonts', bassmidi_module))
#BOOL BASSMIDIDEF(BASS_MIDI_StreamLoadSamples)(HSTREAM handle);
BASS_MIDI_StreamLoadSamples = func_type(ctypes.c_byte, HSTREAM)(('BASS_MIDI_StreamLoadSamples', bassmidi_module))
#BOOL BASSMIDIDEF(BASS_MIDI_StreamEvent)(HSTREAM handle, DWORD chan, DWORD event, DWORD param);
BASS_MIDI_StreamEvent = func_type(ctypes.c_byte, HSTREAM, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong)(('BASS_MIDI_StreamEvent', bassmidi_module))
#DWORD BASSMIDIDEF(BASS_MIDI_StreamGetEvent)(HSTREAM handle, DWORD chan, DWORD event);
BASS_MIDI_StreamGetEvent = func_type(ctypes.c_ulong, HSTREAM, ctypes.c_ulong, ctypes.c_ulong)(('BASS_MIDI_StreamGetEvent', bassmidi_module))
#DWORD BASSMIDIDEF(BASS_MIDI_StreamGetEvents)(HSTREAM handle, DWORD track, DWORD filter, BASS_MIDI_EVENT *events);
BASS_MIDI_StreamGetEvents = func_type(ctypes.c_ulong, HSTREAM, ctypes.c_ulong, ctypes.c_ulong, ctypes.POINTER(BASS_MIDI_EVENT))(('BASS_MIDI_StreamGetEvents', bassmidi_module))
#HSTREAM BASSMIDIDEF(BASS_MIDI_StreamGetChannel)(HSTREAM handle, DWORD chan);
BASS_MIDI_StreamGetChannel = func_type(HSTREAM, HSTREAM, ctypes.c_ulong)(('BASS_MIDI_StreamGetChannel', bassmidi_module))
#HSOUNDFONT BASSMIDIDEF(BASS_MIDI_FontInit)(const void *file, DWORD flags);
BASS_MIDI_FontInit = func_type(HSOUNDFONT, ctypes.c_void_p, ctypes.c_ulong)(('BASS_MIDI_FontInit', bassmidi_module))
#BOOL BASSMIDIDEF(BASS_MIDI_FontFree)(HSOUNDFONT handle);
BASS_MIDI_FontFree = func_type(ctypes.c_byte, HSOUNDFONT)(('BASS_MIDI_FontFree', bassmidi_module))
#BOOL BASSMIDIDEF(BASS_MIDI_FontGetInfo)(HSOUNDFONT handle, BASS_MIDI_FONTINFO *info);
BASS_MIDI_FontGetInfo = func_type(ctypes.c_byte, HSOUNDFONT, ctypes.POINTER(BASS_MIDI_FONTINFO))(('BASS_MIDI_FontGetInfo', bassmidi_module))
#const char *BASSMIDIDEF(BASS_MIDI_FontGetPreset)(HSOUNDFONT handle, int preset, int bank);
BASS_MIDI_FontGetPreset = func_type(ctypes.c_char_p, HSOUNDFONT, ctypes.c_int, ctypes.c_int)(('BASS_MIDI_FontGetPreset', bassmidi_module))
#BOOL BASSMIDIDEF(BASS_MIDI_FontLoad)(HSOUNDFONT handle, int preset, int bank);
BASS_MIDI_FontLoad = func_type(ctypes.c_byte, HSOUNDFONT, ctypes.c_int, ctypes.c_int)(('BASS_MIDI_FontLoad', bassmidi_module))
#BOOL BASSMIDIDEF(BASS_MIDI_FontCompact)(HSOUNDFONT handle);
BASS_MIDI_FontCompact = func_type(ctypes.c_byte, HSOUNDFONT)(('BASS_MIDI_FontCompact', bassmidi_module))
#BOOL BASSMIDIDEF(BASS_MIDI_FontPack)(HSOUNDFONT handle, const void *outfile, const void *encoder, DWORD flags);
BASS_MIDI_FontPack = func_type(ctypes.c_byte, HSOUNDFONT, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_ulong)(('BASS_MIDI_FontPack', bassmidi_module))
#BOOL BASSMIDIDEF(BASS_MIDI_FontUnpack)(HSOUNDFONT handle, const void *outfile, DWORD flags);
BASS_MIDI_FontUnpack = func_type(ctypes.c_byte, HSOUNDFONT, ctypes.c_void_p, ctypes.c_ulong)(('BASS_MIDI_FontUnpack', bassmidi_module))
#BOOL BASSMIDIDEF(BASS_MIDI_FontSetVolume)(HSOUNDFONT handle, float volume);
BASS_MIDI_FontSetVolume = func_type(ctypes.c_byte, HSOUNDFONT, ctypes.c_float)(('BASS_MIDI_FontSetVolume', bassmidi_module))
#float BASSMIDIDEF(BASS_MIDI_FontGetVolume)(HSOUNDFONT handle);
BASS_MIDI_FontGetVolume = func_type(ctypes.c_float, HSOUNDFONT)(('BASS_MIDI_FontGetVolume', bassmidi_module))

View File

@@ -1,117 +0,0 @@
from __future__ import absolute_import
# Copyright(c) Max Kolosov 2009 maxkolosov@inbox.ru
# http://vosolok2008.narod.ru
# BSD license
__version__ = '0.1'
__versionTime__ = '2009-11-15'
__author__ = 'Max Kolosov <maxkolosov@inbox.ru>'
__doc__ = '''
pybassmix.py - is ctypes python module for
BASSmix - extension to the BASS audio library, providing the ability
to mix together multiple BASS channels, with resampling and matrix mixing
features. It also provides the ability to go the other way and split a
BASS channel into multiple channels.
'''
import os, sys, ctypes, platform
from . import pybass
QWORD = pybass.QWORD
HSYNC = pybass.HSYNC
HSTREAM = pybass.HSTREAM
DOWNLOADPROC = pybass.DOWNLOADPROC
SYNCPROC = pybass.SYNCPROC
BASS_FILEPROCS = pybass.BASS_FILEPROCS
from .paths import x86_path, x64_path
import libloader
bassmix_module = libloader.load_library('bassmix', x86_path=x86_path, x64_path=x64_path)
func_type = libloader.get_functype()
# additional BASS_SetConfig option
BASS_CONFIG_MIXER_FILTER = 0x10600
BASS_CONFIG_MIXER_BUFFER = 0x10601
BASS_CONFIG_SPLIT_BUFFER = 0x10610
# BASS_Mixer_StreamCreate flags
BASS_MIXER_END = 0x10000# end the stream when there are no sources
BASS_MIXER_NONSTOP = 0x20000# don't stall when there are no sources
BASS_MIXER_RESUME = 0x1000# resume stalled immediately upon new/unpaused source
# source flags
BASS_MIXER_FILTER = 0x1000# resampling filter
BASS_MIXER_BUFFER = 0x2000# buffer data for BASS_Mixer_ChannelGetData/Level
BASS_MIXER_LIMIT = 0x4000# limit mixer processing to the amount available from this source
BASS_MIXER_MATRIX = 0x10000# matrix mixing
BASS_MIXER_PAUSE = 0x20000# don't process the source
BASS_MIXER_DOWNMIX = 0x400000# downmix to stereo/mono
BASS_MIXER_NORAMPIN = 0x800000# don't ramp-in the start
# envelope node
class BASS_MIXER_NODE(ctypes.Structure):
_fields_ = [('pos', ctypes.c_ulong),#QWORD pos;
('value', ctypes.c_float)#float value;
]
# envelope types
BASS_MIXER_ENV_FREQ = 1
BASS_MIXER_ENV_VOL = 2
BASS_MIXER_ENV_PAN = 3
BASS_MIXER_ENV_LOOP = 0x10000# FLAG: loop
# additional sync type
BASS_SYNC_MIXER_ENVELOPE = 0x10200
# BASS_CHANNELINFO type
BASS_CTYPE_STREAM_MIXER = 0x10800
BASS_CTYPE_STREAM_SPLIT = 0x10801
#DWORD BASSMIXDEF(BASS_Mixer_GetVersion)();
BASS_Mixer_GetVersion = func_type(ctypes.c_ulong)(('BASS_Mixer_GetVersion', bassmix_module))
#HSTREAM BASSMIXDEF(BASS_Mixer_StreamCreate)(DWORD freq, DWORD chans, DWORD flags);
BASS_Mixer_StreamCreate = func_type(HSTREAM, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong)(('BASS_Mixer_StreamCreate', bassmix_module))
#BOOL BASSMIXDEF(BASS_Mixer_StreamAddChannel)(HSTREAM handle, DWORD channel, DWORD flags);
BASS_Mixer_StreamAddChannel = func_type(ctypes.c_byte, HSTREAM, ctypes.c_ulong, ctypes.c_ulong)(('BASS_Mixer_StreamAddChannel', bassmix_module))
#BOOL BASSMIXDEF(BASS_Mixer_StreamAddChannelEx)(HSTREAM handle, DWORD channel, DWORD flags, QWORD start, QWORD length);
BASS_Mixer_StreamAddChannelEx = func_type(ctypes.c_byte, HSTREAM, ctypes.c_ulong, ctypes.c_ulong, QWORD, QWORD)(('BASS_Mixer_StreamAddChannelEx', bassmix_module))
#HSTREAM BASSMIXDEF(BASS_Mixer_ChannelGetMixer)(DWORD handle);
BASS_Mixer_ChannelGetMixer = func_type(HSTREAM, ctypes.c_ulong)(('BASS_Mixer_ChannelGetMixer', bassmix_module))
#DWORD BASSMIXDEF(BASS_Mixer_ChannelFlags)(DWORD handle, DWORD flags, DWORD mask);
BASS_Mixer_ChannelFlags = func_type(ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong)(('BASS_Mixer_ChannelFlags', bassmix_module))
#BOOL BASSMIXDEF(BASS_Mixer_ChannelRemove)(DWORD handle);
BASS_Mixer_ChannelRemove = func_type(ctypes.c_byte, ctypes.c_ulong)(('BASS_Mixer_ChannelRemove', bassmix_module))
#BOOL BASSMIXDEF(BASS_Mixer_ChannelSetPosition)(DWORD handle, QWORD pos, DWORD mode);
BASS_Mixer_ChannelSetPosition = func_type(ctypes.c_byte, ctypes.c_ulong, QWORD, ctypes.c_ulong)(('BASS_Mixer_ChannelSetPosition', bassmix_module))
#QWORD BASSMIXDEF(BASS_Mixer_ChannelGetPosition)(DWORD handle, DWORD mode);
BASS_Mixer_ChannelGetPosition = func_type(QWORD, ctypes.c_ulong, ctypes.c_ulong)(('BASS_Mixer_ChannelGetPosition', bassmix_module))
#DWORD BASSMIXDEF(BASS_Mixer_ChannelGetLevel)(DWORD handle);
BASS_Mixer_ChannelGetLevel = func_type(ctypes.c_ulong, ctypes.c_ulong)(('BASS_Mixer_ChannelGetLevel', bassmix_module))
#DWORD BASSMIXDEF(BASS_Mixer_ChannelGetData)(DWORD handle, void *buffer, DWORD length);
BASS_Mixer_ChannelGetData = func_type(ctypes.c_ulong, ctypes.c_ulong, ctypes.c_void_p, ctypes.c_ulong)(('BASS_Mixer_ChannelGetData', bassmix_module))
#HSYNC BASSMIXDEF(BASS_Mixer_ChannelSetSync)(DWORD handle, DWORD type, QWORD param, SYNCPROC *proc, void *user);
BASS_Mixer_ChannelSetSync = func_type(HSYNC, ctypes.c_ulong, ctypes.c_ulong, QWORD, SYNCPROC, ctypes.c_void_p)(('BASS_Mixer_ChannelSetSync', bassmix_module))
#BOOL BASSMIXDEF(BASS_Mixer_ChannelRemoveSync)(DWORD channel, HSYNC sync);
BASS_Mixer_ChannelRemoveSync = func_type(ctypes.c_byte, ctypes.c_ulong, HSYNC)(('BASS_Mixer_ChannelRemoveSync', bassmix_module))
#BOOL BASSMIXDEF(BASS_Mixer_ChannelSetMatrix)(DWORD handle, const float *matrix);
BASS_Mixer_ChannelSetMatrix = func_type(ctypes.c_byte, ctypes.c_ulong, ctypes.POINTER(ctypes.c_float))(('BASS_Mixer_ChannelSetMatrix', bassmix_module))
#BOOL BASSMIXDEF(BASS_Mixer_ChannelGetMatrix)(DWORD handle, float *matrix);
BASS_Mixer_ChannelGetMatrix = func_type(ctypes.c_byte, ctypes.c_ulong, ctypes.POINTER(ctypes.c_float))(('BASS_Mixer_ChannelGetMatrix', bassmix_module))
#BOOL BASSMIXDEF(BASS_Mixer_ChannelSetEnvelope)(DWORD handle, DWORD type, const BASS_MIXER_NODE *nodes, DWORD count);
BASS_Mixer_ChannelSetEnvelope = func_type(ctypes.c_byte, ctypes.c_ulong, ctypes.c_ulong, ctypes.POINTER(BASS_MIXER_NODE), ctypes.c_ulong)(('BASS_Mixer_ChannelSetEnvelope', bassmix_module))
#BOOL BASSMIXDEF(BASS_Mixer_ChannelSetEnvelopePos)(DWORD handle, DWORD type, QWORD pos);
BASS_Mixer_ChannelSetEnvelopePos = func_type(ctypes.c_byte, ctypes.c_ulong, ctypes.c_ulong, QWORD)(('BASS_Mixer_ChannelSetEnvelopePos', bassmix_module))
#QWORD BASSMIXDEF(BASS_Mixer_ChannelGetEnvelopePos)(DWORD handle, DWORD type, float *value);
BASS_Mixer_ChannelGetEnvelopePos = func_type(QWORD, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_float)(('BASS_Mixer_ChannelGetEnvelopePos', bassmix_module))
#HSTREAM BASSMIXDEF(BASS_Split_StreamCreate)(DWORD channel, DWORD flags, int *chanmap);
BASS_Split_StreamCreate = func_type(HSTREAM, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_int)(('BASS_Split_StreamCreate', bassmix_module))
#DWORD BASSMIXDEF(BASS_Split_StreamGetSource)(HSTREAM handle);
BASS_Split_StreamGetSource = func_type(ctypes.c_ulong, HSTREAM)(('BASS_Split_StreamGetSource', bassmix_module))
#BOOL BASSMIXDEF(BASS_Split_StreamReset)(DWORD handle);
BASS_Split_StreamReset = func_type(ctypes.c_byte, ctypes.c_ulong)(('BASS_Split_StreamReset', bassmix_module))

View File

@@ -1,47 +0,0 @@
# Copyright(c) Max Kolosov 2009 maxkolosov@inbox.ru
# http://vosolok2008.narod.ru
# BSD license
__version__ = '0.1'
__versionTime__ = '2009-11-15'
__author__ = 'Max Kolosov <maxkolosov@inbox.ru>'
__doc__ = '''
pybassflac.py - is ctypes python module for
BASSFLAC - extension to the BASS audio library,
enabling the playing of FLAC (Free Lossless Audio Codec) encoded files.
'''
import os, sys, ctypes, pybass
from paths import x86_path, x64_path
import libloader
bassopus_module = libloader.load_library('bassopus', x86_path=x86_path, x64_path=x64_path)
func_type = libloader.get_functype()
#Register the plugin with the Bass plugin system.
pybass.BASS_PluginLoad(libloader.find_library_path('bassopus', x86_path=x86_path, x64_path=x64_path), 0)
QWORD = pybass.QWORD
HSTREAM = pybass.HSTREAM
DOWNLOADPROC = pybass.DOWNLOADPROC
BASS_FILEPROCS = pybass.BASS_FILEPROCS
# BASS_CHANNELINFO type
BASS_CTYPE_STREAM_OPUS = 0x11200
#HSTREAM BASSOPUSDEF(BASS_OPUS_StreamCreateFile)(BOOL mem, const void *file, QWORD offset, QWORD length, DWORD flags);
BASS_OPUS_StreamCreateFile = func_type(HSTREAM, ctypes.c_byte, ctypes.c_void_p, QWORD, QWORD, ctypes.c_ulong)(('BASS_OPUS_StreamCreateFile', bassopus_module))
#HSTREAM BASSFLACDEF(BASS_FLAC_StreamCreateURL)(const char *url, DWORD offset, DWORD flags, DOWNLOADPROC *proc, void *user);
BASS_OPUS_StreamCreateURL = func_type(HSTREAM, ctypes.c_char_p, ctypes.c_ulong, ctypes.c_ulong, DOWNLOADPROC, ctypes.c_void_p)(('BASS_OPUS_StreamCreateURL', bassopus_module))
#HSTREAM BASSFLACDEF(BASS_FLAC_StreamCreateFileUser)(DWORD system, DWORD flags, const BASS_FILEPROCS *procs, void *user);
BASS_OPUS_StreamCreateFileUser = func_type(HSTREAM, ctypes.c_ulong, ctypes.c_ulong, ctypes.POINTER(BASS_FILEPROCS), ctypes.c_void_p)(('BASS_OPUS_StreamCreateFileUser', bassopus_module))
if __name__ == "__main__":
if not pybass.BASS_Init(-1, 44100, 0, 0, 0):
print 'BASS_Init error', pybass.get_error_description(pybass.BASS_ErrorGetCode())
else:
handle = BASS_OPUS_StreamCreateFile(False, 'test.opus', 0, 0, 0)
pybass.play_handle(handle)
if not pybass.BASS_Free():
print 'BASS_Free error', pybass.get_error_description(pybass.BASS_ErrorGetCode())

View File

@@ -1,148 +0,0 @@
from __future__ import absolute_import
# Copyright(c) Max Kolosov 2009 maxkolosov@inbox.ru
# http://vosolok2008.narod.ru
# BSD license
__version__ = '0.1'
__versionTime__ = '2009-11-15'
__author__ = 'Max Kolosov <maxkolosov@inbox.ru>'
__doc__ = '''
pybasswma.py - is ctypes python module for
BASSWMA - extension to the BASS audio library,
enabling the playback of WMA files and network streams.
The audio tracks of WMV files can also be played.
WMA file encoding and network broadcasting functions are also provided.
Requirements
============
BASS 2.4 is required. The Windows Media Format modules (v9 or above) are
also required to be installed on the user's system. They are installed with
Windows Media player, so will already be on most users' systems, but they
can also be installed separately (WMFDIST.EXE is available from the BASS website).
'''
import os, sys, ctypes
from sound_lib.external import pybass
from .paths import x86_path, x64_path
import libloader
QWORD = pybass.QWORD
HSTREAM = pybass.HSTREAM
BASS_FILEPROCS = pybass.BASS_FILEPROCS
HWMENCODE = ctypes.c_ulong# WMA encoding handle
basswma_module = libloader.load_library('basswma', x86_path=x86_path, x64_path=x64_path)
func_type = libloader.get_functype()
#Register the plugin with the Bass plugin system.
pybass.BASS_PluginLoad(libloader.find_library_path('basswma', x86_path=x86_path, x64_path=x64_path), 0)
# Additional error codes returned by BASS_ErrorGetCode
BASS_ERROR_WMA_LICENSE = 1000# the file is protected
BASS_ERROR_WMA = 1001# Windows Media (9 or above) is not installed
BASS_ERROR_WMA_WM9 = BASS_ERROR_WMA
BASS_ERROR_WMA_DENIED = 1002# access denied (user/pass is invalid)
BASS_ERROR_WMA_INDIVIDUAL = 1004# individualization is needed
BASS_ERROR_WMA_PUBINIT = 1005# publishing point initialization problem
# Additional BASS_SetConfig options
BASS_CONFIG_WMA_PRECHECK = 0x10100
BASS_CONFIG_WMA_PREBUF = 0x10101
BASS_CONFIG_WMA_BASSFILE = 0x10103
BASS_CONFIG_WMA_NETSEEK = 0x10104
BASS_CONFIG_WMA_VIDEO = 0x10105
# additional WMA sync types
BASS_SYNC_WMA_CHANGE = 0x10100
BASS_SYNC_WMA_META = 0x10101
# additional BASS_StreamGetFilePosition WMA mode
BASS_FILEPOS_WMA_BUFFER = 1000# internet buffering progress (0-100%)
# Additional flags for use with BASS_WMA_EncodeOpen/File/Network/Publish
BASS_WMA_ENCODE_STANDARD = 0x2000# standard WMA
BASS_WMA_ENCODE_PRO = 0x4000# WMA Pro
BASS_WMA_ENCODE_24BIT = 0x8000# 24-bit
BASS_WMA_ENCODE_SCRIPT = 0x20000# set script (mid-stream tags) in the WMA encoding
# Additional flag for use with BASS_WMA_EncodeGetRates
BASS_WMA_ENCODE_RATES_VBR = 0x10000# get available VBR quality settings
#typedef void (CALLBACK CLIENTCONNECTPROC)(HWMENCODE handle, BOOL connect, const char *ip, void *user);
CLIENTCONNECTPROC = func_type(None, HWMENCODE, ctypes.c_byte, ctypes.c_char_p, ctypes.c_void_p)
# Client connection notification callback function.
#handle : The encoder
#connect: TRUE=client is connecting, FALSE=disconnecting
#ip : The client's IP (xxx.xxx.xxx.xxx:port)
#user : The 'user' parameter value given when calling BASS_WMA_EncodeSetNotify
#typedef void (CALLBACK WMENCODEPROC)(HWMENCODE handle, DWORD type, const void *buffer, DWORD length, void *user);
WMENCODEPROC = func_type(None, HWMENCODE, ctypes.c_ulong, ctypes.c_void_p, ctypes.c_ulong, ctypes.c_void_p)
# Encoder callback function.
#handle : The encoder handle
#type : The type of data, one of BASS_WMA_ENCODE_xxx values
#buffer : The encoded data
#length : Length of the data
#user : The 'user' parameter value given when calling BASS_WMA_EncodeOpen
# WMENCODEPROC "type" values
BASS_WMA_ENCODE_HEAD = 0
BASS_WMA_ENCODE_DATA = 1
BASS_WMA_ENCODE_DONE = 2
# BASS_WMA_EncodeSetTag "form" values
BASS_WMA_TAG_ANSI = 0
BASS_WMA_TAG_UNICODE = 1
BASS_WMA_TAG_UTF8 = 2
BASS_WMA_TAG_BINARY = 0x100# FLAG: binary tag (HIWORD=length)
# BASS_CHANNELINFO type
BASS_CTYPE_STREAM_WMA = 0x10300
BASS_CTYPE_STREAM_WMA_MP3 = 0x10301
# Additional BASS_ChannelGetTags types
BASS_TAG_WMA = 8# WMA header tags : series of null-terminated UTF-8 strings
BASS_TAG_WMA_META = 11# WMA mid-stream tag : UTF-8 string
#HSTREAM BASSWMADEF(BASS_WMA_StreamCreateFile)(BOOL mem, const void *file, QWORD offset, QWORD length, DWORD flags);
BASS_WMA_StreamCreateFile = func_type(HSTREAM, ctypes.c_byte, ctypes.c_void_p, QWORD, QWORD, ctypes.c_ulong)(('BASS_WMA_StreamCreateFile', basswma_module))
#HSTREAM BASSWMADEF(BASS_WMA_StreamCreateFileAuth)(BOOL mem, const void *file, QWORD offset, QWORD length, DWORD flags, const char *user, const char *pass);
BASS_WMA_StreamCreateFileAuth = func_type(HSTREAM, ctypes.c_byte, ctypes.c_void_p, QWORD, QWORD, ctypes.c_ulong, ctypes.c_char_p, ctypes.c_char_p)(('BASS_WMA_StreamCreateFileAuth', basswma_module))
#HSTREAM BASSWMADEF(BASS_WMA_StreamCreateFileUser)(DWORD system, DWORD flags, const BASS_FILEPROCS *procs, void *user);
BASS_WMA_StreamCreateFileUser = func_type(HSTREAM, ctypes.c_ulong, ctypes.c_ulong, ctypes.POINTER(BASS_FILEPROCS), ctypes.c_void_p)(('BASS_WMA_StreamCreateFileUser', basswma_module))
#const char *BASSWMADEF(BASS_WMA_GetTags)(const void *file, DWORD flags);
BASS_WMA_GetTags = func_type(ctypes.c_char_p, ctypes.c_void_p, ctypes.c_ulong)(('BASS_WMA_GetTags', basswma_module))
#const DWORD *BASSWMADEF(BASS_WMA_EncodeGetRates)(DWORD freq, DWORD chans, DWORD flags);
BASS_WMA_EncodeGetRates = func_type(ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong)(('BASS_WMA_EncodeGetRates', basswma_module))
#HWMENCODE BASSWMADEF(BASS_WMA_EncodeOpen)(DWORD freq, DWORD chans, DWORD flags, DWORD bitrate, WMENCODEPROC *proc, void *user);
BASS_WMA_EncodeOpen = func_type(HWMENCODE, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong, WMENCODEPROC, ctypes.c_void_p)(('BASS_WMA_EncodeOpen', basswma_module))
#HWMENCODE BASSWMADEF(BASS_WMA_EncodeOpenFile)(DWORD freq, DWORD chans, DWORD flags, DWORD bitrate, const char *file);
BASS_WMA_EncodeOpenFile = func_type(HWMENCODE, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_char_p)(('BASS_WMA_EncodeOpenFile', basswma_module))
#HWMENCODE BASSWMADEF(BASS_WMA_EncodeOpenNetwork)(DWORD freq, DWORD chans, DWORD flags, DWORD bitrate, DWORD port, DWORD clients);
BASS_WMA_EncodeOpenNetwork = func_type(HWMENCODE, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong)(('BASS_WMA_EncodeOpenNetwork', basswma_module))
#HWMENCODE BASSWMADEF(BASS_WMA_EncodeOpenNetworkMulti)(DWORD freq, DWORD chans, DWORD flags, const DWORD *bitrates, DWORD port, DWORD clients);
BASS_WMA_EncodeOpenNetworkMulti = func_type(HWMENCODE, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong, ctypes.POINTER(ctypes.c_ulong), ctypes.c_ulong, ctypes.c_ulong)(('BASS_WMA_EncodeOpenNetworkMulti', basswma_module))
#HWMENCODE BASSWMADEF(BASS_WMA_EncodeOpenPublish)(DWORD freq, DWORD chans, DWORD flags, DWORD bitrate, const char *url, const char *user, const char *pass);
BASS_WMA_EncodeOpenPublish = func_type(HWMENCODE, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p)(('BASS_WMA_EncodeOpenPublish', basswma_module))
#HWMENCODE BASSWMADEF(BASS_WMA_EncodeOpenPublishMulti)(DWORD freq, DWORD chans, DWORD flags, const DWORD *bitrates, const char *url, const char *user, const char *pass);
BASS_WMA_EncodeOpenPublishMulti = func_type(HWMENCODE, ctypes.c_ulong, ctypes.c_ulong, ctypes.c_ulong, ctypes.POINTER(ctypes.c_ulong), ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p)(('BASS_WMA_EncodeOpenPublishMulti', basswma_module))
#DWORD BASSWMADEF(BASS_WMA_EncodeGetPort)(HWMENCODE handle);
BASS_WMA_EncodeGetPort = func_type(ctypes.c_ulong, HWMENCODE)(('BASS_WMA_EncodeGetPort', basswma_module))
#BOOL BASSWMADEF(BASS_WMA_EncodeSetNotify)(HWMENCODE handle, CLIENTCONNECTPROC *proc, void *user);
BASS_WMA_EncodeSetNotify = func_type(ctypes.c_byte, HWMENCODE, CLIENTCONNECTPROC, ctypes.c_void_p)(('BASS_WMA_EncodeSetNotify', basswma_module))
#DWORD BASSWMADEF(BASS_WMA_EncodeGetClients)(HWMENCODE handle);
BASS_WMA_EncodeGetClients = func_type(ctypes.c_ulong, HWMENCODE)(('BASS_WMA_EncodeGetClients', basswma_module))
#BOOL BASSWMADEF(BASS_WMA_EncodeSetTag)(HWMENCODE handle, const char *tag, const char *text, DWORD form);
BASS_WMA_EncodeSetTag = func_type(ctypes.c_byte, HWMENCODE, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_ulong)(('BASS_WMA_EncodeSetTag', basswma_module))
#BOOL BASSWMADEF(BASS_WMA_EncodeWrite)(HWMENCODE handle, const void *buffer, DWORD length);
BASS_WMA_EncodeWrite = func_type(ctypes.c_byte, HWMENCODE, ctypes.c_void_p, ctypes.c_ulong)(('BASS_WMA_EncodeWrite', basswma_module))
#BOOL BASSWMADEF(BASS_WMA_EncodeClose)(HWMENCODE handle);
BASS_WMA_EncodeClose = func_type(ctypes.c_byte, HWMENCODE)(('BASS_WMA_EncodeClose', basswma_module))
#void *BASSWMADEF(BASS_WMA_GetWMObject)(DWORD handle);
BASS_WMA_GetWMObject = func_type(ctypes.c_void_p, ctypes.c_ulong)(('BASS_WMA_GetWMObject', basswma_module))

View File

@@ -1,91 +0,0 @@
from __future__ import print_function
from future.builtins import hex
from .pybass import *
def play_handle(handle, show_tags = True):
if handle == 0:
print(('BASS_StreamCreateFile error', get_error_description(BASS_ErrorGetCode())))
else:
if show_tags:
print('============== Tags Information ==============')
try:
import pytags
print((pytags.TAGS_Read(handle, '%IFV1(%ITRM(%TRCK),%ITRM(%TRCK). )%IFV2(%ITRM(%ARTI),%ICAP(%ITRM(%ARTI)),no artist) - %IFV2(%ITRM(%TITL),%ICAP(%ITRM(%TITL)),no title)%IFV1(%ITRM(%ALBM), - %IUPC(%ITRM(%ALBM)))%IFV1(%YEAR, %(%YEAR%))%IFV1(%ITRM(%GNRE), {%ITRM(%GNRE)})%IFV1(%ITRM(%CMNT), [%ITRM(%CMNT)])')))
except:
print('============== tags module not accessible ==============')
print('============== BASS_ChannelGetTags return ==============')
for tag in get_tags(handle):
print(tag)
for key, value in get_tags_as_dict(handle).items():
print((key, ':', value))
print('============== Channel Information ==============')
channel_info = BASS_CHANNELINFO()
if not BASS_ChannelGetInfo(handle, channel_info):
print(('BASS_ChannelGetInfo error', get_error_description(BASS_ErrorGetCode())))
else:
print(('default playback rate =', channel_info.freq))
print(('channels =', channel_info.chans))
print(('BASS_SAMPLE/STREAM/MUSIC/SPEAKER flags =', channel_info.flags))
print(('type of channel =', hex(channel_info.ctype)))
print(('original resolution =', channel_info.origres))
print(('plugin =', channel_info.plugin))
print(('sample =', channel_info.sample))
print(('filename =', channel_info.filename))
print('============== Ext Channel Information ==============')
channel_length = BASS_ChannelGetLength(handle, BASS_POS_BYTE)
channel_position = BASS_ChannelGetPosition(handle, BASS_POS_BYTE)
print(('Channel Length =', channel_length))
print(('Channel Length =', int(BASS_ChannelBytes2Seconds(handle, channel_length)), 'seconds'))
import time
if not BASS_ChannelPlay(handle, False):
print(('BASS_ChannelPlay error', get_error_description(BASS_ErrorGetCode())))
else:
print('============== Play Information ==============')
while channel_position < channel_length:
channel_position = BASS_ChannelGetPosition(handle, BASS_POS_BYTE)
print(('Channel Position =', channel_position))
print(('Channel Position =', int(BASS_ChannelBytes2Seconds(handle, channel_position)), 'seconds'))
print(('CPU =', BASS_GetCPU()))
time.sleep(1)
if not BASS_StreamFree(handle):
print(('BASS_StreamFree error', get_error_description(BASS_ErrorGetCode())))
if __name__ == "__main__":
print(('BASS implemented Version', BASSVERSIONTEXT))
print(('BASS real Version', hex(BASS_GetVersion())))
if not BASS_Init(-1, 44100, 0, 0, 0):
print(('BASS_Init error', get_error_description(BASS_ErrorGetCode())))
else:
print('============== BASS Information ==============')
bi = BASS_INFO()
if not BASS_GetInfo(bi):
print(('BASS_GetInfo error', get_error_description(BASS_ErrorGetCode())))
else:
print(('device capabilities (DSCAPS_xxx flags) =', bi.flags))
print(('size of total device hardware memory =', bi.hwsize))
print(('size of free device hardware memory =', bi.hwfree))
print(('number of free sample slots in the hardware =', bi.freesam))
print(('number of free 3D sample slots in the hardware =', bi.free3d))
print(('min sample rate supported by the hardware =', bi.minrate))
print(('max sample rate supported by the hardware =', bi.maxrate))
print(('device supports EAX? (always FALSE if BASS_DEVICE_3D was not used) =', bool(bi.eax)))
print(('recommended minimum buffer length in ms (requires BASS_DEVICE_LATENCY) =', bi.minbuf))
print(('DirectSound version =', bi.dsver))
print(('delay (in ms) before start of playback (requires BASS_DEVICE_LATENCY) =', bi.latency))
print(('BASS_Init "flags" parameter =', bi.initflags))
print(('number of speakers available', bi.speakers))
print(('current output rate (Vista/OSX only) =', bi.freq))
print('============== volume ==============')
print(('volume =', BASS_GetVolume()))
print('============== Device Information ==============')
bd = BASS_DEVICEINFO()
if not BASS_GetDeviceInfo(BASS_GetDevice(), bd):
print(('BASS_GetDeviceInfo error', get_error_description(BASS_ErrorGetCode())))
else:
print(('description =', bd.name))
print(('driver =', bd.driver))
print(('flags =', bd.flags))
handle = BASS_StreamCreateFile(False, 'test.ogg', 0, 0, 0)
play_handle(handle)
if not BASS_Free():
print(('BASS_Free error', get_error_description(BASS_ErrorGetCode())))

View File

@@ -1,66 +0,0 @@
from __future__ import absolute_import
from future.builtins import object
from ctypes import string_at
import wave
from .external.pybass import *
from . import config
from .main import bass_call, bass_call_0, BassError
class Input (object):
def __init__ (self, device=-1):
try:
bass_call(BASS_RecordInit, device)
except BassError:
pass
self._device = device
self.config = config.BassConfig()
def free(self):
"""Frees all resources used by the recording device."""
return bass_call(BASS_RecordFree)
def get_device(self):
return bass_call_0(BASS_RecordGetDevice)
def set_device(self, device):
if device == self._device:
return
self.free()
self.__init__(device=device)
device = property(fget=get_device, fset=set_device)
@staticmethod
def get_device_names():
"""Convenience method that returns a list of device names that are considered
valid by bass.
Parameters: none.
returns: list of devices, 0-indexed.
"""
result = ['Default']
info = BASS_DEVICEINFO()
count = 0
while BASS_RecordGetDeviceInfo(count, ctypes.byref(info)):
if info.flags & BASS_DEVICE_ENABLED:
retrieved = info.name
if platform.system() == 'Windows':
retrieved = retrieved.decode('mbcs')
retrieved = retrieved.replace('(', '').replace(')', '').strip()
result.append(retrieved)
count += 1
return result
def find_device_by_name(self, name):
return self.get_device_names().index(name) - 1
def find_default_device(self):
return -1
def find_user_provided_device(self, device_name):
try:
return self.find_device_by_name(device_name)
except ValueError:
return self.find_default_device()

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More