Przeglądaj źródła

Import video to pertube from file

Bob Mottram 7 lat temu
rodzic
commit
b8c927a2a6
1 zmienionych plików z 90 dodań i 24 usunięć
  1. 90
    24
      src/freedombone-app-peertube

+ 90
- 24
src/freedombone-app-peertube Wyświetl plik

149
     systemctl restart peertube
149
     systemctl restart peertube
150
 }
150
 }
151
 
151
 
152
+function peertube_import_from_file {
153
+    read_config_param MY_USERNAME
154
+    read_config_param PEERTUBE_DOMAIN_NAME
155
+    read_config_param ONION_ONLY
156
+
157
+    data2=$(mktemp 2>/dev/null)
158
+    dialog --backtitle $"Freedombone Control Panel" \
159
+           --title $"Import Video from file" \
160
+           --form $"Enter your PeerTube login details and video title" 10 65 4 \
161
+           $"Username:" 1 1 "$MY_USERNAME" 1 18 16 15 \
162
+           $"Password:" 2 1 "" 2 18 40 10000 \
163
+           $"Video Title:" 3 1 "" 3 18 40 1000 \
164
+           $"NSFW:" 4 1 $"no" 4 18 4 4 \
165
+           2> "$data2"
166
+    sel=$?
167
+    case $sel in
168
+        1) rm -f "$data2"
169
+           return;;
170
+        255) rm -f "$data2"
171
+             return;;
172
+    esac
173
+    peertubeuser=$(sed -n 1p < "$data2")
174
+    peertubepassword=$(sed -n 2p < "$data2")
175
+    peertubetitle=$(sed -n 3p < "$data2")
176
+    peertubensfw=$(sed -n 4p < "$data2")
177
+    rm -f "$data2"
178
+
179
+    peertubedomain="http://localhost:${PEERTUBE_PORT}"
180
+
181
+    data2=$(mktemp 2>/dev/null)
182
+    dialog --title "Choose the video file (select with spacebar)" --fselect "/home/$MY_USERNAME/" 30 60 2> "$data2"
183
+    selected_file=$(cat "$data2")
184
+    rm -f "$data2"
185
+    if [ ! "$selected_file" ]; then
186
+        return
187
+    fi
188
+    if [[ "$selected_file" != *'.ogv' && "$selected_file" != *'.mp4' && "$selected_file" != *'.webm' ]]; then
189
+        dialog --title $"Import video from file" \
190
+               --msgbox $"The video should be in ogv, mp4 or webm format" 6 75
191
+        return
192
+    fi
193
+
194
+    cd $PEERTUBE_DIR || exit 32468356
195
+    import_script=$PEERTUBE_DIR/dist/server/tools/upload.js
196
+    if [ ! -f $import_script ]; then
197
+        dialog --title $"Import videos" \
198
+               --msgbox $"upload script was not found" 6 75
199
+        return
200
+    fi
201
+
202
+    nsfwstr=
203
+    if [[ "$peertubensfw" == *'y'* || "$peertubensfw" == *'Y'* ]]; then
204
+        nsfwstr='--nsfw'
205
+    fi
206
+
207
+    titlestr=
208
+    if [ "$peertubetitle" ]; then
209
+        titlestr="-n \"$peertubetitle\""
210
+    fi
211
+
212
+    clear
213
+    node $import_script $nsfwstr "$titlestr" -u "$peertubedomain" -U "$peertubeuser" --password "$peertubepassword" -f "$selected_file"
214
+
215
+    dialog --title $"Import video from file" \
216
+           --msgbox $"Video imported from $selected_file" 6 75
217
+}
218
+
152
 function peertube_import_videos {
219
 function peertube_import_videos {
153
     read_config_param MY_USERNAME
220
     read_config_param MY_USERNAME
154
     read_config_param PEERTUBE_DOMAIN_NAME
221
     read_config_param PEERTUBE_DOMAIN_NAME
155
     read_config_param ONION_ONLY
222
     read_config_param ONION_ONLY
156
 
223
 
157
-    data=$(mktemp 2>/dev/null)
224
+    data2=$(mktemp 2>/dev/null)
158
     dialog --backtitle $"Freedombone Control Panel" \
225
     dialog --backtitle $"Freedombone Control Panel" \
159
-           --title $"Import Videos" \
160
-           --form "Enter a channel of video URL for YouTube/Vimeo/Dailymotion" 10 75 4 \
226
+           --title $"Import Videos from legacy sites" \
227
+           --form $"Enter a channel of video URL for YouTube/Vimeo/Dailymotion" 10 75 4 \
161
            $"Username:" 1 1 "$MY_USERNAME" 1 28 16 15 \
228
            $"Username:" 1 1 "$MY_USERNAME" 1 28 16 15 \
162
            $"Password:" 2 1 "" 2 28 40 10000 \
229
            $"Password:" 2 1 "" 2 28 40 10000 \
163
            $"Video/Channel URL:" 3 1 "" 3 28 40 10000 \
230
            $"Video/Channel URL:" 3 1 "" 3 28 40 10000 \
164
-           2> "$data"
231
+           2> "$data2"
165
     sel=$?
232
     sel=$?
166
     case $sel in
233
     case $sel in
167
-        1) rm -f "$data"
234
+        1) rm -f "$data2"
168
            return;;
235
            return;;
169
-        255) rm -f "$data"
236
+        255) rm -f "$data2"
170
              return;;
237
              return;;
171
     esac
238
     esac
172
-    peertubeuser=$(sed -n 1p < "$data")
173
-    peertubepassword=$(sed -n 2p < "$data")
174
-    video_url=$(sed -n 3p < "$data")
175
-    rm -f "$data"
239
+    peertubeuser=$(sed -n 1p < "$data2")
240
+    peertubepassword=$(sed -n 2p < "$data2")
241
+    video_url=$(sed -n 3p < "$data2")
242
+    rm -f "$data2"
176
 
243
 
177
-    peertubedomain="https://$PEERTUBE_DOMAIN_NAME"
178
-    if [[ "$ONION_ONLY" != 'no' ]]; then
179
-        peertubedomain="http://$(cat /var/lib/tor/hidden_service_peertube/hostname)"
180
-    fi
244
+    peertubedomain="http://localhost:${PEERTUBE_PORT}"
181
 
245
 
182
     if [ ${#peertubeuser} -lt 3 ]; then
246
     if [ ${#peertubeuser} -lt 3 ]; then
183
-        dialog --title $"Import videos" \
247
+        dialog --title $"Import videos from legacy sites" \
184
                --msgbox $"Username was not valid" 6 75
248
                --msgbox $"Username was not valid" 6 75
185
         return
249
         return
186
     fi
250
     fi
187
 
251
 
188
     if [ ${#peertubepassword} -lt 3 ]; then
252
     if [ ${#peertubepassword} -lt 3 ]; then
189
-        dialog --title $"Import videos" \
253
+        dialog --title $"Import videos from legacy sites" \
190
                --msgbox $"Password was not valid" 6 75
254
                --msgbox $"Password was not valid" 6 75
191
         return
255
         return
192
     fi
256
     fi
193
 
257
 
194
     if [[ "$video_url" == *' '* || "$video_url" == *','* || "$video_url" == *'@'* ]]; then
258
     if [[ "$video_url" == *' '* || "$video_url" == *','* || "$video_url" == *'@'* ]]; then
195
-        dialog --title $"Import videos" \
259
+        dialog --title $"Import videos from legacy sites" \
196
                --msgbox $"Video/channel URL was not valid" 6 75
260
                --msgbox $"Video/channel URL was not valid" 6 75
197
         return
261
         return
198
     fi
262
     fi
199
 
263
 
200
     if [ ${#video_url} -lt 8 ]; then
264
     if [ ${#video_url} -lt 8 ]; then
201
-        dialog --title $"Import videos" \
265
+        dialog --title $"Import videos from legacy sites" \
202
                --msgbox $"Video/channel URL was not valid" 6 75
266
                --msgbox $"Video/channel URL was not valid" 6 75
203
         return
267
         return
204
     fi
268
     fi
206
     cd $PEERTUBE_DIR || exit 32468356
270
     cd $PEERTUBE_DIR || exit 32468356
207
     import_script=$PEERTUBE_DIR/dist/server/tools/import-videos.js
271
     import_script=$PEERTUBE_DIR/dist/server/tools/import-videos.js
208
     if [ ! -f $import_script ]; then
272
     if [ ! -f $import_script ]; then
209
-        dialog --title $"Import videos" \
273
+        dialog --title $"Import videos from legacy sites" \
210
                --msgbox $"import-videos script was not found" 6 75
274
                --msgbox $"import-videos script was not found" 6 75
211
         return
275
         return
212
     fi
276
     fi
214
     clear
278
     clear
215
     node $import_script -u "$peertubedomain" -U "$peertubeuser" --password "$peertubepassword" -t "$video_url"
279
     node $import_script -u "$peertubedomain" -U "$peertubeuser" --password "$peertubepassword" -t "$video_url"
216
 
280
 
217
-    dialog --title $"Import videos" \
281
+    dialog --title $"Import videos from legacy sites" \
218
            --msgbox $"Video/s imported from $video_url" 6 75
282
            --msgbox $"Video/s imported from $video_url" 6 75
219
 }
283
 }
220
 
284
 
224
         data=$(mktemp 2>/dev/null)
288
         data=$(mktemp 2>/dev/null)
225
         dialog --backtitle $"Freedombone Control Panel" \
289
         dialog --backtitle $"Freedombone Control Panel" \
226
                --title $"PeerTube" \
290
                --title $"PeerTube" \
227
-               --radiolist $"Choose an operation:" 11 70 5 \
291
+               --radiolist $"Choose an operation:" 12 70 6 \
228
                1 $"Set administrator email address" off \
292
                1 $"Set administrator email address" off \
229
                2 $"Disable or enable signups" off \
293
                2 $"Disable or enable signups" off \
230
-               3 $"Import videos" off \
231
-               4 $"Exit" on 2> "$data"
294
+               3 $"Import videos from YouTube/Vimeo/Dailymotion" off \
295
+               4 $"Import video from file" off \
296
+               5 $"Exit" on 2> "$data"
232
         sel=$?
297
         sel=$?
233
         case $sel in
298
         case $sel in
234
             1) break;;
299
             1) break;;
238
             1) peertube_set_admin_email;;
303
             1) peertube_set_admin_email;;
239
             2) peertube_disable_signups;;
304
             2) peertube_disable_signups;;
240
             3) peertube_import_videos;;
305
             3) peertube_import_videos;;
241
-            4) rm -f "$data"
306
+            4) peertube_import_from_file;;
307
+            5) rm -f "$data"
242
                break;;
308
                break;;
243
         esac
309
         esac
244
         rm -f "$data"
310
         rm -f "$data"