├── Default (Linux).sublime-keymap ├── Default (OSX).sublime-keymap ├── Default (Windows).sublime-keymap ├── README.md ├── LICENSE └── medialime.py /Default (Linux).sublime-keymap: -------------------------------------------------------------------------------- 1 | [ 2 | { "keys": ["ctrl+m"], "command": "medialime" }, 3 | ] 4 | -------------------------------------------------------------------------------- /Default (OSX).sublime-keymap: -------------------------------------------------------------------------------- 1 | [ 2 | { "keys": ["super+m"], "command": "medialime" }, 3 | ] 4 | -------------------------------------------------------------------------------- /Default (Windows).sublime-keymap: -------------------------------------------------------------------------------- 1 | [ 2 | { "keys": ["ctrl+m"], "command": "medialime" }, 3 | ] 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Medialime 2 | 3 | Plugin for Sublime Text 3 to play music from the text editor. 4 | 5 | # Dependencies 6 | 7 | This needs `mplayer` to be installed on your machine. 8 | 9 | * For Mac OS X, you can do `brew install mplayer`. 10 | * For Linux, use your package manager to install. 11 | * Windows users can get pre-built binaries from [here](http://oss.netfarm.it/mplayer/). 12 | 13 | # Installation 14 | 15 | Open the Sublime Text command palette (`Cmd+Shift+P` or `Ctrl+Shift+P`) and add repository that points to `https://github.com/sankha93/medialime`. Open the command palette and do a install package and select `medialime`. 16 | 17 | # Using 18 | 19 | To access `medialime` anytime press `Cmd+M` or `Ctrl+M`. You can set the path to your Music library or the mplayer binary. The plugin will index the library and you can play/pause any of your songs while working in yoir favourite text editor. 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Sankha Narayan Guria 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /medialime.py: -------------------------------------------------------------------------------- 1 | import os, subprocess 2 | import sublime, sublime_plugin 3 | 4 | class MedialimeCommand(sublime_plugin.WindowCommand): 5 | def run(self): 6 | sublime.status_message("Indexing library ...") 7 | show_menu() 8 | 9 | music_library = "" 10 | current_playing = "None" 11 | mplayer_process = -1 12 | library_index = {} 13 | songs = [] 14 | paused = False 15 | preferences = sublime.load_settings("Preferences.sublime-settings") 16 | 17 | def show_menu(): 18 | global preferences, music_library, library_index, songs 19 | preferences = sublime.load_settings("Preferences.sublime-settings") 20 | music_library = str(preferences.get("music_library")) 21 | inbuilt = [] 22 | if (paused): 23 | inbuilt.append(["Play", "Now playing: " + current_playing]) 24 | else: 25 | inbuilt.append(["Pause", "Now playing: " + current_playing]) 26 | inbuilt += [ 27 | ["Set Music Library", "Current Directory: " + music_library], 28 | ["Set mplayer path", str(preferences.get("mplayer_path", "mplayer"))] 29 | ] 30 | library_index = index_files(music_library) 31 | songs = list(library_index.keys()) 32 | listing = inbuilt + songs 33 | sublime.active_window().show_quick_panel(listing, selected_option) 34 | sublime.status_message("") 35 | 36 | def update_music_library(new_location): 37 | global music_library 38 | music_library = new_location 39 | preferences.set("music_library", new_location) 40 | sublime.save_settings("Preferences.sublime-settings") 41 | 42 | def update_mplayer_path(new_path): 43 | preferences.set("mplayer_path", new_path) 44 | sublime.save_settings("Preferences.sublime-settings") 45 | 46 | def selected_option(index): 47 | global current_playing, mplayer_process, paused 48 | if (index < 3): 49 | if (index == 0 and mplayer_process != -1 and mplayer_process.poll() is None): 50 | if (paused): 51 | paused = False 52 | else: 53 | paused = True 54 | mplayer_process.stdin.write(b"pause\n") 55 | mplayer_process.stdin.flush() 56 | elif (index == 1): 57 | sublime.active_window().show_input_panel("Music library", music_library, update_music_library, None, None) 58 | else: 59 | sublime.active_window().show_input_panel("mplayer_path", preferences.get("mplayer_path", "mplayer"), update_mplayer_path, None, None) 60 | else: 61 | if (mplayer_process != -1 and mplayer_process.poll() is None): 62 | mplayer_process.kill() 63 | index -= 3 64 | try: 65 | mplayer_process = subprocess.Popen([preferences.get("mplayer_path", "mplayer"), "-slave", library_index[songs[index]]], stdin=subprocess.PIPE) 66 | current_playing = songs[index] 67 | paused = False 68 | sublime.status_message("Now playing: " + current_playing) 69 | except Exception: 70 | pass 71 | 72 | def index_files(music_library): 73 | library_index = {} 74 | for root, dirs, files in os.walk(music_library): 75 | for f in files: 76 | filename, file_ext = os.path.splitext(os.path.join(root, f)) 77 | if file_ext == ".mp3": 78 | library_index[f] = os.path.join(root, f) 79 | return library_index 80 | 81 | def plugin_unloaded(): 82 | if mplayer_process != -1: 83 | mplayer_process.kill() 84 | --------------------------------------------------------------------------------