|
1 | | -# playmedia |
2 | | - |
3 | | -## Install |
4 | | -`pip install playmedia` |
5 | | - |
6 | | ------------- |
7 | | - |
8 | | -**playmedia** python package helps you easily play and control media files. It uses multithreading technology ( playback run in a different thread ). It means after calling `play_single( filepath )` or `play_multiple( directoryPath, shuffle )` execution of program does not stop. |
9 | | - |
10 | | -Example :- |
11 | | -```python |
12 | | -from playmedia import * |
13 | | - |
14 | | -play_single("C:\\Users\\Satvik\\Music\\Why do I.mp3") |
15 | | -print("This is printed as soon as play_single() is called. It does not wait for song to finish") |
16 | | - |
17 | | -#Output : |
18 | | -This is printed as soon as play_single() is called. It does not wait for song to finish |
19 | | -``` |
20 | | -It supports almost all popular formats :- |
21 | | -- .m4a |
22 | | -- .flac |
23 | | -- .mp3 |
24 | | -- .mp4 |
25 | | -- .wav |
26 | | -- .wma |
27 | | -- .aac |
28 | | -- .mkv |
29 | | - |
30 | | -It has 2 major functions :- |
31 | | -1. play_single() |
32 | | -2. play_multiple() |
33 | | - |
34 | | ------------- |
35 | | - |
36 | | -### 1. play_single( filepath ) |
37 | | -`play_single( filepath )` |
38 | | -- filepath ->full path of loaction of media eg.(**"C:\\\Users\\\Satvik\\\Music\\\Why do I.mp3"**). Double backslash( \\\ ) should be used as using others might throw unicode error. |
39 | | - |
40 | | -It has 3 method inside it. |
41 | | -- `pause_single()` - Pauses the song. (calling `pause_single()` again resumes it) |
42 | | - |
43 | | -- `set_volume_single(vol)` - Sets the volume of player to vol%. Eg. `set_volume_single(60)` sets volume to 60% |
44 | | - |
45 | | -- `stop_single()` - Stops playing . Only it should be called to stop playing. Using other techniques might stop playing but not stop the thread |
46 | | - |
47 | | -Example Usage :- |
48 | | -```python |
49 | | -from playmedia import * |
50 | | - |
51 | | -play_single("C:\\Users\\Satvik\\Music\\Why do I.mp3") |
52 | | -#playing started |
53 | | -pause_single() |
54 | | -#pauses |
55 | | -pause_single() |
56 | | -#calling pause_single() again resumes the song |
57 | | -set_volume_single(60) |
58 | | -#sets volume to 60% |
59 | | -stop_single() |
60 | | -#stops playing the song |
61 | | - |
62 | | -``` |
63 | | - |
64 | | ------------- |
65 | | - |
66 | | -### 2. play_multiple( directoryPath, shuffle ) |
67 | | -`play_multiple( directoryPath, shuffle )` |
68 | | -- directoryPath ->full path of directory containing multiple media eg.(**"C:\\\Users\\\Satvik\\\Music\\\"**). Double backslash( \\\ ) should be used as using others might throw unicode error. Also double backslash( \\\ ) at the end is neccesary. |
69 | | -- shuffle ->**True** if you want the songs to be played in random order else **False** |
70 | | - |
71 | | -It has 5 method inside it. |
72 | | -- `pause_multiple()` - Pauses the song. (calling `pause_multiple()` again resumes it) |
73 | | - |
74 | | -- `set_volume_multiple(vol)` - Sets the volume of player to vol%. Eg. `set_volume_multiple(60)` sets volume to 60% |
75 | | - |
76 | | -- `next_multiple()` - Plays next song in the list |
77 | | - |
78 | | -- `previous_multiple` - Plays previous song in the list |
79 | | - |
80 | | -- `stop_multiple()` - Stops playing . Only it should be called to stop playing. Using other techniques might stop playing but not stop the thread |
81 | | - |
82 | | -Example Usage:- |
83 | | -```python |
84 | | -from playmedia import * |
85 | | - |
86 | | -play_multiple("C:\\Users\\Satvik\\Music\\", False) |
87 | | -#started playing |
88 | | -pause_multiple() |
89 | | -#pauses the current song |
90 | | -pause_multiple() |
91 | | -#calling pause_multiple() again resumes the current song |
92 | | -next_multiple() |
93 | | -#plays next song in the list |
94 | | -previous_multiple() |
95 | | -#plays previous song in the list |
96 | | -set_volume_multiple(60) |
97 | | -#sets volume to 60% |
98 | | -stop_multiple() |
99 | | -#stops playing the songs |
100 | | -``` |
101 | | - |
102 | | ------------- |
103 | | - |
104 | | -## 🤝Contributing |
105 | | -Contributions, issues and feature requests are welcome! |
106 | | -Feel free to check [Bug Tracker](https://github.com/SatvikVirmani/playmedia/issues "issues") page. |
107 | | -To submit improvements or features check [Pull Requests](https://github.com/SatvikVirmani/playmedia/pulls "Pull Requests") |
| 1 | +<p align="center"> |
| 2 | + <h1 align="center">playmedia</h1> |
| 3 | +</p> |
| 4 | + |
| 5 | +> ### A python module to play and control media files. |
| 6 | +
|
| 7 | +<p align="center"> |
| 8 | + <a href=""> |
| 9 | + <img src="https://img.shields.io/badge/Made%20by%20Satvik%20Virmani-000000?style=for-the-badge"> |
| 10 | + </a> |
| 11 | +</p> |
| 12 | + |
| 13 | +<p align="center"> |
| 14 | + <img src="https://img.shields.io/github/license/satvikvirmani/playmedia?color=000000&logoColor=000000&style=for-the-badge"> |
| 15 | + <img src="https://img.shields.io/github/issues/satvikvirmani/playmedia?color=000000&logoColor=000000&style=for-the-badge"> |
| 16 | + <img src="https://img.shields.io/github/last-commit/satvikvirmani/playmedia?color=000000&logoColor=000000&style=for-the-badge"> |
| 17 | +</p> |
| 18 | + |
| 19 | +## Installation |
| 20 | + |
| 21 | +```python |
| 22 | +pip install playmedia |
| 23 | +``` |
| 24 | + |
| 25 | +## Dependencies |
| 26 | + |
| 27 | +* [VLC Media Player](https://sourceforge.net/projects/vlc/) |
| 28 | + |
| 29 | +## Usage |
| 30 | + |
| 31 | +1. ### class File |
| 32 | + You can initiate the File class with the path of the media file as argument. |
| 33 | + ```python |
| 34 | + File("path/to/the/media/file") |
| 35 | + ``` |
| 36 | + |
| 37 | + * #### start() |
| 38 | + ##### This method starts the playback |
| 39 | + args = None, return = string |
| 40 | + |
| 41 | + * #### pause(status) |
| 42 | + ##### This method pauses/resumes the playback |
| 43 | + args = [status: boolean], return = string |
| 44 | + |
| 45 | + * #### mute(status) |
| 46 | + ##### This method mutes/unmutes the playback |
| 47 | + args = [status: boolean], return = string |
| 48 | + |
| 49 | + * #### set_volume(vol) |
| 50 | + ##### This method set the volume of the playback |
| 51 | + args = [vol: int], defaults = [vol: 100], return = string |
| 52 | + |
| 53 | + * #### stop() |
| 54 | + ##### This method stops the playback |
| 55 | + args = None, return = None |
| 56 | + |
| 57 | + * #### meta(tag) |
| 58 | + ##### This method returns the meta data of the media |
| 59 | + args = [tag: string], defaults = [tag: "Date"], return = string |
| 60 | + |
| 61 | + * #### edit_meta(tag, new_value) |
| 62 | + ##### This method changes the meta data values |
| 63 | + args = [tag: string, new_value: string], return = string |
| 64 | + |
| 65 | + Supported tags = Actors, Album, AlbumArtist, Artist, ArtworkURL, Copyright, Date, Description, Director, DiscNumber, DiscTotal, EncodedBy, Episode, Genre, Language, NowPlaying, Publisher, Rating, Season, Setting, ShowName, Title, TrackID, TrackNumber, TrackTotal, URL |
| 66 | + |
| 67 | + ```python |
| 68 | + instance = File("path/of/the/media/file/Why do I?.mp3") |
| 69 | + instance.start() # Returns Now playing Why do I? |
| 70 | + instance.pause(True) # Returns Paused |
| 71 | + instance.mute(False) # Returns Unmuted |
| 72 | + instance.set_volume(75) # Returns Volume set to 75% |
| 73 | + instance.meta("Artist") # Returns Artist: Unknown Brain |
| 74 | + instance.edit_meta("Album","playmedia") # Changed Album to playmedia |
| 75 | + instance.stop() |
| 76 | + ``` |
| 77 | + |
| 78 | + > Note: Statements are returned not printed. To print the returned values use `print(instance.set_volume(75))` |
| 79 | + * #### stop() |
| 80 | + args = None, return = None |
| 81 | +2. ### class Files |
| 82 | + You can initiate the File class with either the path of the dirctory containing files or list with paths of the media files. |
| 83 | + ```python |
| 84 | + Files("path/to/the/dirctory/containing/media/file") |
| 85 | + or |
| 86 | + Files(["path/to/media/file/1", "path/to/media/file/2"]) |
| 87 | + ``` |
| 88 | + |
| 89 | + * #### get_list() |
| 90 | + ##### This method returns a dictionary with index as keys and files as values |
| 91 | + args = None, return = dictionary |
| 92 | + |
| 93 | + * #### start() |
| 94 | + ##### This method starts the playback in order |
| 95 | + args = None, return = dictionary |
| 96 | + |
| 97 | + * #### play_at_index(index) |
| 98 | + ##### This method starts the playback of the media file at the given index |
| 99 | + args = [index: int], return = string |
| 100 | + |
| 101 | + * #### pause(status) |
| 102 | + ##### This method pauses/resumes the playback |
| 103 | + args = [status: boolean], return = string |
| 104 | + |
| 105 | + * #### next() |
| 106 | + ##### This method skips the current media and plays the next one |
| 107 | + args = None, return = string |
| 108 | + |
| 109 | + * #### previous() |
| 110 | + ##### This method plays the previous media |
| 111 | + args = None, return = string |
| 112 | + |
| 113 | + * #### mute(status) |
| 114 | + ##### This method mutes/unmutes the playback |
| 115 | + args = [status: boolean], return = string |
| 116 | + |
| 117 | + * #### set_volume(vol) |
| 118 | + ##### This method set the volume of the playback |
| 119 | + args = [vol: int], defaults = [vol: 100], return = string |
| 120 | + |
| 121 | + * #### stop() |
| 122 | + ##### This method stops the playback |
| 123 | + args = None, return = None |
| 124 | + |
| 125 | + * #### current_meta(tag) |
| 126 | + ##### This method returns the meta data of the currently playing media |
| 127 | + args = [tag: string], defaults = [tag: "Date"], return = string |
| 128 | + |
| 129 | + > Note: A media should be playing when this method is called. Either call start(), play_at_index(index) before otherwise it raises a IndexError. |
| 130 | + |
| 131 | + Supported tags = Actors, Album, AlbumArtist, Artist, ArtworkURL, Copyright, Date, Description, Director, DiscNumber, DiscTotal, EncodedBy, Episode, Genre, Language, NowPlaying, Publisher, Rating, Season, Setting, ShowName, Title, TrackID, TrackNumber, TrackTotal, URL |
| 132 | + |
| 133 | + * #### current_time() |
| 134 | + args = None, return = dictionary |
| 135 | + |
| 136 | + ```python |
| 137 | + instance = File("path/to/the/dirctory/containing/media/file") |
| 138 | + instance.get_list() # Returns {0: 'File 1.mp3', 1: 'File 2 .mp4', 2: 'File 3.wav'} |
| 139 | + instance.start() # Returns {0: 'File 1.mp3', 1: 'File 2 .mp4', 2: 'File 3.wav'} |
| 140 | + instance.stop() |
| 141 | + instance.play_at_index(1) # Returns Now playing File 2 |
| 142 | + instance.pause(True) # Returns Paused |
| 143 | + instance.mute(False) # Returns Unmuted |
| 144 | + instance.set_volume(75) # Returns Volume set to 75% |
| 145 | + instance.current_meta("Artist") # Returns Artist: "Artist of File 2" |
| 146 | + instance.current_time("Album","playmedia") # Returns {"Current time": '98.63s'} |
| 147 | + ``` |
| 148 | + |
| 149 | + > Note: Statements are returned not printed. To print the returned values use `print(instance.set_volume(75))` |
| 150 | + |
| 151 | + |
| 152 | +#### Supported Files |
| 153 | +1. '.m4a' |
| 154 | +2. '.flac' |
| 155 | +3. '.mp3' |
| 156 | +4. '.mp4' |
| 157 | +5. '.wav' |
| 158 | +6. '.wma' |
| 159 | +7. '.aac' |
| 160 | +8. '.mkv' |
| 161 | + |
| 162 | +## Author |
| 163 | + |
| 164 | +### Satvik Virmani |
| 165 | + |
| 166 | +<a href="https://twitter.com/satvikvirmani"> |
| 167 | + <img src="https://img.shields.io/twitter/follow/satvikvirmani?color=000000&logo=twitter&logoColor=FFFFFF&style=for-the-badge"> |
| 168 | +</a> |
| 169 | + |
| 170 | +## Contributions |
| 171 | + |
| 172 | +Contributions, issues and feature requests are welcome! |
| 173 | +Feel free to check [issues](https://github.com/satvikvirmani/playmedia/issues) page. |
| 174 | + |
| 175 | +## Show your support |
| 176 | + |
| 177 | +Give a ⭐️ if this project helped you! |
0 commit comments