misc fixes

This commit is contained in:
Hellowlol 2020-04-16 00:30:00 +02:00
parent ed3d16d1b0
commit e0d5a873e1
6 changed files with 46 additions and 58 deletions

View file

@ -529,7 +529,6 @@ class LibrarySection(PlexObject):
# cleanup the core arguments
args = {}
for category, value in kwargs.items():
log.info("ttt %s %s",category, value)
args[category] = self._cleanSearchFilter(category, value, libtype)
if title is not None:
args['title'] = title
@ -537,7 +536,6 @@ class LibrarySection(PlexObject):
args['sort'] = self._cleanSearchSort(sort)
if libtype is not None:
args['type'] = utils.searchType(libtype)
log.info("ass %s", self.key)
# iterate over the results
results, subresults = [], '_init'
args['X-Plex-Container-Start'] = 0
@ -1018,9 +1016,11 @@ class Collections(PlexObject):
TAG = 'Directory'
TYPE = 'collection'
_include = "?includeExternalMedia=1&includePreferences=1"
def _loadData(self, data):
self.ratingKey = utils.cast(int, data.attrib.get('ratingKey'))
self._details_key = "/library/metadata/%s%s" % (self.ratingKey, self._include)
self.key = data.attrib.get('key')
self.type = data.attrib.get('type')
self.title = data.attrib.get('title')
@ -1040,13 +1040,6 @@ class Collections(PlexObject):
def children(self):
return self.fetchItems(self.key)
def reload(self, key=None):
return self.fetchItem(int(self.ratingKey))
#return self.reload(key=self._initpath)
res = self.fetchItems(self._initpath)
if len(res):
return [i for i in res if i.ratingKey == self.ratingKey][0]
def __len__(self):
return self.childCount
@ -1075,7 +1068,6 @@ class Collections(PlexObject):
if key is None:
raise BadRequest('Unknown collection mode : %s. Options %s' % (mode, list(mode_dict)))
part = '/library/metadata/%s/prefs?collectionMode=%s' % (self.ratingKey, key)
log.info("ffs part key %s", part)
return self._server.query(part, method=self._server._session.put)
def sortUpdate(self, sort=None):

View file

@ -2,15 +2,16 @@
import logging
import os
import re
import requests
import time
import zipfile
from datetime import datetime
from getpass import getpass
from threading import Thread, Event
from tqdm import tqdm
from threading import Event, Thread
import requests
from plexapi import compat
from plexapi.exceptions import NotFound
from tqdm import tqdm
log = logging.getLogger('plexapi')
@ -67,10 +68,13 @@ def cast(func, value):
"""
if value is not None:
if func == bool:
try:
return bool(int(value))
except ValueError:
return bool(value)
if value in (1, True, "1", "true"):
return True
elif value in (0, False, "0", "false"):
return False
else:
raise ValueError(value)
elif func in (int, float):
try:
return func(value)

View file

@ -1,7 +1,9 @@
# -*- coding: utf-8 -*-
import pytest
from datetime import datetime
import pytest
from plexapi.exceptions import BadRequest, NotFound
from . import conftest as utils
@ -20,7 +22,7 @@ def test_history_Show(show):
def test_history_Season(show):
season = show.season('Season 1')
season = show.season("Season 1")
season.markWatched()
history = season.history()
assert len(history)
@ -66,7 +68,7 @@ def test_history_MyLibrary(plex, movie, show):
def test_history_MySection(plex, movie):
movie.markWatched()
history = plex.library.section('Movies').history()
history = plex.library.section("Movies").history()
assert len(history)
movie.markUnwatched()
@ -89,6 +91,7 @@ def test_history_UserServer(account, shared_username, plex):
def test_history_UserSection(account, shared_username, plex):
userSharedServerSection = account.user(shared_username).server(plex.friendlyName).section('Movies')
userSharedServerSection = (
account.user(shared_username).server(plex.friendlyName).section("Movies")
)
history = userSharedServerSection.history()

View file

@ -212,53 +212,30 @@ def test_library_and_section_search_for_movie(plex):
assert l_search == s_search
#@pytest.mark.skip(reason="broken test?")
def test_library_Colletion_modeUpdate_hide(collection):
collection.modeUpdate(mode="hide")
collection.reload()
assert collection.collectionMode == "0"
def test_library_Collection_modeUpdate(collection):
mode_dict = {"default": "-2", "hide": "0", "hideItems": "1", "showItems": "2"}
for key, value in mode_dict.items():
collection.modeUpdate(key)
collection.reload()
assert collection.collectionMode == value
#@pytest.mark.skip(reason="broken test?")
def test_library_Colletion_modeUpdate_default(collection):
collection.modeUpdate(mode="default")
collection.reload()
assert collection.collectionMode == "-2"
#@pytest.mark.skip(reason="broken test?")
def test_library_Colletion_modeUpdate_hideItems(collection):
collection.modeUpdate(mode="hideItems")
collection.reload()
assert collection.collectionMode == "1"
#@pytest.mark.skip(reason="broken test?")
def test_library_Colletion_modeUpdate_showItems(collection):
collection.modeUpdate(mode="showItems")
collection.reload()
assert collection.collectionMode == "2"
#@pytest.mark.skip(reason="broken test?")
def test_library_Colletion_sortAlpha(collection):
collection.sortUpdate(sort="alpha")
collection.reload()
assert collection.collectionSort == "1"
@pytest.mark.skip(reason="broken test?")
def test_library_Colletion_sortRelease(collection):
collection.sortUpdate(sort="release")
collection.reload()
assert collection.collectionSort == "0"
@pytest.mark.skip(reason="broken test?")
def test_search_with_apostrophe(plex):
show_title = "Marvel's Daredevil"
result_root = plex.search(show_title)
result_shows = plex.library.section("TV Shows").search(show_title)
def test_search_with_weird_a(plex):
ep_title = "Coup de Grâce"
result_root = plex.search(ep_title)
result_shows = plex.library.section("TV Shows").searchEpisodes(title=ep_title)
assert result_root
assert result_shows
assert result_root == result_shows

View file

@ -276,6 +276,7 @@ def test_server_downloadDatabases(tmpdir, plex):
plex.downloadDatabases(savepath=str(tmpdir), unpack=True)
assert len(tmpdir.listdir()) > 1
def test_server_allowMediaDeletion(account):
plex = PlexServer(utils.SERVER_BASEURL, account.authenticationToken)
# Check server current allowMediaDeletion setting

View file

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import os
from datetime import datetime
from time import sleep
@ -12,12 +13,14 @@ def test_video_Movie(movies, movie):
movie2 = movies.get(movie.title)
assert movie2.title == movie.title
def test_video_Movie_attributeerror(movie):
with pytest.raises(AttributeError):
movie.asshat
def test_video_ne(movies):
assert len(movies.fetchItems('/library/sections/1/all', title__ne='Sintel')) == 3
assert len(movies.fetchItems('/library/sections/%s/all' % movies.key, title__ne='Sintel')) == 3
def test_video_Movie_delete(movie, patched_http_call):
@ -86,13 +89,16 @@ def test_video_Movie_download(monkeydownload, tmpdir, movie):
def test_video_Movie_subtitlestreams(movie):
assert not movie.subtitleStreams()
def test_video_Episode_subtitlestreams(episode):
assert not episode.subtitleStreams()
def test_video_Movie_upload_select_remove_subtitle(movie, subtitle):
import os
filepath = os.path.realpath(subtitle.name)
movie.uploadSubtitles(filepath)
movie.reload()
subtitles = [sub.title for sub in movie.subtitleStreams()]
subname = subtitle.name.rsplit('.', 1)[0]
assert subname in subtitles
@ -100,16 +106,21 @@ def test_video_Movie_upload_select_remove_subtitle(movie, subtitle):
subtitleSelection = movie.subtitleStreams()[0]
parts = [part for part in movie.iterParts()]
parts[0].setDefaultSubtitleStream(subtitleSelection)
movie.reload()
subtitleSelection = movie.subtitleStreams()[0]
assert subtitleSelection.selected
movie.removeSubtitles(streamTitle=subname)
movie.reload()
subtitles = [sub.title for sub in movie.subtitleStreams()]
assert subname not in subtitles
if subtitle:
try:
os.remove(filepath)
except:
pass
def test_video_Movie_attrs(movies):
movie = movies.get('Sita Sings the Blues')