This commit is contained in:
Hellowlol 2017-02-18 01:51:06 +01:00
parent 881089468e
commit c7c04d2a42
4 changed files with 84 additions and 25 deletions

View file

@ -66,6 +66,7 @@ class MediaPart(PlexObject):
duration (int): Length of this media part in milliseconds.
file (str): Path to this file on disk (ex: /media/Movies/Cars.(2006)/Cars.cd2.avi)
id (int): Unique ID of this media part.
indexes (str, None): None or SD.
key (str): Key used to access this media part (ex: /library/parts/46618/1389985872/file.avi).
size (int): Size of this file in bytes (ex: 733884416).
streams (list<:class:`~plexapi.media.MediaPartStream`>): List of streams in this media part.
@ -79,6 +80,7 @@ class MediaPart(PlexObject):
self.duration = cast(int, data.attrib.get('duration'))
self.file = data.attrib.get('file')
self.id = cast(int, data.attrib.get('id'))
self.indexes = data.attrib.get('indexes')
self.key = data.attrib.get('key')
self.size = cast(int, data.attrib.get('size'))
self.streams = self._buildStreams(data)

View file

@ -1,7 +1,13 @@
# -*- coding: utf-8 -*-
import logging, os, requests
import logging
import os
from datetime import datetime
import time
from threading import Thread
import requests
from plexapi.compat import quote, string_type
from plexapi.exceptions import NotFound
@ -185,6 +191,49 @@ def toList(value, itemcast=None, delim=','):
return [itemcast(item) for item in value.split(delim) if item != '']
def get_session_images(server, filename=None, height=150, width=150, opacity=100, saturation=100):
"""Simple helper to download a bif image or thumb.url from plex.server.sessions. Returns a dict.
Parameters:
filename (str): default to None,
height (int): Height of the image.
width (int): width of the image.
opacity (int): Opacity of the resulting image (possibly deprecated).
saturation (int): Saturating of the resulting image.
Returns:
{'hellowlol': {'fp': 'path_to_file'
'url', 'http://....'}
}
"""
info = {}
for media in server.sessions():
url = None
for part in media.iterParts():
if media.thumb:
url = media.thumb
# Always use bif images if available.
if part.indexes:
url = '/library/parts/%s/indexes/sd/%s' % (part.id, media.viewOffset)
if url:
if filename is None:
filename = 'session_transcode_%s_%s_%s' % (media.usernames[0], media._prettyfilename(),
int(time.time()))
url = server.transcodeImage(url, height=height, width=width,
opacity=opacity, saturation=saturation)
dfp = download(url, filename=filename)
info['username'] = {'fp': dfp,
'url': url}
return info
def download(url, filename=None, savepath=None, session=None, chunksize=4024, mocked=False):
""" Helper to download a thumb, videofile or other media item. Returns the local
path to the downloaded file.

View file

@ -146,6 +146,10 @@ class Movie(Video, Playable):
"""
return [p.file for p in self.iterParts() if p]
def _prettyfilename(self):
# This is just for compat.
return self.title
def download(self, savepath=None, keep_orginal_name=False, **kwargs):
""" Download video files to specified directory.

View file

@ -15,6 +15,10 @@ def _test_utils_threaded():
pass
def _download_session_images():
pass # TODO Add this when we got clients fixed.
def test_utils_searchType():
st = utils.searchType('movie')
assert st == 1