Changeset 8b942de2822ae69316152244f6c6d807e2bd4bd3
- Timestamp:
- 12/02/07 21:04:02
(1 year ago)
- Author:
- Jason Michalski <armooo@armooo.net>
- git-committer:
- Jason Michalski <armooo@armooo.net> 1196651042 -0600
- git-parent:
[3854c6a75c597ac0fcdbc323a36189204a2f3831]
- git-author:
- Jason Michalski <armooo@armooo.net> 1196537632 -0600
- Message:
Updated base plugin to use full paths and support random play
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r214a148 |
r8b942de |
|
| 1 | | import os, shutil, re |
|---|
| | 1 | import os, shutil, re, random |
|---|
| 2 | 2 | from urllib import unquote, unquote_plus |
|---|
| 3 | 3 | from urlparse import urlparse |
|---|
| … | … | |
| 32 | 32 | shutil.copyfileobj(f, handler.wfile) |
|---|
| 33 | 33 | |
|---|
| | 34 | def get_local_base_path(self, handler, query): |
|---|
| | 35 | |
|---|
| | 36 | subcname = query['Container'][0] |
|---|
| | 37 | container = handler.server.containers[subcname.split('/')[0]] |
|---|
| | 38 | |
|---|
| | 39 | return container['path'] |
|---|
| | 40 | |
|---|
| 34 | 41 | def get_local_path(self, handler, query): |
|---|
| 35 | 42 | |
|---|
| … | … | |
| 46 | 53 | def get_files(self, handler, query, filterFunction=None): |
|---|
| 47 | 54 | subcname = query['Container'][0] |
|---|
| | 55 | cname = subcname.split('/')[0] |
|---|
| 48 | 56 | path = self.get_local_path(handler, query) |
|---|
| 49 | 57 | |
|---|
| 50 | | files = os.listdir(path) |
|---|
| | 58 | files = [ os.path.join(path, file) for file in os.listdir(path)] |
|---|
| | 59 | if query.get('Recurse',['No'])[0] == 'Yes': |
|---|
| | 60 | for file in files: |
|---|
| | 61 | if os.path.isdir(file): |
|---|
| | 62 | for new_file in os.listdir(file): |
|---|
| | 63 | files.append( os.path.join(file, new_file) ) |
|---|
| | 64 | |
|---|
| | 65 | file_type = query['Filter'][0] |
|---|
| 51 | 66 | if filterFunction: |
|---|
| 52 | | files = filter(filterFunction, files) |
|---|
| | 67 | files = [file for file in files if filterFunction(file, file_type)] |
|---|
| | 68 | |
|---|
| 53 | 69 | totalFiles = len(files) |
|---|
| 54 | 70 | |
|---|
| … | … | |
| 88 | 104 | return cmp(xStr, yStr) |
|---|
| 89 | 105 | |
|---|
| 90 | | files.sort(dir_sort) |
|---|
| | 106 | if query.get('SortOrder',['Normal'])[0] == 'Random': |
|---|
| | 107 | seed = query.get('RandomSeed', ['1'])[0] |
|---|
| | 108 | random.seed(seed) |
|---|
| | 109 | random.shuffle(files) |
|---|
| | 110 | else: |
|---|
| | 111 | files.sort(dir_sort) |
|---|
| | 112 | |
|---|
| | 113 | local_base_path = self.get_local_base_path(handler, query) |
|---|
| 91 | 114 | |
|---|
| 92 | 115 | index = 0 |
|---|
| … | … | |
| 97 | 120 | if query.has_key('AnchorItem'): |
|---|
| 98 | 121 | anchor = unquote(query['AnchorItem'][0]) |
|---|
| 99 | | for i in range(len(files)): |
|---|
| 100 | | if os.path.isdir(os.path.join(path,files[i])): |
|---|
| 101 | | file_url = '/TiVoConnect?Command=QueryContainer&Container=' + subcname + '/' + files[i] |
|---|
| | 122 | for file, i in zip(files, range(len(files))): |
|---|
| | 123 | file_name = file.replace(local_base_path, '') |
|---|
| | 124 | |
|---|
| | 125 | if os.path.isdir(os.path.join(file)): |
|---|
| | 126 | file_url = '/TiVoConnect?Command=QueryContainer&Container=' + cname + file_name |
|---|
| 102 | 127 | else: |
|---|
| 103 | | file_url = '/' + subcname + '/' + files[i] |
|---|
| | 128 | file_url = '/' + cname + file_name |
|---|
| | 129 | |
|---|
| 104 | 130 | if file_url == anchor: |
|---|
| 105 | 131 | if count > 0: |
|---|
| … | … | |
| 110 | 136 | index = i |
|---|
| 111 | 137 | break |
|---|
| | 138 | |
|---|
| 112 | 139 | if query.has_key('AnchorOffset'): |
|---|
| 113 | 140 | index = index + int(query['AnchorOffset'][0]) |
|---|
| 114 | | |
|---|
| | 141 | |
|---|
| 115 | 142 | #foward count |
|---|
| 116 | 143 | if index < index + count: |
|---|
| … | … | |
| 119 | 146 | #backwards count |
|---|
| 120 | 147 | else: |
|---|
| 121 | | print 'index, count', index, count |
|---|
| 122 | | print index + count |
|---|
| 123 | 148 | #off the start of the list |
|---|
| 124 | 149 | if index + count < 0: |
|---|
| 125 | | print 0 - (index + count) |
|---|
| 126 | 150 | index += 0 - (index + count) |
|---|
| 127 | | print index + count |
|---|
| 128 | 151 | files = files[index + count:index] |
|---|
| 129 | 152 | return files, totalFiles, index + count |
|---|