Browse Source

Merge branch 'feature/encoding' of Zykino/prismedia into develop

fix #12, thanks Zykino!
LecygneNoir 6 months ago
parent
commit
5907859066
3 changed files with 25 additions and 19 deletions
  1. 5
    4
      README.md
  2. 14
    4
      lib/utils.py
  3. 6
    11
      prismedia_upload.py

+ 5
- 4
README.md View File

@@ -98,7 +98,8 @@ Options:
98 98
   --disable-comments  Disable comments (Peertube only as YT API does not support) (default: comments are enabled)
99 99
   --nsfw  Set the video as No Safe For Work (Peertube only as YT API does not support) (default: video is safe)
100 100
   --nfo=STRING  Configure a specific nfo file to set options for the video.
101
-                By default Prismedia search a .txt based on video name
101
+                By default Prismedia search a .txt based on the video name and will
102
+                decode the file as UTF-8 (so make sure your nfo file is UTF-8 encoded)
102 103
                 See nfo_example.txt for more details
103 104
   --platform=STRING  List of platform(s) to upload to, comma separated.
104 105
                      Supported platforms are youtube and peertube (default is both)
@@ -149,8 +150,8 @@ Languages:
149 150
   - [x] set default language
150 151
   - [x] thumbnail/preview
151 152
   - [x] multiple lines description (see [issue 4](https://git.lecygnenoir.info/LecygneNoir/prismedia/issues/4))
152
-  - [x] add videos to playlist for Peertube
153
-  - [x] add videos to playlist for Youtube
153
+  - [x] add videos to playlist
154
+  - [x] create playlist
154 155
 - [x] Use a config file (NFO) file to retrieve videos arguments
155 156
 - [x] Allow to choose peertube or youtube upload (to resume failed upload for example)
156 157
 - [x] Add publishAt option to plan your videos
@@ -163,4 +164,4 @@ Languages:
163 164
 If your server uses peertube before 1.0.0-beta4, use the version inside tag 1.0.0-beta3!
164 165
 
165 166
 ## Sources
166
-inspired by [peeror](https://git.rigelk.eu/rigelk/peeror) and [youtube-upload](https://github.com/tokland/youtube-upload)
167
+inspired by [peeror](https://git.rigelk.eu/rigelk/peeror) and [youtube-upload](https://github.com/tokland/youtube-upload)

+ 14
- 4
lib/utils.py View File

@@ -123,7 +123,6 @@ def searchThumbnail(options):
123 123
             options['--thumbnail'] = video_directory + video_file + ".jpeg"
124 124
     return options
125 125
 
126
-
127 126
 # return the nfo as a RawConfigParser object
128 127
 def loadNFO(options):
129 128
     video_directory = dirname(options.get('--file')) + "/"
@@ -168,7 +167,6 @@ def loadNFO(options):
168 167
     logging.info("No suitable NFO found, skipping.")
169 168
     return False
170 169
 
171
-
172 170
 def parseNFO(options):
173 171
     nfo = loadNFO(options)
174 172
     if nfo:
@@ -189,11 +187,9 @@ def parseNFO(options):
189 187
                 exit(1)
190 188
     return options
191 189
 
192
-
193 190
 def upcaseFirstLetter(s):
194 191
     return s[0].upper() + s[1:]
195 192
 
196
-
197 193
 def cleanString(toclean):
198 194
     toclean = toclean.split(' ')
199 195
     cleaned = ''
@@ -208,3 +204,17 @@ def cleanString(toclean):
208 204
         cleaned = cleaned + strtoclean
209 205
 
210 206
     return cleaned
207
+
208
+def decodeArgumentStrings(options, encoding):
209
+    # Python crash when decoding from UTF-8 to UTF-8, so we prevent this
210
+    if "utf-8" == encoding.lower():
211
+        return;
212
+
213
+    if options["--name"] is not None:
214
+        options["--name"] = options["--name"].decode(encoding)
215
+
216
+    if options["--description"] is not None:
217
+        options["--description"] = options["--description"].decode(encoding)
218
+
219
+    if options["--tags"] is not None:
220
+        options["--tags"] = options["--tags"].decode(encoding)

+ 6
- 11
prismedia_upload.py View File

@@ -64,12 +64,12 @@ Languages:
64 64
 from os.path import dirname, realpath
65 65
 import sys
66 66
 import datetime
67
+import locale
67 68
 import logging
68 69
 logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO)
69 70
 
70 71
 from docopt import docopt
71 72
 
72
-
73 73
 # Allows a relative import from the parent folder
74 74
 sys.path.insert(0, dirname(realpath(__file__)) + "/lib")
75 75
 
@@ -110,7 +110,6 @@ VALID_LANGUAGES = ('arabic', 'english', 'french',
110 110
                    'japanese', 'korean', 'mandarin',
111 111
                    'portuguese', 'punjabi', 'russian', 'spanish')
112 112
 
113
-
114 113
 def validateVideo(path):
115 114
     supported_types = ['video/mp4']
116 115
     if magic.from_file(path, mime=True) in supported_types:
@@ -118,21 +117,18 @@ def validateVideo(path):
118 117
     else:
119 118
         return False
120 119
 
121
-
122 120
 def validateCategory(category):
123 121
     if category.lower() in VALID_CATEGORIES:
124 122
         return True
125 123
     else:
126 124
         return False
127 125
 
128
-
129 126
 def validatePrivacy(privacy):
130 127
     if privacy.lower() in VALID_PRIVACY_STATUSES:
131 128
         return True
132 129
     else:
133 130
         return False
134 131
 
135
-
136 132
 def validatePlatform(platform):
137 133
     for plfrm in platform.split(','):
138 134
         if plfrm.lower().replace(" ", "") not in VALID_PLATFORM:
@@ -140,14 +136,12 @@ def validatePlatform(platform):
140 136
 
141 137
     return True
142 138
 
143
-
144 139
 def validateLanguage(language):
145 140
     if language.lower() in VALID_LANGUAGES:
146 141
         return True
147 142
     else:
148 143
         return False
149 144
 
150
-
151 145
 def validatePublish(publish):
152 146
     # Check date format and if date is future
153 147
     try:
@@ -173,17 +167,17 @@ if __name__ == '__main__':
173 167
     schema = Schema({
174 168
         '--file': And(str, validateVideo, error='file is not supported, please use mp4'),
175 169
         Optional('--name'): Or(None, And(
176
-                                str,
170
+                                basestring,
177 171
                                 lambda x: not x.isdigit(),
178 172
                                 error="The video name should be a string")
179 173
                                ),
180 174
         Optional('--description'): Or(None, And(
181
-                                        str,
175
+                                        basestring,
182 176
                                         lambda x: not x.isdigit(),
183
-                                        error="The video name should be a string")
177
+                                        error="The video description should be a string")
184 178
                                       ),
185 179
         Optional('--tags'): Or(None, And(
186
-                                    str,
180
+                                    basestring,
187 181
                                     lambda x: not x.isdigit(),
188 182
                                     error="Tags should be a string")
189 183
                                ),
@@ -222,6 +216,7 @@ if __name__ == '__main__':
222 216
         '--version': bool
223 217
     })
224 218
 
219
+    utils.decodeArgumentStrings(options, locale.getpreferredencoding())
225 220
     options = utils.parseNFO(options)
226 221
 
227 222
     if not options.get('--thumbnail'):

Loading…
Cancel
Save