-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuild_docs.py
More file actions
1251 lines (1030 loc) · 58 KB
/
Copy pathbuild_docs.py
File metadata and controls
1251 lines (1030 loc) · 58 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
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
import configparser
import os
import re
import shutil
import sys
import time
from src import ampache
# user variables
url = 'https://demo.ampache.dev'
api = 'demo'
user = 'demodemo'
limit = 4
offset = 0
api_version = '8.0.0'
song_url = 'https://music.com.au/play/index.php?ssid=eeb9f1b6056246a7d563f479f518bb34&type=song&oid=60&uid=4&player=api&name=Synthetic%20-%20BrownSmoke.wma'
try:
if sys.argv[1]:
url = sys.argv[1]
if sys.argv[2]:
api = sys.argv[2]
if sys.argv[3]:
user = sys.argv[3]
except IndexError:
conf_files = ['ampache.conf',
os.path.join(os.pardir, 'ampache.conf'),
'docs/examples/ampyche.conf']
conf_file = next((path for path in conf_files if os.path.isfile(path)), None)
if conf_file:
print('Using config file ' + conf_file)
conf = configparser.RawConfigParser()
conf.read(conf_file)
url = conf.get('conf', 'ampache_url')
api = conf.get('conf', 'ampache_apikey')
user = conf.get('conf', 'ampache_user')
else:
print()
sys.exit('Error: docs/examples/ampyche.conf not found and no arguments set')
def object_list(connection, data, attribute):
""" Return a list of (id, fields) tuples for any api response
Ampache hands back three different shapes for a list of things, so they are
all folded into one here:
* a wrapped list {'song': [{...}, {...}]}
* a bare object {'id': '132', 'title': '...'} (song, user, bookmark)
* an index list {'song': ['132', '133']}
Nested objects (a song's artist and album) are flattened to their name so
that fields['artist'] is a string in both json and xml.
"""
objects = list()
if data is None:
return objects
if connection.AMPACHE_API == 'xml':
for child in data:
if child.tag != attribute:
continue
fields = dict()
for field in child:
if len(field) > 0:
# a nested object such as a song's artist, so read its name
nested = field.find('name')
fields[field.tag] = nested.text if nested is not None else None
else:
fields[field.tag] = field.text
objects.append((child.attrib.get('id'), fields))
return objects
if not isinstance(data, dict):
return objects
items = data.get(attribute)
if items is None:
# a bare object response carries the object itself
items = [data] if 'id' in data else None
if isinstance(items, dict):
items = [items]
if not isinstance(items, list):
return objects
for item in items:
if isinstance(item, (str, int)):
objects.append((str(item), dict()))
continue
if not isinstance(item, dict):
continue
fields = {key: (value.get('name') if isinstance(value, dict) else value)
for key, value in item.items()}
item_id = item.get('id')
objects.append((str(item_id) if item_id is not None else None, fields))
return objects
def id_list(connection, data, attribute):
""" Return every id in an api response """
return [object_id for object_id, fields in object_list(connection, data, attribute) if object_id]
def first_id(connection, data, attribute):
""" Return the first id in an api response, or None when the server has none """
found = id_list(connection, data, attribute)
return found[0] if found else None
def first_value(connection, data, attribute, field):
""" Return a field from the first object in an api response """
for object_id, fields in object_list(connection, data, attribute):
value = fields.get(field)
if value:
return value
return None
def find_id(connection, data, attribute, field, value):
""" Return the id of the first object whose field matches value """
for object_id, fields in object_list(connection, data, attribute):
if str(fields.get(field)) == str(value):
return object_id
return None
def resolve(connection, lookup, attribute, candidate, fallback):
""" Check that a discovered id really resolves before adopting it
A random stat can name an object that is no longer in the catalog. When that
happens the fallback is looked up again so its response, and not the error, is
what ends up in the documentation.
"""
if candidate and str(candidate) != str(fallback):
if first_id(connection, lookup(candidate), attribute):
return candidate
print('the server offered ' + attribute + ' ' + str(candidate) + ' but it does not resolve, keeping ' + str(fallback))
lookup(fallback)
return fallback
def remove_existing(connection, data, attribute, names, delete):
""" Delete anything an interrupted run left behind
Ampache rejects a duplicate name, so the objects this script creates have to be
cleared out before it can create them again.
"""
for name in names:
existing = find_id(connection, data, attribute, 'name', name)
if existing:
print('removing the leftover ' + attribute + ' "' + name + '" from an earlier run')
delete(existing)
def pick(items, index):
""" Cycle through whatever the server has so callers can ask for distinct objects """
if not items:
return None
return items[index % len(items)]
def filter_word(text, fallback='a'):
""" Turn a real name into a search filter that is guaranteed to match it """
if not text:
return fallback
for word in str(text).split():
if len(word) > 2:
return word
return str(text)[:3] or fallback
def build_docs(ampache_url, ampache_api, ampache_user, api_format):
ampacheConnection = ampache.API()
skipped = list()
"""TODO
def stream(id, type, destination, api_format = 'xml'):
def download(id, type, destination, format = 'raw', api_format = 'xml'):
def random(destination, type, filter_id, ...): streams a random object, needs a writable destination
def upload(file_path, ...): needs a real media file and the allow_upload preference
podcast_episode_delete: delete an existing podcast_episode
catalog_file: clean, add, verify using the file path (good for scripting)
catalog_folder: clean, add, verify using the folder path
catalog_create: creates a real catalog, so it is left to run_tests.py
sonic_match: answers 4703 unless a sonic analysis plugin is enabled for the user
"""
""" def set_debug(boolean):
This function can be used to enable/disable debugging messages
"""
ampacheConnection.set_debug(True)
ampacheConnection.set_format(api_format)
# send a bad ping
ampacheConnection.ping(ampache_url, False, api_version)
if os.path.isfile("docs/" + api_format + "-responses/ping." + api_format):
shutil.move("docs/" + api_format + "-responses/ping." + api_format,
"docs/" + api_format + "-responses/ping (no auth)." + api_format)
""" def encrypt_string(ampache_api, user)
This function can be used to encrypt your apikey into the accepted format.
"""
encrypted_key = ampacheConnection.encrypt_string(ampache_api, ampache_user)
""" def handshake(user = False, timestamp = False, version = '5.0.0', api_format = 'xml'):
This is the function that handles verifying a new handshake
Takes a timestamp, auth key, and username.
"""
# bad handshake
ampacheConnection.handshake(ampache_url, 'badkey', '', 0, api_version)
if os.path.isfile("docs/" + api_format + "-responses/handshake." + api_format):
shutil.move("docs/" + api_format + "-responses/handshake." + api_format,
"docs/" + api_format + "-responses/handshake (error)." + api_format)
# use correct details
ampache_session = ampacheConnection.handshake(ampache_url, encrypted_key, '', 0, api_version)
if not ampache_session:
print(encrypted_key)
sys.exit('ERROR: Failed to connect to ' + ampache_url)
""" def ping(api_format = 'xml'):
This can be called without being authenticated, it is useful for determining if what the status
of the server is, and what version it is running/compatible with
"""
my_ping = ampacheConnection.ping(ampache_url, ampache_session, api_version)
if not my_ping:
print()
sys.exit('ERROR: Failed to ping ' + ampache_url)
""" def system_update(ampache_url: str, ampache_api: str, api_format: str = 'xml'):
"""
ampacheConnection.system_update()
""" def live_streams(filter = False, exact = False, offset = 0, limit = 0, api_format = 'xml'):
"""
live_streams = ampacheConnection.live_streams(False, False, offset, limit)
single_live_stream = first_id(ampacheConnection, live_streams, 'live_stream')
""" def live_stream(filter, api_format = 'xml'):
"""
if single_live_stream:
ampacheConnection.live_stream(single_live_stream)
else:
skipped.append('live_stream (no live streams on this server)')
""" def labels(filter = False, exact = False, offset = 0, limit = 0, api_format = 'xml'):
"""
labels = ampacheConnection.labels(False, False, offset, limit)
single_label = first_id(ampacheConnection, labels, 'label')
""" def label(filter, api_format = 'xml'):
"""
""" def label_songs(filter, api_format = 'xml'):
"""
if single_label:
ampacheConnection.label(single_label)
ampacheConnection.label_artists(filter_id=single_label)
else:
skipped.append('label, label_artists (no labels on this server)')
""" def user_create(username, password, email, fullname = False, disable = False, api_format = 'xml'):
"""
tempusername = 'temp_user'
ampacheConnection.user_create(tempusername, 'supoersecretpassword', 'email@gmail.com', False, False)
ampacheConnection.user(tempusername)
""" def user_edit(username, password = False, fullname = False, email = False, website = False, state = False, city = False, disable = False, maxbitrate = False, api_format = 'xml'):
"""
ampacheConnection.user_edit(username=tempusername, password=False, fullname=False, email=False, website=False, state=False, city=False, disable=True, maxbitrate=False)
ampacheConnection.user(tempusername)
if os.path.isfile("docs/" + api_format + "-responses/user." + api_format):
shutil.move("docs/" + api_format + "-responses/user." + api_format,
"docs/" + api_format + "-responses/user (disabled)." + api_format)
""" def user_delete(username, api_format = 'xml'):
"""
ampacheConnection.user_delete(tempusername)
""" def user(username, api_format = 'xml'):
"""
ampacheConnection.user('missing_user')
if os.path.isfile("docs/" + api_format + "-responses/user." + api_format):
shutil.move("docs/" + api_format + "-responses/user." + api_format,
"docs/" + api_format + "-responses/user (error)." + api_format)
myuser = ampacheConnection.user(ampache_user)
user_id = first_id(ampacheConnection, myuser, 'user')
if not user_id:
sys.exit('ERROR: could not read the user id for ' + ampache_user)
print('\nbuilding docs as user ' + ampache_user + ' (id ' + str(user_id) + ')')
""" def index(object_type, filter_str, exact, add, update, include, offset, limit)):
'song'|'album'|'artist'|'playlist'
"""
songs = ampacheConnection.index(object_type='song', filter_str=False, exact=False, add=False, update=False, include=False, offset=offset, limit=limit)
if os.path.isfile("docs/" + api_format + "-responses/index." + api_format):
shutil.move("docs/" + api_format + "-responses/index." + api_format,
"docs/" + api_format + "-responses/index (song)." + api_format)
song_ids = id_list(ampacheConnection, songs, 'song')
if not song_ids:
sys.exit('ERROR: no songs found on ' + ampache_url + ', the docs need a catalog with data in it')
single_song = pick(song_ids, 0)
ampacheConnection.index(object_type='song', filter_str=False, exact=False, add=False, update=False, include=True, offset=offset, limit=limit)
if os.path.isfile("docs/" + api_format + "-responses/index." + api_format):
shutil.move("docs/" + api_format + "-responses/index." + api_format,
"docs/" + api_format + "-responses/index (song with include)." + api_format)
albums = ampacheConnection.index(object_type='album', filter_str=False, exact=False, add=False, update=False, include=False, offset=offset, limit=limit)
if os.path.isfile("docs/" + api_format + "-responses/index." + api_format):
shutil.move("docs/" + api_format + "-responses/index." + api_format,
"docs/" + api_format + "-responses/index (album)." + api_format)
album_ids = id_list(ampacheConnection, albums, 'album')
if not album_ids:
sys.exit('ERROR: no albums found on ' + ampache_url + ', the docs need a catalog with data in it')
single_album = pick(album_ids, 0)
ampacheConnection.index(object_type='album', filter_str=False, exact=False, add=False, update=False, include=True, offset=offset, limit=limit)
if os.path.isfile("docs/" + api_format + "-responses/index." + api_format):
shutil.move("docs/" + api_format + "-responses/index." + api_format,
"docs/" + api_format + "-responses/index (album with include)." + api_format)
artists = ampacheConnection.index(object_type='artist', filter_str=False, exact=False, add=False, update=False, include=False, offset=offset, limit=limit)
if os.path.isfile("docs/" + api_format + "-responses/index." + api_format):
shutil.move("docs/" + api_format + "-responses/index." + api_format,
"docs/" + api_format + "-responses/index (artist)." + api_format)
artist_ids = id_list(ampacheConnection, artists, 'artist')
if not artist_ids:
sys.exit('ERROR: no artists found on ' + ampache_url + ', the docs need a catalog with data in it')
single_artist = pick(artist_ids, 0)
ampacheConnection.index(object_type='artist', filter_str=False, exact=False, add=False, update=False, include=True, offset=offset, limit=limit)
if os.path.isfile("docs/" + api_format + "-responses/index." + api_format):
shutil.move("docs/" + api_format + "-responses/index." + api_format,
"docs/" + api_format + "-responses/index (artist with include)." + api_format)
playlists = ampacheConnection.index(object_type='playlist', filter_str=False, exact=False, add=False, update=False, include=False, offset=offset, limit=limit)
if os.path.isfile("docs/" + api_format + "-responses/index." + api_format):
shutil.move("docs/" + api_format + "-responses/index." + api_format,
"docs/" + api_format + "-responses/index (playlist)." + api_format)
playlist_ids = id_list(ampacheConnection, playlists, 'playlist')
# the playlist index also carries smartlists as 'smart_<id>', which most methods reject
real_playlist_ids = [playlist for playlist in playlist_ids if str(playlist).isdigit()]
single_playlist = pick(real_playlist_ids, 0)
ampacheConnection.index(object_type='playlist', filter_str=False, exact=False, add=False, update=False, include=True, offset=offset, limit=1)
if os.path.isfile("docs/" + api_format + "-responses/index." + api_format):
shutil.move("docs/" + api_format + "-responses/index." + api_format,
"docs/" + api_format + "-responses/index (playlist with include)." + api_format)
ampacheConnection.index(object_type='podcast', filter_str=False, exact=False, add=False, update=False, include=False, offset=offset, limit=limit)
if os.path.isfile("docs/" + api_format + "-responses/index." + api_format):
shutil.move("docs/" + api_format + "-responses/index." + api_format,
"docs/" + api_format + "-responses/index (podcast)." + api_format)
ampacheConnection.index(object_type='podcast', filter_str=False, exact=False, add=False, update=False, include=True, offset=offset, limit=limit)
if os.path.isfile("docs/" + api_format + "-responses/index." + api_format):
shutil.move("docs/" + api_format + "-responses/index." + api_format,
"docs/" + api_format + "-responses/index (podcast with include)." + api_format)
""" Read the names off real objects so every filter below matches something.
Nothing here is specific to a catalog, so the docs build on any server with data.
"""
song = ampacheConnection.song(single_song)
song_title = first_value(ampacheConnection, song, 'song', 'title')
song_artist = first_value(ampacheConnection, song, 'song', 'artist')
song_album = first_value(ampacheConnection, song, 'song', 'album')
song_stream = first_value(ampacheConnection, song, 'song', 'url')
print('using the song "' + str(song_title) + '" by "' + str(song_artist) + '" on "' + str(song_album) + '"')
artist = ampacheConnection.artist(single_artist, False)
artist_title = first_value(ampacheConnection, artist, 'artist', 'name')
album = ampacheConnection.album(single_album, False)
album_title = first_value(ampacheConnection, album, 'album', 'name')
# filters that are guaranteed to return the object they came from
song_filter = filter_word(song_title)
artist_filter = filter_word(artist_title)
""" def url_to_song(url, api_format = 'xml'):
"""
ampacheConnection.url_to_song(song_stream if song_stream else song_url)
""" def videos(filter = False, exact = False, offset = 0, limit = 0, api_format = 'xml'):
"""
videos = ampacheConnection.videos(False, False, 0, 0)
single_video = first_id(ampacheConnection, videos, 'video')
""" def video(filter, api_format = 'xml'):
"""
if single_video:
ampacheConnection.video(single_video)
else:
skipped.append('video (no videos on this server)')
""" def advanced_search(rules, operator = 'and', type = 'song', offset = 0, limit = 0, api_format = 'xml'):
"""
search_rules = [['favorite', 0, '%'], ['title', 2, song_filter]]
search_song = ampacheConnection.advanced_search(search_rules, 'or', 'song', offset, limit, 0)
if os.path.isfile("docs/" + api_format + "-responses/advanced_search." + api_format):
shutil.move("docs/" + api_format + "-responses/advanced_search." + api_format,
"docs/" + api_format + "-responses/advanced_search (song)." + api_format)
song_id = first_id(ampacheConnection, search_song, 'song')
if not song_id:
song_id = single_song
search_rules = [['artist', 0, artist_filter]]
search_album = ampacheConnection.advanced_search(search_rules, 'or', 'album', offset, limit, 0)
if os.path.isfile("docs/" + api_format + "-responses/advanced_search." + api_format):
shutil.move("docs/" + api_format + "-responses/advanced_search." + api_format,
"docs/" + api_format + "-responses/advanced_search (album)." + api_format)
found_album = first_value(ampacheConnection, search_album, 'album', 'name')
if found_album:
album_title = found_album
search_rules = [['artist', 2, artist_filter]]
search_artist = ampacheConnection.advanced_search(search_rules, 'or', 'artist', offset, limit, 0)
if os.path.isfile("docs/" + api_format + "-responses/advanced_search." + api_format):
shutil.move("docs/" + api_format + "-responses/advanced_search." + api_format,
"docs/" + api_format + "-responses/advanced_search (artist)." + api_format)
found_artist = first_value(ampacheConnection, search_artist, 'artist', 'name')
if found_artist:
artist_title = found_artist
search_rules = [['favorite', 0, '%'], ['title', 2, song_filter]]
# (https://raw.githubusercontent.com/ampache/python3-ampache/api6/docs/json-responses/search_group%20\(all\).json)
# (https://raw.githubusercontent.com/ampache/python3-ampache/api6/docs/xml-responses/search_group%20\(all\).xml)]]
ampacheConnection.search_group(search_rules, 'or', 'all', offset, limit, 0)
if os.path.isfile("docs/" + "search_group." + api_format):
shutil.move("docs/" + "search_group." + api_format,
"docs/" + "search_group (all)." + api_format)
search_rules = [['artist', 0, artist_filter]]
# (https://raw.githubusercontent.com/ampache/python3-ampache/api6/docs/json-responses/search_group%20\(music\).json)
# (https://raw.githubusercontent.com/ampache/python3-ampache/api6/docs/xml-responses/search_group%20\(music\).xml)]]
ampacheConnection.search_group(search_rules, 'or', 'music', offset, limit, 0)
if os.path.isfile("docs/" + "search_group." + api_format):
shutil.move("docs/" + "search_group." + api_format,
"docs/" + "search_group (music)." + api_format)
search_rules = [['title', 2, song_filter]]
# (https://raw.githubusercontent.com/ampache/python3-ampache/api6/docs/json-responses/search_group%20\(podcast\).json)
# (https://raw.githubusercontent.com/ampache/python3-ampache/api6/docs/xml-responses/search_group%20\(podcast\).xml)]]
ampacheConnection.search_group(search_rules, 'or', 'podcast', offset, limit, 0)
if os.path.isfile("docs/" + "search_group." + api_format):
shutil.move("docs/" + "search_group." + api_format,
"docs/" + "search_group (podcast)." + api_format)
""" def album(filter, include = False, api_format = 'xml'):
"""
ampacheConnection.album(single_album, True)
if os.path.isfile("docs/" + api_format + "-responses/album." + api_format):
shutil.move("docs/" + api_format + "-responses/album." + api_format,
"docs/" + api_format + "-responses/album (with include)." + api_format)
album = ampacheConnection.album(single_album, False)
found_album = first_value(ampacheConnection, album, 'album', 'name')
if found_album:
album_title = found_album
""" def album_songs(filter, offset = 0, limit = 0, api_format = 'xml'):
"""
ampacheConnection.album_songs(single_album, offset, limit)
""" def albums(filter = False, exact = False, add = False, update = False, offset = 0, limit = 0, include = False, api_format = 'xml'):
"""
ampacheConnection.albums(album_title, 1, False, False, 0, 2, True)
if os.path.isfile("docs/" + api_format + "-responses/albums." + api_format):
shutil.move("docs/" + api_format + "-responses/albums." + api_format,
"docs/" + api_format + "-responses/albums (with include)." + api_format)
albums = ampacheConnection.albums(album_title, 1, False, False, 0, 10, False)
""" def stats(type, filter = 'random', username = False, user_id = False, offset = 0, limit = 0, api_format = 'xml'):
"""
ampacheConnection.stats('song', 'random', ampache_user, None, 0, 2)
if os.path.isfile("docs/" + api_format + "-responses/stats." + api_format):
shutil.move("docs/" + api_format + "-responses/stats." + api_format,
"docs/" + api_format + "-responses/stats (song)." + api_format)
stats = ampacheConnection.stats('artist', 'random', ampache_user, False, 0, 2)
if os.path.isfile("docs/" + api_format + "-responses/stats." + api_format):
shutil.move("docs/" + api_format + "-responses/stats." + api_format,
"docs/" + api_format + "-responses/stats (artist)." + api_format)
random_artist = resolve(ampacheConnection, lambda filter_id: ampacheConnection.artist(filter_id, False),
'artist', first_id(ampacheConnection, stats, 'artist'), single_artist)
if str(random_artist) != str(single_artist):
print('\ngetting a random artist using the stats method and found',
first_value(ampacheConnection, stats, 'artist', 'name'))
single_artist = random_artist
artist_title = first_value(ampacheConnection, stats, 'artist', 'name') or artist_title
stats = ampacheConnection.stats('album', 'random', ampache_user, None, 0, 2)
if os.path.isfile("docs/" + api_format + "-responses/stats." + api_format):
shutil.move("docs/" + api_format + "-responses/stats." + api_format,
"docs/" + api_format + "-responses/stats (album)." + api_format)
random_album = resolve(ampacheConnection, lambda filter_id: ampacheConnection.album(filter_id, False),
'album', first_id(ampacheConnection, stats, 'album'), single_album)
if str(random_album) != str(single_album):
print('\ngetting a random album using the stats method and found',
first_value(ampacheConnection, stats, 'album', 'name'))
single_album = random_album
album_title = first_value(ampacheConnection, stats, 'album', 'name') or album_title
""" def artist(filter, include = False, api_format = 'xml'):
"""
ampacheConnection.artist(single_artist, True)
if os.path.isfile("docs/" + api_format + "-responses/artist." + api_format):
shutil.move("docs/" + api_format + "-responses/artist." + api_format,
"docs/" + api_format + "-responses/artist (with include songs,albums)." + api_format)
ampacheConnection.artist(single_artist, 'songs')
if os.path.isfile("docs/" + api_format + "-responses/artist." + api_format):
shutil.move("docs/" + api_format + "-responses/artist." + api_format,
"docs/" + api_format + "-responses/artist (with include songs)." + api_format)
ampacheConnection.artist(single_artist, 'albums')
if os.path.isfile("docs/" + api_format + "-responses/artist." + api_format):
shutil.move("docs/" + api_format + "-responses/artist." + api_format,
"docs/" + api_format + "-responses/artist (with include albums)." + api_format)
artist = ampacheConnection.artist(single_artist, False)
if api_format == 'xml':
for child in artist:
if child.tag == 'artist':
print('\nsearching for an artist with this id', single_artist)
""" def artist_albums(filter, offset = 0, limit = 0, api_format = 'xml'):
"""
ampacheConnection.artist_albums(single_artist, offset, limit)
""" def artist_songs(filter, offset = 0, limit = 0, api_format = 'xml'):
"""
ampacheConnection.artist_songs(filter_id=single_artist, offset=offset, limit=limit)
""" def artists(filter = False, add = False, update = False, offset = 0, limit = 0, include = False, api_format = 'xml'):
"""
ampacheConnection.artists(filter_str=False, add=False, update=False, offset=offset, limit=limit, include=True)
if os.path.isfile("docs/" + api_format + "-responses/artists." + api_format):
shutil.move("docs/" + api_format + "-responses/artists." + api_format,
"docs/" + api_format + "-responses/artists (with include songs,albums)." + api_format)
ampacheConnection.artists(filter_str=False, add=False, update=False, offset=offset, limit=limit, include='songs')
if os.path.isfile("docs/" + api_format + "-responses/artists." + api_format):
shutil.move("docs/" + api_format + "-responses/artists." + api_format,
"docs/" + api_format + "-responses/artists (with include songs)." + api_format)
ampacheConnection.artists(filter_str=False, add=False, update=False, offset=offset, limit=limit, include='albums')
if os.path.isfile("docs/" + api_format + "-responses/artists." + api_format):
shutil.move("docs/" + api_format + "-responses/artists." + api_format,
"docs/" + api_format + "-responses/artists (with include albums)." + api_format)
ampacheConnection.artists(filter_str=False, add=False, update=False, offset=offset, limit=limit, include=False)
""" catalogs: get all the catalogs
"""
catalogs = ampacheConnection.catalogs()
catalog_ids = id_list(ampacheConnection, catalogs, 'catalog')
single_catalog = pick(catalog_ids, 0)
podcast_catalog = find_id(ampacheConnection, catalogs, 'catalog', 'gather_types', 'podcast')
""" def catalog_action(task, catalog, api_format = 'xml'):
'clean' is not a task name, so this documents the error response
"""
ampacheConnection.catalog_action('clean', single_catalog)
if os.path.isfile("docs/" + api_format + "-responses/catalog_action." + api_format):
shutil.move("docs/" + api_format + "-responses/catalog_action." + api_format,
"docs/" + api_format + "-responses/catalog_action (error)." + api_format)
#ampacheConnection.catalog_action('clean_catalog', single_catalog)
ampacheConnection.bookmark_create(pick(song_ids, 1), 'song', 0, 'client1')
ampacheConnection.bookmark_create(pick(song_ids, 2), 'song', 10, 'client')
# (https://raw.githubusercontent.com/ampache/python3-ampache/api6/docs/json-responses/bookmarks.json)
# (https://raw.githubusercontent.com/ampache/python3-ampache/api6/docs/xml-responses/bookmarks.xml)
bookmarks = ampacheConnection.bookmarks(False, True)
if os.path.isfile("docs/" + api_format + "-responses/bookmarks." + api_format):
shutil.move("docs/" + api_format + "-responses/bookmarks." + api_format,
"docs/" + api_format + "-responses/bookmarks (with include)." + api_format)
ampacheConnection.bookmarks()
single_bookmark = first_id(ampacheConnection, bookmarks, 'bookmark')
# (https://raw.githubusercontent.com/ampache/python3-ampache/api6/docs/json-responses/bookmark.json)
# (https://raw.githubusercontent.com/ampache/python3-ampache/api6/docs/xml-responses/bookmark.xml)
if single_bookmark:
ampacheConnection.bookmark(single_bookmark)
if os.path.isfile("docs/" + api_format + "-responses/bookmark." + api_format):
shutil.move("docs/" + api_format + "-responses/bookmark." + api_format,
"docs/" + api_format + "-responses/bookmark (with include)." + api_format)
ampacheConnection.bookmark(single_bookmark)
else:
skipped.append('bookmark (no bookmarks on this server)')
# (https://raw.githubusercontent.com/ampache/python3-ampache/api6/docs/json-responses/bookmark_create.json)
# (https://raw.githubusercontent.com/ampache/python3-ampache/api6/docs/xml-responses/bookmark_create.xml)
ampacheConnection.bookmark_create(single_song, 'song')
ampacheConnection.get_bookmark(single_song, 'song', 1)
if os.path.isfile("docs/" + api_format + "-responses/get_bookmark." + api_format):
shutil.move("docs/" + api_format + "-responses/get_bookmark." + api_format,
"docs/" + api_format + "-responses/get_bookmark (with include)." + api_format)
mybookmark = first_id(ampacheConnection, ampacheConnection.get_bookmark(single_song, 'song'), 'bookmark')
# (https://raw.githubusercontent.com/ampache/python3-ampache/api6/docs/json-responses/bookmark_edit.json)
# (https://raw.githubusercontent.com/ampache/python3-ampache/api6/docs/xml-responses/bookmark_edit.xml)
if mybookmark:
ampacheConnection.bookmark_edit(mybookmark, 'bookmark', 10)
# (https://raw.githubusercontent.com/ampache/python3-ampache/api6/docs/json-responses/bookmark_delete)
# (https://raw.githubusercontent.com/ampache/python3-ampache/api6/docs/xml-responses/bookmark_delete)
ampacheConnection.bookmark_delete(mybookmark, 'bookmark')
else:
skipped.append('bookmark_edit, bookmark_delete (could not read back the new bookmark)')
""" def flag(type, id, flag, api_format = 'xml'):
"""
if single_playlist:
ampacheConnection.flag('playlist', single_playlist, True)
""" def rate(type, id, rating, api_format = 'xml'):
"""
ampacheConnection.rate('playlist', single_playlist, 2)
else:
skipped.append('flag, rate on a playlist (no playlists on this server)')
""" def record_play(id, user, client = 'AmpacheAPI', api_format = 'xml'):
"""
ampacheConnection.record_play(song_id, user_id, 'debug')
""" def followers(username, api_format = 'xml'):
"""
ampacheConnection.followers(username=ampache_user)
""" def following(username, api_format = 'xml'):
"""
ampacheConnection.following(ampache_user)
""" def friends_timeline(limit = 0, since = 0, api_format = 'xml'):
"""
ampacheConnection.friends_timeline(limit, 0)
""" def last_shouts(username, limit = 0, api_format = 'xml'):
"""
ampacheConnection.last_shouts(ampache_user, limit)
remove_existing(ampacheConnection, ampacheConnection.playlists(False, False, 0, 0), 'playlist',
('rename', 'documentation'), ampacheConnection.playlist_delete)
""" def playlists(filter = False, exact = False, offset = 0, limit = 0, api_format = 'xml'):
"""
ampacheConnection.playlists(False, False, offset, limit)
""" def playlist_create(name, type, api_format = 'xml'):
"""
playlist_create = ampacheConnection.playlist_create('rename', 'private')
single_playlist = first_id(ampacheConnection, playlist_create, 'playlist')
if not single_playlist:
sys.exit('ERROR: could not create a playlist on ' + ampache_url)
""" def playlist_edit(filter, name = False, type = False, api_format = 'xml'):
"""
ampacheConnection.playlist_edit(single_playlist, 'documentation', 'public')
""" def playlist_add_song(filter, song, check = 0, api_format = 'xml'):
"""
ampacheConnection.playlist_add_song(single_playlist, pick(song_ids, 1), 0)
ampacheConnection.playlist_add_song(single_playlist, pick(song_ids, 2), 0)
ampacheConnection.playlist_add_song(single_playlist, single_song, 0)
ampacheConnection.playlist_add_song(single_playlist, single_song, 1)
if os.path.isfile("docs/" + api_format + "-responses/playlist_add_song." + api_format):
shutil.move("docs/" + api_format + "-responses/playlist_add_song." + api_format,
"docs/" + api_format + "-responses/playlist_add_song (error)." + api_format)
ampacheConnection.playlist_add_song(single_playlist, single_song, 1)
ampacheConnection.playlist_add_song(single_playlist, single_song, 0)
""" def playlist_remove_song(filter, song = False, track = False, api_format = 'xml'):
playlist_add_song is deprecated and adds nothing, so fill the playlist with the
current method first or there is no track 1 to remove
"""
ampacheConnection.playlist_add(single_playlist, single_song, 'song')
ampacheConnection.playlist_remove_song(single_playlist, False, 1)
""" def playlist(filter, api_format = 'xml'):
"""
ampacheConnection.playlist(single_playlist)
""" def playlist_songs(filter, random, offset = 0, limit = 0, api_format = 'xml'):
"""
ampacheConnection.playlist_songs(single_playlist, 0, offset, limit)
""" def playlist_delete(filter, api_format = 'xml'):
"""
ampacheConnection.playlist_delete(single_playlist)
""" def playlist_generate(mode = 'random', filter = False, album = False, artist = False, flag = False, format = 'song', offset = 0, limit = 0, api_format = 'xml'):
'song'|'index'|'id'
"""
ampacheConnection.playlist_generate('random', False, False, False, False, 'song', offset, limit)
if os.path.isfile("docs/" + api_format + "-responses/playlist_generate." + api_format):
shutil.move("docs/" + api_format + "-responses/playlist_generate." + api_format,
"docs/" + api_format + "-responses/playlist_generate (song)." + api_format)
ampacheConnection.playlist_generate('random', False, False, False, False, 'index', offset, limit)
if os.path.isfile("docs/" + api_format + "-responses/playlist_generate." + api_format):
shutil.move("docs/" + api_format + "-responses/playlist_generate." + api_format,
"docs/" + api_format + "-responses/playlist_generate (index)." + api_format)
ampacheConnection.playlist_generate('random', False, False, False, False, 'id', offset, limit)
if os.path.isfile("docs/" + api_format + "-responses/playlist_generate." + api_format):
shutil.move("docs/" + api_format + "-responses/playlist_generate." + api_format,
"docs/" + api_format + "-responses/playlist_generate (id)." + api_format)
""" def scrobble(title, artist, album, MBtitle = False, MBartist = False, MBalbum = False, time = False, client = 'AmpacheAPI', api_format = 'xml'):
"""
# a song that does not exist, so this documents the error response
ampacheConnection.scrobble('Hear. Life. Spoken', 'Sub Atari Knives', 'Sub Atari Knives', False, False, False,
int(time.time()), 'debug')
if os.path.isfile("docs/" + api_format + "-responses/scrobble." + api_format):
shutil.move("docs/" + api_format + "-responses/scrobble." + api_format,
"docs/" + api_format + "-responses/scrobble (error)." + api_format)
ampacheConnection.scrobble(song_title, song_artist, song_album, False, False, False,
int(time.time()), 'debug')
""" def record_play(object_id, user, client = 'AmpacheAPI', api_format = 'xml'):
"""
ampacheConnection.record_play(single_song, ampache_user, 'debug')
""" def rate(ampache_dexesurl, ampache_api, object_type, object_id, rating, api_format = 'xml'):
"""
ampacheConnection.rate('song', single_song, 5)
ampacheConnection.rate('song', single_song, 0)
""" def flag(object_type, object_id, flag, api_format = 'xml'):
"""
ampacheConnection.flag('song', single_song, True)
ampacheConnection.flag('song', single_song, False)
""" def get_art(object_id, object_type, destination, api_format = 'xml'):
"""
ampacheConnection.get_art(single_song, 'song', (os.path.join(os.getcwd(), 'get_art.jpg')))
""" def search_songs(filter, offset = 0, limit = 0, api_format = 'xml'):
"""
search_songs = ampacheConnection.search_songs(song_filter, offset, limit)
if api_format == 'xml':
for child in search_songs:
print(child.tag, child.attrib)
for subchildren in child:
print(str(subchildren.tag) + ': ' + str(subchildren.text))
""" def song(filter, api_format = 'xml'):
"""
song = ampacheConnection.song(single_song)
if api_format == 'xml':
for child in song:
print(child.tag, child.attrib)
for subchildren in child:
print(str(subchildren.tag) + ': ' + str(subchildren.text))
""" def songs(filter = False, exact = False, add = False, update = False, offset = 0, limit = 0, api_format = 'xml'):
"""
songs = ampacheConnection.songs(False, False, False, False, offset, limit)
if api_format == 'xml':
for child in songs:
print(child.tag, child.attrib)
for subchildren in child:
print(str(subchildren.tag) + ': ' + str(subchildren.text))
""" def genres(filter = False, exact = False, offset = 0, limit = 0, api_format = 'xml'):
"""
# read a real genre name first so the documented filter matches something
genre_name = first_value(ampacheConnection, ampacheConnection.genres(False, False, offset, limit),
'genre', 'name')
tags = ampacheConnection.genres(filter_word(genre_name), False, offset, limit)
genre = first_id(ampacheConnection, tags, 'genre')
if genre:
""" def genre(filter, api_format = 'xml'):
"""
ampacheConnection.genre(genre)
""" def genre_albums(filter, offset = 0, limit = 0, api_format = 'xml'):
"""
ampacheConnection.genre_albums(genre, 0, 2)
""" def genre_artists(filter, offset = 0, limit = 0, api_format = 'xml'):
"""
ampacheConnection.genre_artists(genre, 0, 1)
""" def genre_songs(filter, offset = 0, limit = 0, api_format = 'xml'):
"""
ampacheConnection.genre_songs(genre, 0, 1)
else:
skipped.append('genre, genre_albums, genre_artists, genre_songs (no genres on this server)')
""" def licenses(filter = False, exact = False, offset = 0, limit = 0, api_format = 'xml'):
"""
licenses = ampacheConnection.licenses(False, False, offset, limit)
single_license = first_id(ampacheConnection, licenses, 'license')
""" def license(filter, api_format = 'xml'):
"""
""" def license_songs(filter, api_format = 'xml'):
"""
if single_license:
ampacheConnection.license(single_license)
ampacheConnection.license_songs(filter_id=single_license)
else:
skipped.append('license, license_songs (no licenses on this server)')
""" def podcast_create
Needs a catalog that gathers podcasts, so it only runs where one exists
"""
podcast_new = None
if podcast_catalog:
podcast_create = ampacheConnection.podcast_create(
'https://www.abc.net.au/radio/programs/trace/feed/8597522/podcast.xml', podcast_catalog)
podcast_new = first_id(ampacheConnection, podcast_create, 'podcast')
else:
skipped.append('podcast_create (no podcast catalog on this server)')
""" def podcasts(filter_str = False, exact = False, offset = 0, limit = 0, api_format = 'xml'):
"""
podcasts = ampacheConnection.podcasts(filter_str=False, exact=False, offset=0, limit=4)
single_podcast = first_id(ampacheConnection, podcasts, 'podcast')
if single_podcast:
""" def podcast(filter_str, api_format = 'xml'):
"""
ampacheConnection.podcast(single_podcast, 'episodes')
if os.path.isfile("docs/" + api_format + "-responses/podcast." + api_format):
shutil.move("docs/" + api_format + "-responses/podcast." + api_format,
"docs/" + api_format + "-responses/podcast (include episodes)." + api_format)
ampacheConnection.podcast(single_podcast, False)
""" def podcast_episodes
"""
episodes = ampacheConnection.podcast_episodes(single_podcast, offset, limit)
""" def podcast_episode
"""
single_episode = first_id(ampacheConnection, episodes, 'podcast_episode')
if single_episode:
ampacheConnection.podcast_episode(single_episode)
else:
skipped.append('podcast_episode (this podcast has no episodes)')
""" def podcast_edit(filter_str, stream, download, expires, description)
"""
ampacheConnection.podcast_edit(single_podcast)
""" def update_podcast(filter_str, api_format = 'xml'):
"""
ampacheConnection.update_podcast(single_podcast)
else:
skipped.append('podcast, podcast_episodes, podcast_episode, podcast_edit, update_podcast'
' (no podcasts on this server)')
""" def podcast_delete
Only ever removes the podcast this run created
"""
if podcast_new:
ampacheConnection.podcast_delete(podcast_new)
else:
skipped.append('podcast_delete (nothing was created to delete)')
""" share_create
"""
share_create = ampacheConnection.share_create(single_song, 'song', False, False)
share_new = first_id(ampacheConnection, share_create, 'share')
""" shares
"""
shares = ampacheConnection.shares(False, False, offset, limit)
share_id = first_id(ampacheConnection, shares, 'share')
""" share
"""
if share_id:
ampacheConnection.share(share_id)
else:
skipped.append('share (no shares on this server)')
""" share_edit
"""
""" share_delete
"""
if share_new:
ampacheConnection.share_edit(share_new, 0, 0, False, False)
ampacheConnection.share_delete(share_new)
else:
skipped.append('share_edit, share_delete (could not create a share)')
""" def timeline(username, limit = 0, since = 0, api_format = 'xml'):
"""
ampacheConnection.timeline(ampache_user, 10, 0)
""" def toggle_follow(username, api_format = 'xml'):
"""
toggle = 'generic'
if ampache_user == 'generic':
toggle = 'user'
# unfollow and refollow for timeline stuff
ampacheConnection.toggle_follow(toggle)
ampacheConnection.toggle_follow(toggle)
""" def update_from_tags(ampache_type, ampache_id, api_format = 'xml'):
"""
ampacheConnection.update_from_tags('album', single_album)
""" def update_artist_info(id, api_format = 'xml'):
"""
ampacheConnection.update_artist_info(single_artist)
""" def update_art(ampache_type, ampache_id, overwrite = False, api_format = 'xml'):
"""
ampacheConnection.update_art('artist', single_artist, True)
""" def localplay(command, api_format = 'xml'):
"""
ampacheConnection.localplay('status', False, False, 0)
if os.path.isfile("docs/" + api_format + "-responses/localplay." + api_format):
shutil.move("docs/" + api_format + "-responses/localplay." + api_format,
"docs/" + api_format + "-responses/localplay (status)." + api_format)
ampacheConnection.localplay('stop', False, False, 0)
""" def localplay_songs():
"""
ampacheConnection.localplay_songs()
""" catalogs: get all the catalogs
"""
ampacheConnection.catalogs()
""" catalog: get a catalog by id
"""
if single_catalog:
ampacheConnection.catalog(single_catalog)
else:
skipped.append('catalog (no catalogs on this server)')
""" def deleted_songs(offset = 0, limit = 0, api_format = 'xml'):
"""
ampacheConnection.deleted_songs()
""" def deleted_podcast_episodes(offset = 0, limit = 0, api_format = 'xml'):
"""
ampacheConnection.deleted_podcast_episodes()
""" def deleted_videos(offset = 0, limit = 0, api_format = 'xml'):
"""
ampacheConnection.deleted_videos()
""" def democratic(method, action, oid, api_format = 'xml'):
"""
# ampacheConnection.democratic()
""" def index(object_type, filter_str, exact, add, update, include, offset, limit, hide_search, sort, cond):
MINIMUM_API_VERSION=8.0.0 for the album_disk type
"""
ampacheConnection.index(object_type='album_disk', offset=offset, limit=limit)
if os.path.isfile("docs/" + api_format + "-responses/index." + api_format):
shutil.move("docs/" + api_format + "-responses/index." + api_format,
"docs/" + api_format + "-responses/index (album_disk)." + api_format)
""" def list(object_type, filter_str, exact, add, update, offset, limit):
"""
ampacheConnection.list(object_type='album', offset=offset, limit=limit)
""" def browse(filter_str, object_type, catalog, add, update, offset, limit):
"""
ampacheConnection.browse()
""" def get_similar(object_type, filter_id, offset, limit):
"""
ampacheConnection.get_similar('song', single_song, offset, limit)
""" def album_disks(filter_id, include, offset, limit, sort, cond):
MINIMUM_API_VERSION=8.0.0
"""
album_disks = ampacheConnection.album_disks(single_album, False, offset, limit)
disk_list = id_list(ampacheConnection, album_disks, 'album_disk')
""" def album_disk(filter_id, include):
MINIMUM_API_VERSION=8.0.0
"""
if disk_list:
single_disk = disk_list[0]
ampacheConnection.album_disk(single_disk, False)
ampacheConnection.album_disk(single_disk, True)
if os.path.isfile("docs/" + api_format + "-responses/album_disk." + api_format):
shutil.move("docs/" + api_format + "-responses/album_disk." + api_format,
"docs/" + api_format + "-responses/album_disk (with include)." + api_format)
""" def album_disk_songs(filter_id, offset, limit, sort, cond):
MINIMUM_API_VERSION=8.0.0
"""