def test_save(self): self.subject.add(MediaInfo()) self.subject.add(MediaInfo()) self.subject.save() self.assertEqual(len(self.subject.items()), 2)
def test_find_video(self): Storage.add(self.subject, MediaInfo(path='path1')) Storage.add(self.subject, MediaInfo(path='path2')) search_item = MediaInfo(path='path1') self.assertEqual(self.subject.find(search_item)['path'], 'path1')
def test_load(self): self.subject.load_storage = lambda : \ [MediaInfo(), MediaInfo()] self.subject.load() self.assertEqual(len(self.subject.items()), 2)
def test_save(self): self.subject.add(MediaInfo()) self.subject.add(MediaInfo()) self.subject.save_storage = lambda(items): \ self.assertEqual(len(items), 2) self.subject.save()
def test_find_season_with_correct_season_attribute(self): Storage.add(self.subject, MediaInfo(type='season', path='path3', season='season1')) Storage.add(self.subject, MediaInfo(type='season', path='path4', season='season2')) search_item = MediaInfo(type='season', path='path4', season='season2') self.assertEqual(self.subject.find(search_item)['path'], 'path4')
def test_find_season_with_wrong_season_attribute(self): Storage.add(self.subject, MediaInfo(type='season', path='path3', season='season1')) Storage.add(self.subject, MediaInfo(type='season', path='path4', season='season2')) search_item = MediaInfo(type='season', path='path1', season='season3') self.assertEqual(self.subject.find(search_item), None)
def test_load(self): data = [MediaInfo(), MediaInfo()] open(self.subject.file_name, "w").write(json.dumps(data)) self.subject.load() self.assertEqual(len(self.subject.items()), 2) os.remove(self.subject.file_name)
def test_load(self): self.subject.add(MediaInfo(path='path1')) self.subject.add(MediaInfo(path='path2')) self.subject.save() self.subject.load() self.assertEqual(len(self.subject.items()), 2) os.remove(self.subject.file_name)
def test_add_no_repeat(self): item = MediaInfo(path='path1') self.subject.add(item) self.subject.add(item) self.assertEqual(len(self.subject.items()), 1)
def HandleSerie(operation=None, **params): oc = ObjectContainer(title1=unicode(params['name'])) media_info = MediaInfo(**params) service.queue.handle_bookmark_operation(operation, media_info) response = service.get_seasons(params['id']) for item in response: season_number = item['name'][len("Season"):].strip() new_params = { 'type': 'season', 'id': item['path'], 'serieName': params['name'], 'name': item['name'], 'thumb': params['thumb'], 'season': season_number, } oc.add( DirectoryObject(key=Callback(HandleSeason, **new_params), title=item['name'], thumb=params['thumb'])) service.queue.append_bookmark_controls(oc, HandleSerie, media_info) return oc
def HandleSelection(page=1, operation=None, **params): oc = ObjectContainer(title2=unicode(params['name'])) media_info = MediaInfo(**params) service.queue.handle_bookmark_operation(operation, media_info) response = service.get_selection(params['id'], page=page) for item in response['movies']: new_params = { 'type': 'movie', 'id': item['path'], 'name': item['name'], 'thumb': item['thumb'], } oc.add(DirectoryObject( key=Callback(HandleMovie, **new_params), title=plex_util.sanitize(item['name']), thumb=plex_util.get_thumb(item['thumb']) )) service.queue.append_bookmark_controls(oc, HandleSelection, media_info) pagination.append_controls(oc, response, page=page, callback=HandleSelection, **media_info) return oc
def HandleDoubleAlbum(operation=None, **params): oc = ObjectContainer(title2=unicode(params['name'])) media_info = MediaInfo(**params) service.queue.handle_bookmark_operation(operation, media_info) response = service.get_albums(limit=util.get_elements_per_page(), year__gte=util.get_start_music_year(), year__lte=util.get_end_music_year(), **service.filter_request_params(params)) for media in response['objects']: id = media['id'] name = media['title'] thumb = media['thumbnail'] new_params = { 'type': 'album', 'album': id, 'id': id, 'name': name, 'thumb': thumb } key = Callback(HandleTracks, **new_params) oc.add(DirectoryObject(key=key, title=unicode(name), thumb=thumb)) service.queue.append_bookmark_controls(oc, HandleDoubleAlbum, media_info) return oc
def HandleSeason(operation=None, container=False, **params): oc = ObjectContainer(title1=unicode(params['name'])) media_info = MediaInfo(**params) service.queue.handle_bookmark_operation(operation, media_info) response = service.get_season(params['id']) for item in response: episode_name = service.simplify_name(item['name']) episode_number = episode_name[len("Episode"):].strip() new_params = { 'type': 'episode', 'id': item['path'], 'serieName': params['serieName'], 'name': episode_name, 'thumb': params['thumb'], 'season': params['season'], 'episodeNumber': episode_number } oc.add( DirectoryObject(key=Callback(HandleEpisode, **new_params), title=episode_name)) if str(container) == 'False': history.push_to_history(Data, media_info) service.queue.append_bookmark_controls(oc, HandleSeason, media_info) return oc
def test_find_episode_with_season_attribute_no_episode_attribute(self): Storage.add( self.subject, MediaInfo(type='episode', path='path5', season='season3', episode="episode1")) Storage.add( self.subject, MediaInfo(type='episode', path='path6', season='season4', episode="episode2")) search_item = MediaInfo(type='episode', path='path5', season='season3') self.assertEqual(self.subject.find(search_item), None)
def test_remove(self): item = MediaInfo(path='path1') self.subject.add(item) self.assertEqual(len(self.subject.items()), 1) self.subject.remove(item) self.assertEqual(len(self.subject.items()), 0)
def HandleEpisode(operation=None, container=False, **params): oc = ObjectContainer(title2=unicode(L(params['name'])), user_agent='Plex') media_info = MediaInfo(**params) if 'season' in media_info: season = media_info['season'] else: season = None if 'episode' in media_info: episode = media_info['episode'] else: episode = None if season and int(season) > 0 and episode: urls = json.loads(urllib.unquote_plus(media_info['id'])) else: urls = service.get_urls(path=media_info['id']) if len(urls) == 0: return plex_util.no_contents() else: service.queue.handle_bookmark_operation(operation, media_info) metadata_object = FlowBuilder.build_metadata_object( media_type=media_info['type'], title=media_info['name']) metadata_object.key = Callback(HandleEpisode, container=True, **media_info) metadata_object.rating_key = unicode(media_info['name']) metadata_object.thumb = media_info['thumb'] metadata_object.title = media_info['name'] for url in urls: metadata = service.get_metadata(url) if 'height' in metadata: metadata["video_resolution"] = metadata['height'] media_object = FlowBuilder.build_media_object( Callback(common_routes.PlayAudio, url=url), metadata) metadata_object.items.append(media_object) oc.add(metadata_object) if str(container) == 'False': history.push_to_history(Data, media_info) service.queue.append_bookmark_controls(oc, HandleEpisode, media_info) return oc
def HandleTracks(operation=None, page=1, **params): media_info = MediaInfo(**params) if 'album' in params: media_info['id'] = params['album'] service.queue.handle_bookmark_operation(operation, media_info) oc = ObjectContainer(title2=unicode(params['name'])) page = int(page) limit = util.get_elements_per_page() offset = (page - 1) * limit response = service.get_tracks(limit=util.get_elements_per_page(), offset=offset, **service.filter_request_params(params)) for media in response['objects']: title = media['title'] file = media['file'] if media['album']['artist']: artist = media['album']['artist']['title'] else: artist = '' format = 'mp3' url = service.BASE_URL + file bitrate = "128" new_params = { 'type': 'track', 'id': url, 'name': title, 'thumb': params['thumb'], 'artist': artist, 'format': format, 'bitrate': bitrate } oc.add(HandleTrack(**new_params)) service.queue.append_bookmark_controls(oc, HandleTracks, media_info) service.add_pagination_to_response(response, page, util.get_elements_per_page()) pagination.append_controls(oc, response['data'], callback=HandleTracks, page=page, **params) return oc
def HandleSerieVersion(version, operation=None, selected_season=None, selected_episode=None, **params): oc = ObjectContainer(title2=unicode(params['title'])) media_info = MediaInfo(**params) media_info['version'] = version service.queue.handle_bookmark_operation(operation, media_info) movie_documents = service.get_movie_documents(params['id']) movie_document = movie_documents[version - 1]['movie_document'] if selected_season: addSelectedSeason(oc, movie_document, selected_season, selected_episode, **params) serial_info = service.get_serial_info(movie_document) for season in sorted(serial_info['seasons'].keys()): if not selected_season or selected_season and selected_season != int( season): season_name = serial_info['seasons'][season] rating_key = service.get_episode_url(params['id'], season, 0) # source_title = unicode(L('Title')) new_params = { 'type': 'season', 'id': params['id'], 'serieName': params['name'], 'name': season_name, 'thumb': params['thumb'], 'season': season, 'version': version } oc.add( SeasonObject( key=Callback(HandleSeason, **new_params), title=unicode(season_name), rating_key=rating_key, index=int(season), thumb=params['thumb'], # source_title=source_title, # summary=data['summary'] )) service.queue.append_bookmark_controls(oc, HandleSerieVersion, media_info) return oc
def HandleArtist(operation=None, **params): oc = ObjectContainer(title2=unicode(L("Artist") + " " + params['name'])) media_info = MediaInfo(**params) service.queue.handle_bookmark_operation(operation, media_info) response1 = service.get_albums(artists=params['id'], limit=1, offset=0, year__gte=util.get_start_music_year(), year__lte=util.get_end_music_year()) count1 = int(response1['meta']['total_count']) if count1 > 0: new_params = { 'title': unicode(L('Albums')) + " " + params['name'], 'artists': params['id'] } oc.add( DirectoryObject( key=Callback(HandleAlbums, **new_params), title=unicode(L('Albums') + ' (' + str(count1) + ')'), thumb=media_info['thumb'])) response2 = service.get_tracks(artists=params['id'], limit=1, offset=0, year__gte=util.get_start_music_year(), year__lte=util.get_end_music_year()) count2 = int(response2['meta']['total_count']) if count2 > 0: new_params = { 'type': 'tracks', 'artists': params['id'], 'id': params['id'], 'name': L('Audio Tracks') + " " + params['name'], 'thumb': params['thumb'] } oc.add( DirectoryObject(key=Callback(HandleTracks, **new_params), title=unicode( L('Audio Tracks') + ' (' + response2['meta']['total_count'] + ')'), thumb=params['thumb'])) service.queue.append_bookmark_controls(oc, HandleArtist, media_info) return oc
def HandleTracks(name, playlist_url): oc = ObjectContainer(title2=unicode(L(name))) serie_info = service.get_serie_info(playlist_url)[0] oc.title2 = unicode(serie_info['comment']) for item in serie_info['playlist']: url = item['file'][0] name = item['comment'] format = "mp3" new_params = MediaInfo(type='track', id=url, name=name, format=format) oc.add(HandleTrack(**new_params)) return oc
def HandleMovie(operation=None, container=False, **params): oc = ObjectContainer(title1=unicode(params['name'])) media_info = MediaInfo(**params) service.queue.handle_bookmark_operation(operation, media_info) response = service.get_movie(params['id']) if response['thumb']: thumb = response['thumb'] else: thumb = params['thumb'] name = response['name'] urls = response['urls'] urls_length = len(urls) for index, url in enumerate(urls): if urls_length > 1: url_name = str(index + 1) + "-" + name else: url_name = name oc.add( VideoClipObject(url=url, thumb=plex_util.get_thumb(thumb), title=unicode(L(url_name)))) #oc.add(MetadataObjectForURL2(media_info=media_info, url_items=url_items, handler=HandleMovie, player=PlayVideo)) # if 'trailer_url' in response: # oc.add(VideoClipObject( # url=response['trailer_url'], # thumb=plex_util.get_thumb(thumb), # title=unicode(L("Watch Trailer")) # )) if str(container) == 'False': history.push_to_history(Data, media_info) service.queue.append_bookmark_controls(oc, HandleMovie, media_info) return oc
def HandleSeason(operation=None, container=False, **params): oc = ObjectContainer(title2=unicode(params['name'])) media_info = MediaInfo(**params) service.queue.handle_bookmark_operation(operation, media_info) if not params['episodes']: playlist_url = service.get_serie_playlist_url(params['id']) serie_info = service.get_serie_info(playlist_url) list = serie_info[int(params['season']) - 1]['playlist'] else: list = json.loads(params['episodes']) for index, episode in enumerate(list): episode_name = episode['comment'].replace('<br>', ' ') thumb = params['thumb'] url = episode['file'] new_params = { 'type': 'episode', 'id': json.dumps(url), 'name': episode_name, 'serieName': params['serieName'], 'thumb': thumb, 'season': params['season'], 'episode': episode, 'episodeNumber': index + 1 } key = Callback(HandleEpisode, container=container, **new_params) oc.add( DirectoryObject(key=key, title=unicode(episode_name), thumb=plex_util.get_thumb(thumb))) if str(container) == 'False': history.push_to_history(Data, media_info) service.queue.append_bookmark_controls(oc, HandleSeason, media_info) return oc
def HandleTrack(container=False, **params): media_info = MediaInfo(**params) if 'm4a' in media_info['format']: audio_container = Container.MP4 audio_codec = AudioCodec.AAC else: audio_container = Container.MP3 audio_codec = AudioCodec.MP3 if 'bitrate' in media_info: bitrate = media_info['bitrate'] else: bitrate = 0 if 'duration' in media_info: duration = media_info['duration'] else: duration = 0 url_items = [{ "url": media_info['id'], "config": { "container": audio_container, "audio_codec": audio_codec, "bitrate": bitrate, "duration": duration } }] track = AudioMetadataObjectForURL(media_info, url_items=url_items, player=PlayAudio) if container: oc = ObjectContainer(title2=unicode(media_info['name'])) oc.add(track) return oc else: return track
def HandleGenre(operation=None, **params): media_info = MediaInfo(**params) service.queue.handle_bookmark_operation(operation, media_info) oc = ObjectContainer(title2=unicode(L(params['name']))) key = Callback(HandleAlbums, title=params['name'], genre__in=params['genre__in']) oc.add(DirectoryObject(key=key, title=unicode(params['name']))) service.queue.append_bookmark_controls(oc, HandleGenre, media_info) oc.add( InputDirectoryObject(key=Callback(HandleSearch), title=unicode(L("Search Music")), thumb=R(SEARCH_ICON))) return oc
def HandleTrack(container=False, **params): media_info = MediaInfo(**params) url = media_info['id'] metadata_object = FlowBuilder.build_metadata_object(media_type=media_info['type'], title=media_info['name']) metadata_object.key = Callback(HandleTrack, container=True, **media_info) metadata_object.rating_key = unicode(media_info['name']) metadata_object.title = unicode(media_info['name']) metadata_object.duration = int(media_info['duration']) if 'thumb' in media_info: metadata_object.artist = media_info['thumb'] if 'artist' in media_info: metadata_object.artist = media_info['artist'] if 'm4a' in media_info['format']: format = 'm4a' else: format = 'mp3' metadata = FlowBuilder.get_metadata(format) metadata["bitrate"] = media_info['bitrate'] metadata["duration"] = media_info['duration'] media_object = FlowBuilder.build_media_object(Callback(common_routes.PlayAudio, url=url), metadata) metadata_object.items.append(media_object) if container: oc = ObjectContainer(title2=unicode(params['name'])) oc.add(metadata_object) return oc else: return metadata_object
def HandleSeasonVersion(version, operation=None, container=False, **params): version = int(version) if 'thumb' in params: thumb = params['thumb'] else: thumb = None oc = ObjectContainer(title2=unicode(params['name'])) media_info = MediaInfo(**params) service.queue.handle_bookmark_operation(operation, media_info) movie_documents = service.get_movie_documents(params['id'], params['season'], 1) movie_document = movie_documents[version - 1]['movie_document'] serial_info = service.get_serial_info(movie_document) for index, episode in enumerate(sorted(serial_info['episodes'].keys())): episode_name = serial_info['episodes'][episode] new_params = { 'type': 'episode', 'id': params['id'], 'serieName': params['serieName'], 'name': episode_name, 'thumb': thumb, 'season': params['season'], 'episode': episode, 'episodeNumber': index + 1 } key = Callback(HandleMovie, container=container, **new_params) oc.add(DirectoryObject(key=key, title=unicode(episode_name))) service.queue.append_bookmark_controls(oc, HandleSeasonVersion, media_info) return oc
def HandleTracks(**params): oc = ObjectContainer(title2=unicode(params['name'])) for track in json.loads(params['tracks']): url = track['url'] name = track['name'] format = "mp3" bitrate = track['bitrate'] duration = track['duration'] new_params = MediaInfo( type='track', id=url, name=name, artist=params['artist'], format=format, bitrate=bitrate, duration=duration ) oc.add(HandleTrack(**new_params)) return oc
def HandleCollection(operation=None, **params): media_info = MediaInfo(**params) service.queue.handle_bookmark_operation(operation, media_info) oc = ObjectContainer(title2=unicode(L(params['name']))) new_params = { 'type': 'tracks', 'collection__id': params['collection__id'], 'id': params['collection__id'], 'name': params['name'], 'thumb': params['thumb'] } key = Callback(HandleTracks, **new_params) oc.add( DirectoryObject(key=key, title=unicode(params['name']), thumb=params['thumb'])) service.queue.append_bookmarks_controls(oc, HandleCollection, media_info) return oc
def HandleSoundtrack(operation=None, container=False, **params): oc = ObjectContainer(title2=unicode(params['name'])) media_info = MediaInfo(**params) service.queue.handle_bookmark_operation(operation, media_info) albums = service.get_albums(params['id']) albums_count = len(albums) for index, album in enumerate(albums): prefix = str(index + 1) + ". " if albums_count > 1 else "" album_name = prefix + album['name'] thumb = album['thumb'] artist = album['composer'] tracks = album['tracks'] new_params = { 'type': 'tracks', 'name': album_name, 'artist': artist, 'tracks': json.dumps(tracks) } oc.add(DirectoryObject( key=Callback(HandleTracks, **new_params), title=plex_util.sanitize(album_name), thumb=plex_util.get_thumb(thumb) )) if str(container) == 'False': history.push_to_history(Data, media_info) service.queue.append_bookmark_controls(oc, HandleSoundtrack, media_info) return oc
def HandleSerie(operation=None, **params): oc = ObjectContainer(title2=unicode(params['name'])) media_info = MediaInfo(**params) service.queue.handle_bookmark_operation(operation, media_info) playlist_url = service.get_serie_playlist_url(params['id']) serie_info = service.get_serie_info(playlist_url) for index, item in enumerate(serie_info): season = index + 1 season_name = item['comment'].replace('<b>', '').replace('</b>', '') episodes = item['playlist'] rating_key = service.get_episode_url(params['id'], season, 0) new_params = { 'type': 'season', 'id': params['id'], 'serieName': params['name'], 'name': season_name, 'thumb': params['thumb'], 'season': season, 'episodes': json.dumps(episodes) } oc.add( SeasonObject(key=Callback(HandleSeason, **new_params), rating_key=rating_key, title=plex_util.sanitize(season_name), index=int(season), thumb=plex_util.get_thumb(params['thumb']))) service.queue.append_bookmark_controls(oc, HandleSerie, media_info) return oc