Skip to content

Commit e0d5a87

Browse files
committed
misc fixes
1 parent ed3d16d commit e0d5a87

File tree

6 files changed

+46
-58
lines changed

6 files changed

+46
-58
lines changed

plexapi/library.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -529,15 +529,13 @@ def search(self, title=None, sort=None, maxresults=999999, libtype=None, **kwarg
529529
# cleanup the core arguments
530530
args = {}
531531
for category, value in kwargs.items():
532-
log.info("ttt %s %s",category, value)
533532
args[category] = self._cleanSearchFilter(category, value, libtype)
534533
if title is not None:
535534
args['title'] = title
536535
if sort is not None:
537536
args['sort'] = self._cleanSearchSort(sort)
538537
if libtype is not None:
539538
args['type'] = utils.searchType(libtype)
540-
log.info("ass %s", self.key)
541539
# iterate over the results
542540
results, subresults = [], '_init'
543541
args['X-Plex-Container-Start'] = 0
@@ -1018,9 +1016,11 @@ class Collections(PlexObject):
10181016

10191017
TAG = 'Directory'
10201018
TYPE = 'collection'
1019+
_include = "?includeExternalMedia=1&includePreferences=1"
10211020

10221021
def _loadData(self, data):
10231022
self.ratingKey = utils.cast(int, data.attrib.get('ratingKey'))
1023+
self._details_key = "/library/metadata/%s%s" % (self.ratingKey, self._include)
10241024
self.key = data.attrib.get('key')
10251025
self.type = data.attrib.get('type')
10261026
self.title = data.attrib.get('title')
@@ -1040,13 +1040,6 @@ def _loadData(self, data):
10401040
def children(self):
10411041
return self.fetchItems(self.key)
10421042

1043-
def reload(self, key=None):
1044-
return self.fetchItem(int(self.ratingKey))
1045-
#return self.reload(key=self._initpath)
1046-
res = self.fetchItems(self._initpath)
1047-
if len(res):
1048-
return [i for i in res if i.ratingKey == self.ratingKey][0]
1049-
10501043
def __len__(self):
10511044
return self.childCount
10521045

@@ -1075,7 +1068,6 @@ def modeUpdate(self, mode=None):
10751068
if key is None:
10761069
raise BadRequest('Unknown collection mode : %s. Options %s' % (mode, list(mode_dict)))
10771070
part = '/library/metadata/%s/prefs?collectionMode=%s' % (self.ratingKey, key)
1078-
log.info("ffs part key %s", part)
10791071
return self._server.query(part, method=self._server._session.put)
10801072

10811073
def sortUpdate(self, sort=None):

plexapi/utils.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
import logging
33
import os
44
import re
5-
import requests
65
import time
76
import zipfile
87
from datetime import datetime
98
from getpass import getpass
10-
from threading import Thread, Event
11-
from tqdm import tqdm
9+
from threading import Event, Thread
10+
11+
import requests
1212
from plexapi import compat
1313
from plexapi.exceptions import NotFound
14+
from tqdm import tqdm
1415

1516
log = logging.getLogger('plexapi')
1617

@@ -67,10 +68,13 @@ def cast(func, value):
6768
"""
6869
if value is not None:
6970
if func == bool:
70-
try:
71-
return bool(int(value))
72-
except ValueError:
73-
return bool(value)
71+
if value in (1, True, "1", "true"):
72+
return True
73+
elif value in (0, False, "0", "false"):
74+
return False
75+
else:
76+
raise ValueError(value)
77+
7478
elif func in (int, float):
7579
try:
7680
return func(value)

tests/test_history.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# -*- coding: utf-8 -*-
2-
import pytest
32
from datetime import datetime
3+
4+
import pytest
45
from plexapi.exceptions import BadRequest, NotFound
6+
57
from . import conftest as utils
68

79

@@ -20,7 +22,7 @@ def test_history_Show(show):
2022

2123

2224
def test_history_Season(show):
23-
season = show.season('Season 1')
25+
season = show.season("Season 1")
2426
season.markWatched()
2527
history = season.history()
2628
assert len(history)
@@ -66,7 +68,7 @@ def test_history_MyLibrary(plex, movie, show):
6668

6769
def test_history_MySection(plex, movie):
6870
movie.markWatched()
69-
history = plex.library.section('Movies').history()
71+
history = plex.library.section("Movies").history()
7072
assert len(history)
7173
movie.markUnwatched()
7274

@@ -89,6 +91,7 @@ def test_history_UserServer(account, shared_username, plex):
8991

9092

9193
def test_history_UserSection(account, shared_username, plex):
92-
userSharedServerSection = account.user(shared_username).server(plex.friendlyName).section('Movies')
94+
userSharedServerSection = (
95+
account.user(shared_username).server(plex.friendlyName).section("Movies")
96+
)
9397
history = userSharedServerSection.history()
94-

tests/test_library.py

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -212,53 +212,30 @@ def test_library_and_section_search_for_movie(plex):
212212
assert l_search == s_search
213213

214214

215-
#@pytest.mark.skip(reason="broken test?")
216-
def test_library_Colletion_modeUpdate_hide(collection):
217-
collection.modeUpdate(mode="hide")
218-
collection.reload()
219-
assert collection.collectionMode == "0"
220-
221-
222-
#@pytest.mark.skip(reason="broken test?")
223-
def test_library_Colletion_modeUpdate_default(collection):
224-
collection.modeUpdate(mode="default")
225-
collection.reload()
226-
assert collection.collectionMode == "-2"
227-
228-
229-
#@pytest.mark.skip(reason="broken test?")
230-
def test_library_Colletion_modeUpdate_hideItems(collection):
231-
collection.modeUpdate(mode="hideItems")
232-
collection.reload()
233-
assert collection.collectionMode == "1"
234-
235-
236-
#@pytest.mark.skip(reason="broken test?")
237-
def test_library_Colletion_modeUpdate_showItems(collection):
238-
collection.modeUpdate(mode="showItems")
239-
collection.reload()
240-
assert collection.collectionMode == "2"
215+
def test_library_Collection_modeUpdate(collection):
216+
mode_dict = {"default": "-2", "hide": "0", "hideItems": "1", "showItems": "2"}
217+
for key, value in mode_dict.items():
218+
collection.modeUpdate(key)
219+
collection.reload()
220+
assert collection.collectionMode == value
241221

242222

243-
#@pytest.mark.skip(reason="broken test?")
244223
def test_library_Colletion_sortAlpha(collection):
245224
collection.sortUpdate(sort="alpha")
246225
collection.reload()
247226
assert collection.collectionSort == "1"
248227

249228

250-
@pytest.mark.skip(reason="broken test?")
251229
def test_library_Colletion_sortRelease(collection):
252230
collection.sortUpdate(sort="release")
253231
collection.reload()
254232
assert collection.collectionSort == "0"
255233

256234

257-
@pytest.mark.skip(reason="broken test?")
258-
def test_search_with_apostrophe(plex):
259-
show_title = "Marvel's Daredevil"
260-
result_root = plex.search(show_title)
261-
result_shows = plex.library.section("TV Shows").search(show_title)
235+
def test_search_with_weird_a(plex):
236+
ep_title = "Coup de Grâce"
237+
result_root = plex.search(ep_title)
238+
result_shows = plex.library.section("TV Shows").searchEpisodes(title=ep_title)
262239
assert result_root
263240
assert result_shows
264241
assert result_root == result_shows

tests/test_server.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ def test_server_downloadDatabases(tmpdir, plex):
276276
plex.downloadDatabases(savepath=str(tmpdir), unpack=True)
277277
assert len(tmpdir.listdir()) > 1
278278

279+
279280
def test_server_allowMediaDeletion(account):
280281
plex = PlexServer(utils.SERVER_BASEURL, account.authenticationToken)
281282
# Check server current allowMediaDeletion setting

tests/test_video.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding: utf-8 -*-
2+
import os
23
from datetime import datetime
34
from time import sleep
45

@@ -12,12 +13,14 @@ def test_video_Movie(movies, movie):
1213
movie2 = movies.get(movie.title)
1314
assert movie2.title == movie.title
1415

16+
1517
def test_video_Movie_attributeerror(movie):
1618
with pytest.raises(AttributeError):
1719
movie.asshat
1820

21+
1922
def test_video_ne(movies):
20-
assert len(movies.fetchItems('/library/sections/1/all', title__ne='Sintel')) == 3
23+
assert len(movies.fetchItems('/library/sections/%s/all' % movies.key, title__ne='Sintel')) == 3
2124

2225

2326
def test_video_Movie_delete(movie, patched_http_call):
@@ -86,30 +89,38 @@ def test_video_Movie_download(monkeydownload, tmpdir, movie):
8689
def test_video_Movie_subtitlestreams(movie):
8790
assert not movie.subtitleStreams()
8891

92+
8993
def test_video_Episode_subtitlestreams(episode):
9094
assert not episode.subtitleStreams()
9195

96+
9297
def test_video_Movie_upload_select_remove_subtitle(movie, subtitle):
93-
import os
98+
9499
filepath = os.path.realpath(subtitle.name)
95100
movie.uploadSubtitles(filepath)
101+
movie.reload()
96102
subtitles = [sub.title for sub in movie.subtitleStreams()]
97103
subname = subtitle.name.rsplit('.', 1)[0]
98104
assert subname in subtitles
99105

100106
subtitleSelection = movie.subtitleStreams()[0]
101107
parts = [part for part in movie.iterParts()]
102108
parts[0].setDefaultSubtitleStream(subtitleSelection)
109+
movie.reload()
103110

104111
subtitleSelection = movie.subtitleStreams()[0]
105112
assert subtitleSelection.selected
106113

107114
movie.removeSubtitles(streamTitle=subname)
115+
movie.reload()
108116
subtitles = [sub.title for sub in movie.subtitleStreams()]
109117
assert subname not in subtitles
110118

111-
if subtitle:
119+
try:
112120
os.remove(filepath)
121+
except:
122+
pass
123+
113124

114125
def test_video_Movie_attrs(movies):
115126
movie = movies.get('Sita Sings the Blues')

0 commit comments

Comments
 (0)