Sfoglia il codice sorgente

Option to import videos into peertube

Bob Mottram 7 anni fa
parent
commit
3bba0ea621
1 ha cambiato i file con 74 aggiunte e 3 eliminazioni
  1. 74
    3
      src/freedombone-app-peertube

+ 74
- 3
src/freedombone-app-peertube Vedi File

@@ -149,16 +149,86 @@ function peertube_disable_signups {
149 149
     systemctl restart peertube
150 150
 }
151 151
 
152
+function peertube_import_videos {
153
+    read_config_param MY_USERNAME
154
+    read_config_param PEERTUBE_DOMAIN_NAME
155
+    read_config_param ONION_ONLY
156
+
157
+    data=$(mktemp 2>/dev/null)
158
+    dialog --backtitle $"Freedombone Control Panel" \
159
+           --title $"Import Videos" \
160
+           --form "Enter a channel of video URL for YouTube/Vimeo/Dailymotion" 10 75 4 \
161
+           $"Username:" 1 1 "$MY_USERNAME" 1 28 16 15 \
162
+           $"Password:" 2 1 "" 2 28 40 10000 \
163
+           $"Video/Channel URL:" 3 1 "" 3 28 40 10000 \
164
+           2> "$data"
165
+    sel=$?
166
+    case $sel in
167
+        1) rm -f "$data"
168
+           return;;
169
+        255) rm -f "$data"
170
+             return;;
171
+    esac
172
+    peertubeuser=$(sed -n 1p < "$data")
173
+    peertubepassword=$(sed -n 2p < "$data")
174
+    video_url=$(sed -n 3p < "$data")
175
+    rm -f "$data"
176
+
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
181
+
182
+    if [ ${#peertubeuser} -lt 3 ]; then
183
+        dialog --title $"Import videos" \
184
+               --msgbox $"Username was not valid" 6 75
185
+        return
186
+    fi
187
+
188
+    if [ ${#peertubepassword} -lt 3 ]; then
189
+        dialog --title $"Import videos" \
190
+               --msgbox $"Password was not valid" 6 75
191
+        return
192
+    fi
193
+
194
+    if [[ "$video_url" == *' '* || "$video_url" == *','* || "$video_url" == *'@'* ]]; then
195
+        dialog --title $"Import videos" \
196
+               --msgbox $"Video/channel URL was not valid" 6 75
197
+        return
198
+    fi
199
+
200
+    if [ ${#video_url} -lt 8 ]; then
201
+        dialog --title $"Import videos" \
202
+               --msgbox $"Video/channel URL was not valid" 6 75
203
+        return
204
+    fi
205
+
206
+    cd $PEERTUBE_DIR || exit 32468356
207
+    import_script=$PEERTUBE_DIR/dist/server/tools/import-videos.js
208
+    if [ ! -f $import_script ]; then
209
+        dialog --title $"Import videos" \
210
+               --msgbox $"import-videos script was not found" 6 75
211
+        return
212
+    fi
213
+
214
+    clear
215
+    node $import_script -u "$peertubedomain" -U "$peertubeuser" --password "$peertubepassword" -t "$video_url"
216
+
217
+    dialog --title $"Import videos" \
218
+           --msgbox $"Video/s imported from $video_url" 6 75
219
+}
220
+
152 221
 function configure_interactive_peertube {
153 222
     while true
154 223
     do
155 224
         data=$(mktemp 2>/dev/null)
156 225
         dialog --backtitle $"Freedombone Control Panel" \
157 226
                --title $"PeerTube" \
158
-               --radiolist $"Choose an operation:" 10 70 4 \
227
+               --radiolist $"Choose an operation:" 11 70 5 \
159 228
                1 $"Set administrator email address" off \
160 229
                2 $"Disable or enable signups" off \
161
-               3 $"Exit" on 2> "$data"
230
+               3 $"Import videos" off \
231
+               4 $"Exit" on 2> "$data"
162 232
         sel=$?
163 233
         case $sel in
164 234
             1) break;;
@@ -167,7 +237,8 @@ function configure_interactive_peertube {
167 237
         case $(cat "$data") in
168 238
             1) peertube_set_admin_email;;
169 239
             2) peertube_disable_signups;;
170
-            3) rm -f "$data"
240
+            3) peertube_import_videos;;
241
+            4) rm -f "$data"
171 242
                break;;
172 243
         esac
173 244
         rm -f "$data"