|
3 | 3 | from plexapi.exceptions import BadRequest, NotFound |
4 | 4 | from plexapi.base import Playable, PlexPartialObject |
5 | 5 | from plexapi.compat import quote_plus |
6 | | -import ntpath |
| 6 | +import os |
| 7 | + |
7 | 8 |
|
8 | 9 | class Video(PlexPartialObject): |
9 | 10 | """ Base class for all video objects including :class:`~plexapi.video.Movie`, |
@@ -227,27 +228,19 @@ def subtitleStreams(self): |
227 | 228 | streams += part.subtitleStreams() |
228 | 229 | return streams |
229 | 230 |
|
230 | | - def uploadSubtitles(self, file): |
| 231 | + def uploadSubtitles(self, filepath): |
231 | 232 | """ Upload Subtitle file for video. """ |
232 | 233 | url = '%s/subtitles' % self.key |
233 | | - filename = ntpath.basename(file) |
234 | | - with open(file, 'rb') as subfile: |
| 234 | + filename = os.path.basename(filepath) |
| 235 | + subFormat = os.path.splitext(filepath)[1][1:] |
| 236 | + with open(filepath, 'rb') as subfile: |
235 | 237 | params = {'title': filename, |
236 | | - 'format': filename.rsplit('.', 1)[1] |
| 238 | + 'format': subFormat |
237 | 239 | } |
238 | 240 | headers = {'Accept': 'text/plain, */*'} |
239 | 241 | self._server.query(url, self._server._session.post, data=subfile, params=params, headers=headers) |
240 | 242 | self.reload() |
241 | 243 |
|
242 | | - def selectSubtitle(self, streamID=int, streamTitle=str): |
243 | | - """ Select Subtitle for movie. """ |
244 | | - url = '/library/parts/%s' % self.media[0].parts[0].id |
245 | | - for stream in self.subtitleStreams(): |
246 | | - if streamID == stream.id or streamTitle == stream.title: |
247 | | - params = {'subtitleStreamID': stream.id} |
248 | | - self._server.query(url, self._server._session.put, params=params) |
249 | | - self.reload() |
250 | | - |
251 | 244 | def removeSubtitles(self, streamID=int, streamTitle=str): |
252 | 245 | """ Remove Subtitle from movie's subtitles listing. """ |
253 | 246 | for stream in self.subtitleStreams(): |
@@ -659,29 +652,21 @@ def subtitleStreams(self): |
659 | 652 | streams += part.subtitleStreams() |
660 | 653 | return streams |
661 | 654 |
|
662 | | - def uploadSubtitles(self, file): |
| 655 | + def uploadSubtitles(self, filepath): |
663 | 656 | """ Upload Subtitle file for video. """ |
664 | 657 | url = '%s/subtitles' % self.key |
665 | | - filename = ntpath.basename(file) |
666 | | - with open(file, 'rb') as subfile: |
| 658 | + filename = os.path.basename(filepath) |
| 659 | + subFormat = os.path.splitext(filepath)[1][1:] |
| 660 | + with open(filepath, 'rb') as subfile: |
667 | 661 | params = {'title': filename, |
668 | | - 'format': filename.rsplit('.', 1)[1] |
| 662 | + 'format': subFormat |
669 | 663 | } |
670 | 664 | headers = {'Accept': 'text/plain, */*'} |
671 | 665 | self._server.query(url, self._server._session.post, data=subfile, params=params, headers=headers) |
672 | 666 | self.reload() |
673 | 667 |
|
674 | | - def selectSubtitle(self, streamID=int, streamTitle=str): |
675 | | - """ Select Subtitle for episode. """ |
676 | | - url = '/library/parts/%s' % self.media[0].parts[0].id |
677 | | - for stream in self.subtitleStreams(): |
678 | | - if streamID == stream.id or streamTitle == stream.title: |
679 | | - params = {'subtitleStreamID': stream.id} |
680 | | - self._server.query(url, self._server._session.put, params=params) |
681 | | - self.reload() |
682 | | - |
683 | 668 | def removeSubtitles(self, streamID=int, streamTitle=str): |
684 | | - """ Remove Subtitle from episode's subtitles listing. """ |
| 669 | + """ Remove Subtitle from movie's subtitles listing. """ |
685 | 670 | for stream in self.subtitleStreams(): |
686 | 671 | if streamID == stream.id or streamTitle == stream.title: |
687 | 672 | self._server.query(stream.key, self._server._session.delete) |
|
0 commit comments