-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollage_tools
More file actions
executable file
Β·708 lines (634 loc) Β· 25.9 KB
/
collage_tools
File metadata and controls
executable file
Β·708 lines (634 loc) Β· 25.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
#!/bin/bash
# Orpheus Collage Tools - Enhanced with Crate Functionality
SCRIPT_DIR=$(dirname "$0")
CONFIG_DIR="$HOME/.orpheus-config"
CONFIG_FILE="$CONFIG_DIR/config.json"
# Configuration management
check_and_setup_config() {
# Check if config directory exists, create if not
if [ ! -d "$CONFIG_DIR" ]; then
echo "π§ Setting up Orpheus configuration directory..."
mkdir -p "$CONFIG_DIR"
if [ $? -ne 0 ]; then
echo "β Failed to create config directory: $CONFIG_DIR"
exit 1
fi
echo "β
Created config directory: $CONFIG_DIR"
fi
# Check if config file exists
if [ ! -f "$CONFIG_FILE" ]; then
echo ""
echo "π Orpheus Configuration Setup"
echo "=============================="
echo "Configuration file not found. Please provide your Orpheus credentials."
echo ""
# Loop until valid username and password are entered
while true; do
# Prompt for username
read -p "Enter your Orpheus username: " username
if [ -z "$username" ]; then
echo "β Username is required!"
continue
fi
# Prompt for password (hidden input)
echo -n "Enter your Orpheus password: "
read -s password
echo
if [ -z "$password" ]; then
echo "β Password is required!"
continue
fi
# Test login credentials
echo "π Validating credentials..."
# Use curl to test login
login_response=$(curl -s -c /tmp/orpheus_cookies -b /tmp/orpheus_cookies \
-d "username=$username" \
-d "password=$password" \
-d "keeplogged=1" \
-d "login=Log in" \
-w "%{http_code}" \
-o /dev/null \
"https://orpheus.network/login.php" 2>/dev/null)
# Clean up temp cookies
rm -f /tmp/orpheus_cookies 2>/dev/null
# Check if login was successful (302/303 redirect or 200 with session)
if [ "$login_response" = "302" ] || [ "$login_response" = "303" ]; then
echo "β
Login credentials validated successfully!"
break
else
echo "β Login failed. Please check your username and password."
echo ""
fi
done
# Now prompt for API key and validate it
echo ""
while true; do
read -p "Enter your Orpheus API key: " api_key
if [ -z "$api_key" ]; then
echo "β API key is required!"
continue
fi
# Test API key with a simple API call
echo "π Validating API key..."
# Use curl to test API key with collage endpoint (simple test)
api_response=$(curl -s \
-H "Authorization: token $api_key" \
-H "User-Agent: Orpheus-CLI/1.0" \
-w "%{http_code}" \
-o /tmp/api_test_response \
"https://orpheus.network/ajax.php?action=collage&id=1" 2>/dev/null)
# Check response content for success/error
if [ -f /tmp/api_test_response ]; then
response_content=$(cat /tmp/api_test_response)
rm -f /tmp/api_test_response 2>/dev/null
# Check if response contains success (API key works)
if [[ "$api_response" = "200" ]] && [[ "$response_content" == *"\"status\":\"success\""* ]] && [[ "$response_content" != *"\"error\""* ]]; then
echo "β
API key validated successfully!"
break
elif [[ "$response_content" == *"\"error\""* ]]; then
echo "β API key validation failed. Please check your API key."
echo "π‘ To obtain your API key:"
echo " 1. Go to User Settings: https://orpheus.network/user.php?action=edit&id=8956#access"
echo " 2. Scroll all the way down to the 'Access' section"
echo " 3. Copy your API key from there"
echo ""
else
echo "β API key validation failed. Please check your API key."
echo "π‘ To obtain your API key:"
echo " 1. Go to User Settings: https://orpheus.network/user.php?action=edit&id=8956#access"
echo " 2. Scroll all the way down to the 'Access' section"
echo " 3. Copy your API key from there"
echo ""
fi
else
echo "β Could not validate API key. Please check your API key."
echo "π‘ To obtain your API key:"
echo " 1. Go to User Settings: https://orpheus.network/user.php?action=edit&id=8956#access"
echo " 2. Scroll all the way down to the 'Access' section"
echo " 3. Copy your API key from there"
echo ""
fi
done
# Create config file
echo "π Saving configuration..."
cat > "$CONFIG_FILE" << EOF
{
"username": "$username",
"password": "$password",
"api_key": "$api_key"
}
EOF
# Set secure permissions
chmod 600 "$CONFIG_FILE"
echo "β
Configuration saved to: $CONFIG_FILE"
echo "π File permissions set to 600 (owner read/write only)"
echo ""
# Create symlink in project directory if it doesn't exist
PROJECT_CONFIG="$SCRIPT_DIR/config.json"
if [ ! -f "$PROJECT_CONFIG" ] && [ ! -L "$PROJECT_CONFIG" ]; then
ln -s "$CONFIG_FILE" "$PROJECT_CONFIG" 2>/dev/null || echo "β οΈ Note: Could not create symlink in project directory"
fi
else
# Config exists, verify it has required fields
if ! command -v python3 >/dev/null 2>&1; then
echo "β Python3 is required but not installed"
exit 1
fi
# Basic validation using python
python3 -c "
import json
try:
with open('$CONFIG_FILE', 'r') as f:
config = json.load(f)
required_fields = ['username', 'password', 'api_key']
missing = [field for field in required_fields if field not in config or not config[field]]
if missing:
print('β Config file missing required fields: ' + ', '.join(missing))
exit(1)
except Exception as e:
print('β Invalid config file format: ' + str(e))
exit(1)
" 2>/dev/null || {
echo "β Invalid or incomplete configuration file"
echo "Please delete $CONFIG_FILE and run again to reconfigure"
exit 1
}
fi
}
# Interactive prompts function
interactive_mode() {
while true; do
tput clear
# Loading bar with modern style
echo -e "\033[32mLoading...\033[0m"
bar_length=30
for i in $(seq 1 $bar_length); do
filled=$(printf '%.0s' $(seq 1 $i))
empty=$(printf '%.0s' $(seq 1 $(($bar_length - $i))))
printf "\r\033[1;32m[%s%s]\033[0m %d%%" "$filled" "$empty" $(($i * 100 / $bar_length))
sleep 0.1
done
echo
echo -e "\033[1;35mReady to go! π¨\033[0m"
tput clear
echo -e "\033[1;34m"
echo " ###### ###### ###### ## ## ####### ## ## ###### "
sleep 0.1
echo " ## ## ## ## ## ## ## ## ## ## ## ## ## "
sleep 0.09
echo " ## ## ## ## ## ## ## ## ## ## ## ## "
sleep 0.08
echo " ## ## ###### ###### ######## ###### ## ## ###### "
sleep 0.07
echo " ## ## ## ## ## ## ## ## ## ## ## "
sleep 0.06
echo " ## ## ## ## ## ## ## ## ## ## ## ## "
sleep 0.05
echo " ###### ## ## ## ## ## ####### ###### ###### "
sleep 0.04
echo -e "\033[1;36m"
echo -e " Orpheus Collage Tools - Interactive Mode"
sleep 0.04
echo -e "\033[1;32m"
echo
echo "==========================================="
echo ""
echo "What would you like to do?"
sleep 0.04
echo -e "\033[1;31m"
echo "1. π€ Find artist albums & releases (with crates)"
sleep 0.03
echo -e "\033[1;32m"
echo "2. π Find collages"
sleep 0.02
echo -e "\033[1;35m"
echo "3. β¬οΈ Download torrents from a collage"
sleep 0.03
echo -e "\033[1;37m"
echo "4. π¦ Manage crates"
sleep 0.04
echo -e "\033[1;38m"
echo "5. π― Load crate and browse"
sleep 0.05
echo -e "\033[1;39m"
echo "6. β Exit"
sleep 0.06
echo ""
echo "π‘ Quick tips:"
echo " β’ Use option 1 for browsing artist discographies"
echo " β’ Use option 2 for all collage search and discovery"
echo " β’ Use option 3 to download by collage ID"
echo " β’ All downloads save to ~/Documents/Orpheus/"
echo ""
echo ""
read -p "Choose option (1-6): " choice
case $choice in
1)
echo ""
echo "π€ Find Artist Albums & Releases (Enhanced with Crates)"
echo "======================================================"
read -p "Enter artist name: " artist
if [ -z "$artist" ]; then
echo "β Artist name is required!"
echo ""
continue
fi
echo ""
echo "π΅ Release search options:"
echo "1. All releases (including compilations)"
echo "2. Official releases only"
echo "3. Search specific release"
echo ""
read -p "Choose option (1-3): " search_option
case $search_option in
1)
echo ""
echo "π Searching for all releases by $artist..."
# Use the original working script - no changes to search!
python3 "$SCRIPT_DIR/lib/find_album_collages.py" --artist "$artist" --interactive
result=$?
;;
2)
echo ""
echo "π Searching for official releases by $artist..."
# Use the original working script - no changes to search!
python3 "$SCRIPT_DIR/lib/find_album_collages.py" --artist "$artist" --official-only --interactive
result=$?
;;
3)
echo ""
read -p "Enter album/release name: " album
if [ -z "$album" ]; then
echo "β Album name is required!"
echo ""
continue
fi
echo ""
echo "π Searching for '$album' by $artist..."
# Use the original working script - no changes to search!
python3 "$SCRIPT_DIR/lib/find_album_collages.py" --artist "$artist" --album "$album" --interactive
result=$?
;;
*)
echo "β Invalid choice!"
echo ""
continue
;;
esac
;;
2)
collage_menu
;;
3)
echo ""
echo "β¬οΈ Download Torrents from a Collage"
echo "===================================="
read -p "Enter collage ID: " collage_id
if [ -z "$collage_id" ]; then
echo "β Collage ID is required!"
echo ""
continue
fi
echo ""
echo "π Choose preferred encoding:"
echo "1. MP3 320 CBR (High quality, universal compatibility)"
echo "2. MP3 V0 VBR (Excellent quality, smaller files)"
echo "3. FLAC Lossless (Perfect quality, largest files)"
echo ""
echo "π‘ Tips:"
echo " β’ 320 CBR: Best for most users, works everywhere"
echo " β’ V0 VBR: Great quality with smaller file sizes"
echo " β’ FLAC: Perfect quality for audiophiles"
echo ""
read -p "Choose option (1-3): " encoding_choice
case $encoding_choice in
1)
prefer="--prefer-320"
format_name="MP3 320 CBR"
;;
2)
prefer="--prefer-v0"
format_name="MP3 V0 VBR"
;;
3)
prefer="--prefer-flac"
format_name="FLAC Lossless"
;;
*)
echo "β Invalid choice!"
echo ""
continue
;;
esac
echo ""
echo "β¬οΈ Starting download from collage ID: $collage_id"
echo "π΅ Preferred format: $format_name"
echo ""
if [ -f "$SCRIPT_DIR/lib/download_collage_torrents.py" ]; then
python3 "$SCRIPT_DIR/lib/download_collage_torrents.py" "$collage_id" "$prefer"
fi
;;
4)
echo ""
echo "π¦ Crate Management"
echo "=================="
echo "1. π List existing crates"
echo "2. π Create new crate"
echo "3. β¬οΈ Download a crate"
echo "4. π Back to main menu"
echo ""
read -p "Choose option (1-4): " crate_choice
case $crate_choice in
1)
python3 "$SCRIPT_DIR/lib/download_crate.py" --list-crates
;;
2)
read -p "Enter crate name: " crate_name
if [ -n "$crate_name" ]; then
python3 "$SCRIPT_DIR/lib/download_crate.py" --create-crate "$crate_name"
else
echo "β Please provide a crate name"
fi
;;
3)
echo ""
python3 "$SCRIPT_DIR/lib/download_crate.py" --list-crates
echo ""
read -p "Enter crate name to download: " download_crate
if [ -n "$download_crate" ]; then
python3 "$SCRIPT_DIR/lib/download_crate.py" --download-crate "$download_crate"
else
echo "β Please provide a crate name"
fi
;;
4)
continue
;;
*)
echo "β Invalid choice!"
;;
esac
;;
5)
echo ""
echo "π― Load Crate and Browse"
echo "======================="
python3 "$SCRIPT_DIR/lib/download_crate.py" --list-crates
echo ""
read -p "Enter crate name to load: " load_crate
if [ -n "$load_crate" ]; then
read -p "Enter artist to search: " artist
if [ -n "$artist" ]; then
echo "π Searching with crate functionality..."
# Use original script - search works perfectly!
python3 "$SCRIPT_DIR/lib/find_album_collages.py" --artist "$artist" --interactive
else
echo "β Artist name is required for browsing"
fi
else
echo "β Please provide a crate name"
fi
;;
6)
echo "π Goodbye!"
exit 0
;;
*)
echo "β Invalid choice!"
echo ""
continue
;;
esac
# Pause before showing menu again
if [ $result -ne 2 ] 2>/dev/null; then
echo ""
read -p "Press Enter to return to main menu..."
fi
echo ""
done
}
# Collage submenu function
collage_menu() {
while true; do
echo ""
echo "π COLLAGE SEARCH OPTIONS"
echo "========================="
echo ""
echo "1. π΅ Find collages featuring an artist"
echo "2. π Find which collages contain a specific album"
echo "3. π Search & download collages by name"
echo "4. π Back to main menu"
echo ""
read -p "Choose option (1-4): " collage_choice
case $collage_choice in
1)
echo ""
echo "π΅ Find Collages Featuring an Artist"
echo "===================================="
read -p "Enter artist name: " artist
if [ -z "$artist" ]; then
echo "β Artist name is required!"
echo ""
continue
fi
echo ""
echo "π Searching for collages that contain albums by $artist..."
echo "π‘ This will find all collages featuring $artist's music"
echo ""
if [ -f "$SCRIPT_DIR/lib/search_artist_collages.py" ]; then
python3 "$SCRIPT_DIR/lib/search_artist_collages.py" "$artist"
else
echo "β Artist collage search script not found!"
fi
;;
2)
echo ""
echo "π Find Which Collages Contain an Album"
echo "======================================="
read -p "Enter artist name: " artist
read -p "Enter album name: " album
if [ -z "$artist" ] || [ -z "$album" ]; then
echo "β Both artist and album names are required!"
echo ""
continue
fi
echo ""
echo "π Searching for '$album' by $artist in collages..."
python3 "$SCRIPT_DIR/lib/find_album_collages.py" --artist "$artist" --album "$album" --show-collages
result=$?
;;
3)
echo ""
echo "π Search & Download Collages by Name"
echo "===================================="
read -p "Enter collage name or keywords: " collage_search
if [ -z "$collage_search" ]; then
echo "β Search term is required!"
echo ""
continue
fi
echo ""
echo "π Searching for collages containing: '$collage_search'"
echo "π‘ This will show matching collages with their IDs"
echo " You can then use option 3 to download them"
echo ""
if [ -f "$SCRIPT_DIR/lib/search_collages.py" ]; then
python3 "$SCRIPT_DIR/lib/search_collages.py" "$collage_search"
else
echo "β Collage search script not found!"
fi
;;
4)
return
;;
*)
echo "β Invalid choice! Please choose 1, 2, 3, or 4."
echo ""
continue
;;
esac
echo ""
read -p "Press Enter to return to collage menu..."
echo ""
done
}
# Check and setup configuration before running any commands
check_and_setup_config
case $1 in
crate)
case $2 in
list)
python3 "$SCRIPT_DIR/lib/download_crate.py" --list-crates
;;
create)
if [ -n "$3" ]; then
python3 "$SCRIPT_DIR/lib/download_crate.py" --create-crate "$3"
else
echo "Usage: ./collage_tools crate create <crate_name>"
fi
;;
download)
if [ -n "$3" ]; then
python3 "$SCRIPT_DIR/lib/download_crate.py" --download-crate "$3"
else
echo "Usage: ./collage_tools crate download <crate_name>"
fi
;;
*)
echo "π¦ Crate Commands:"
echo " ./collage_tools crate list # List all crates"
echo " ./collage_tools crate create <n> # Create new crate"
echo " ./collage_tools crate download <n> # Download crate"
;;
esac
;;
find-artist-collages)
shift
artist="$1"
if [ -z "$artist" ]; then
echo "β Artist name is required!"
echo "Usage: ./collage_tools find-artist-collages 'Artist Name'"
exit 1
fi
echo ""
echo "π΅ Finding Collages Featuring '$artist'"
echo "======================================"
echo "π Searching for collages that contain albums by $artist..."
echo "π‘ This will find all collages featuring $artist's music"
echo ""
if [ -f "$SCRIPT_DIR/lib/search_artist_collages.py" ]; then
python3 "$SCRIPT_DIR/lib/search_artist_collages.py" "$artist"
else
echo "β Artist collage search script not found!"
exit 1
fi
;;
download)
# Download torrent files from a collage (--prefer is MANDATORY)
shift
collage_id="$1"
shift
# Check if --prefer option is provided
prefer_found=false
for arg in "$@"; do
case $arg in
--prefer-*)
prefer_found=true
break
;;
esac
done
if [ "$prefer_found" = false ]; then
echo "β ERROR: --prefer option is MANDATORY!"
echo ""
echo "Required encoding preference:"
echo " --prefer-320 # MP3 320 CBR"
echo " --prefer-v0 # MP3 V0 VBR"
echo " --prefer-flac # FLAC Lossless"
echo ""
echo "Example: ./collage_tools download 6936 --prefer-320"
exit 1
fi
python3 "$SCRIPT_DIR/lib/download_collage_torrents.py" "$collage_id" "$@"
;;
quick-search)
# Quick search for an artist/album's collages
shift
artist=""
album=""
while [ $# -gt 0 ]; do
case $1 in
--artist)
artist="$2"
shift 2
;;
--album)
album="$2"
shift 2
;;
*)
shift
;;
esac
done
if [ -n "$artist" ] || [ -n "$album" ]; then
echo "π Quick search for collages..."
python3 "$SCRIPT_DIR/lib/find_album_collages.py" --artist "$artist" --album "$album"
else
echo "Usage: ./collage_tools quick-search --artist 'Name' --album 'Name'"
fi
;;
"")
# No arguments - start interactive mode
interactive_mode
;;
*)
echo "π΅ Orpheus Collage Tools - Enhanced with Crates"
echo "==============================================="
echo ""
echo "π Live Search Commands:"
echo " ./collage_tools find-album --artist 'Name' --interactive"
echo " ./collage_tools find-album --artist 'Name' --album 'Name'"
echo ""
echo "π¦ Crate Commands:"
echo " ./collage_tools crate list # List all crates"
echo " ./collage_tools crate create <n> # Create new crate"
echo " ./collage_tools crate download <n> # Download crate"
echo ""
echo "β¬οΈ Download Commands (--prefer is MANDATORY):"
echo " ./collage_tools download [collage_id] --prefer-320 # MP3 320"
echo " ./collage_tools download [collage_id] --prefer-v0 # MP3 V0"
echo " ./collage_tools download [collage_id] --prefer-flac # FLAC"
echo ""
echo "π Quick Search:"
echo " ./collage_tools quick-search --artist 'Name' --album 'Name'"
echo ""
echo "π― Interactive Mode:"
echo " ./collage_tools # Start guided prompts"
echo ""
echo "π‘ Examples:"
echo " ./collage_tools find-album --artist 'The Prodigy' --interactive"
echo " ./collage_tools crate create 'My Favorites'"
echo " ./collage_tools crate download 'My Favorites'"
;;
esac