Browse code

Adds new backend/interface directories

Jaidyn Levesque authored on 2018-09-09 15:32:12
Showing 7 changed files
1 1
new file mode 100644
2 2
new file mode 100644
... ...
@@ -0,0 +1,27 @@
1
+#!/bin/sh
2
+
3
+# This file is free software, go thank RMS
4
+## PRAISE RMS, LORD AND SAVIOR
5
+
6
+#==============================
7
+#         BASIC URL          #
8
+#==============================
9
+
10
+# TYPE_URL PARAMS -> URL
11
+# Outputs a url string with type_of_url and parameters
12
+# this function won't check if type_url or params are valid
13
+function output_url_string {
14
+    local BASEURL="https://api.jamendo.com/v3.0/"
15
+    local Type_Url="$1"
16
+    local url_Type="$BASEURL$Type_Url"
17
+    
18
+    local CLIENTID="?client_id=73efbf98&"
19
+    local FORMAT="format=jsonpretty&"
20
+    local client_Format="$CLIENTID$FORMAT"
21
+
22
+    local params="$2"
23
+
24
+    echo "$url_Type$client_Format$params"
25
+}
26
+
27
+
... ...
@@ -4,6 +4,7 @@
4 4
 #        LIBRARIES          #
5 5
 #==============================
6 6
 . ./lib/mj-lib.sh
7
+. ./lib/playlist.sh
7 8
 
8 9
 #==============================
9 10
 #        CONSTANTS          #
... ...
@@ -3,6 +3,7 @@
3 3
 # name: lib.sh
4 4
 ####################
5 5
 
6
+#**
6 7
 # https://stackoverflow.com/questions/1831527/simple-way-to-colour-alternate-output-lines-in-bash
7 8
 # LIST -> COLORIZED LIST
8 9
 # outputs a list with differnt colors for even and odd lines
... ...
@@ -17,9 +18,10 @@ function color_output
17 18
     echo -en "\033[0m"
18 19
 }
19 20
 
21
+#**
20 22
 # URL -> stdout 
21 23
 # downloads URL as text to standard output
22
-function download_std
24
+function download_stdout
23 25
 {
24 26
 	if whereis "curl" > /dev/null
25 27
 ## ohhh, you could use the above function!
... ...
@@ -34,6 +36,7 @@ function download_std
34 36
 	fi
35 37
 }
36 38
 
39
+#**
37 40
 # usage: if_nonreal_create root_path filenames[]
38 41
 # ROOTPATH LISTofFILENAMES -> FILES
39 42
 # Checks if FILENAME(s) exist in ROOT_PATH--
... ...
@@ -54,6 +57,7 @@ function if_nonreal_create
54 57
 	done
55 58
 }
56 59
 
60
+#**
57 61
 # usage: is_dir filenames[]
58 62
 # LIST of FILENAMES -> 0 or 1
59 63
 # Returns 0 if FILENAME(s) is name of directory
... ...
@@ -72,6 +76,7 @@ function is_dir
72 76
 }
73 77
 
74 78
 
79
+#**
75 80
 # VALUE NUMBER -> NUMBER
76 81
 # returns a number
77 82
 function return_valid_number {
... ...
@@ -81,7 +86,20 @@ function return_valid_number {
81 86
     esac
82 87
 }
83 88
 
89
+#**
90
+### WRITE THIS
91
+# VALUE STRING -> STRING
92
+# returns a string
93
+#function return_valid_string {
94
+#    case "$1" in
95
+#    ''|*[!0-9]*) echo "$2" ;;
96
+#    *) echo "$1" ;;
97
+#    esac
98
+#}
84 99
 
100
+
101
+
102
+#**
85 103
 # MULTI-LINE_STRING NUMBER -> SINGLE-LINE_STRING
86 104
 # return line number of string
87 105
 function get_line {
... ...
@@ -94,11 +112,13 @@ function get_line {
94 112
 
95 113
 
96 114
 
115
+#**
97 116
 function tab_seperate {
98 117
     	printf "%s\t%s\n" "$1" "$2"
99 118
 
100 119
 }
101 120
 
121
+#**
102 122
 # NUMBER NUMBER -> NUMBER
103 123
 # increment a number by $2
104 124
 function increment {
... ...
@@ -113,6 +133,7 @@ function increment {
113 133
 	echo "$number + $increment" | bc
114 134
 }
115 135
 
136
+#**
116 137
 # STRINGS -> TAB_SEPERATED_LIST
117 138
 # combine two strings (equal length) into a single tab-seperated list
118 139
 function conjoin_strings {
... ...
@@ -42,7 +42,7 @@ function output_playlists_url {
42 42
 function get_user_playlists {
43 43
     local user_id="$1"
44 44
     local limit="$2"
45
-    download_std "$(output_playlists_url $user_id $limit)"
45
+    download_stdout "$(output_playlists_url $user_id $limit)"
46 46
 }
47 47
 
48 48
 
... ...
@@ -100,7 +100,7 @@ function output_1playlist_url {
100 100
 # get_1playlist 500432775
101 101
 function get_1playlist {
102 102
     local playlist_id="$1"
103
-    download_std "$(output_1playlist_url $playlist_id)"
103
+    download_stdout "$(output_1playlist_url $playlist_id)"
104 104
 }
105 105
 
106 106
 # 1PLAYLIST_JSON -> ListOfSongsURLS
107 107
new file mode 100644
... ...
@@ -0,0 +1,148 @@
1
+#!/bin/sh
2
+
3
+# This file is free software, go thank RMS
4
+## PRAISE RMS, LORD AND SAVIOR
5
+
6
+#==============================
7
+#         PLAYLISTS         #
8
+#==============================
9
+
10
+#------------------------------
11
+# PLAYLIST LISTS
12
+#------------------------------
13
+
14
+### CAN BE ABSTRACTED FURTHER
15
+# QUERY -> PLAYLIST_SEARCH_URL
16
+# Generate the URL of a playlist query
17
+function gen_pl_query_url {
18
+        local query="$1"
19
+
20
+ 	local URL="https://api.jamendo.com/v3.0/playlists/"
21
+	local URL="${URL}?client_id=73efbf98&format=jsonpretty"
22
+	local URL="${URL}&order=creationdate_desc&limit=20"
23
+	local URL="${URL}${query}"
24
+
25
+	echo "$URL"
26
+	return
27
+}
28
+
29
+# QUERY -> PLAYLIST_SERACH_JSON
30
+# Fetch search results of a query; JSON list of playlists
31
+function pl_query {
32
+	local query="$1"
33
+
34
+	download_stdout "$(gen_pl_query_url "$query")"
35
+	return
36
+}
37
+	
38
+
39
+# USER_ID LIMIT-> USER_PLAYLISTS_JSON
40
+# Outputs JSON of playlists created by user
41
+function user_playlists {
42
+	local user_id="$1"
43
+	
44
+	pl_query "&user_id=${user_id}"
45
+	return
46
+}
47
+
48
+
49
+#**
50
+# PLAYLISTS_JSON VALUE -> LIST OF VALUES
51
+# Outputs a list of values from a JSON
52
+#### get json_value
53
+function get_pl_query_value {
54
+	local value="$1"
55
+	local json="$2"
56
+
57
+	echo "$json"   \
58
+	| jq ".results[] | .$value"   ## .${json}
59
+	return
60
+}
61
+
62
+
63
+#**
64
+# PLAYLISTS_JSON -> LIST OF NAMES
65
+# Outputs list of names without double quotes
66
+function get_pl_query_name {
67
+	local json="$1"
68
+
69
+	get_pl_query_value "name" "$json"       \
70
+	| sed 's/\"//g'                    
71
+	return
72
+}
73
+
74
+
75
+#**
76
+# PLAYLISTS_JSON -> LIST OF IDS
77
+# Outputs list of ids without double quotes
78
+function get_pl_query_id {
79
+	local json="$1"
80
+
81
+	get_pl_query_value "id" "$json"       \
82
+	| sed 's/\"//g'                    
83
+	return
84
+}
85
+
86
+
87
+#**
88
+# PLAYLIST_ID -> PLAYLIST_TRACKS_URL
89
+# Outputs URL of a single playlist
90
+# playlist_url 500432775
91
+function gen_pl_url {
92
+	local playlist_id="$1"
93
+
94
+	local URL="https://api.jamendo.com/v3.0/playlists/tracks/"
95
+	local URL="${URL}?client_id=73efbf98&format=jsonpretty&"
96
+	local URL="${URL}audioformat=ogg&track_type=single+albumtrack"
97
+	local URL="${URL}&id=$playlist_id"
98
+
99
+	echo "$URL"
100
+	return
101
+}
102
+
103
+
104
+#**
105
+# PLAYLIST_ID -> PLAYLIST_JSON
106
+# outputs JSON of single playlist
107
+# get_playlist 500432775
108
+function get_playlist {
109
+    local playlist_id="$1"
110
+
111
+    download_stdout "$(gen_pl_url $playlist_id)"
112
+}
113
+
114
+
115
+#**
116
+# PLAYLIST_JSON -> ListOfSongsURLS
117
+# outputs List of URLS of songs (without double quotes)
118
+# songs_of_1playlist "$(get_1playlist 500432775)"
119
+function get_pl_track_value {
120
+	local value="$1"
121
+	local json="$2"
122
+
123
+	echo "$json"   \
124
+	| jq ".results[] | .tracks[] | .$value" \
125
+	| sed 's/\"//g'                    
126
+}
127
+
128
+
129
+#**
130
+# PLAYLIST_JSON -> ListOfSongsURLS
131
+# outputs List of URLS of songs (without double quotes)
132
+# songs_of_1playlist "$(get_1playlist 500432775)"
133
+function playlist_track_url {
134
+	local json="$1"
135
+
136
+	get_pl_track_value "audio"
137
+	return
138
+}
139
+
140
+#**
141
+# PLAYLIST_JSON -> ListOfSongsNAMES
142
+# outputs List of names of songs (without double quotes)
143
+function playlist_track_name {
144
+	local json="$1"
145
+
146
+	get_pl_track_value "name"
147
+	return
148
+}
0 149
new file mode 100755
... ...
@@ -0,0 +1,30 @@
1
+#! /bin/sh
2
+# file: examples/equality_test.sh
3
+## load mj-lib.sh
4
+
5
+########################################
6
+####       TEST INTERFACE          ####
7
+########################################
8
+
9
+#==============================
10
+#   TEST SIMPLE COMMANDS     #
11
+#==============================
12
+
13
+test_print_version() {
14
+    local expected_string="https://api.jamendo.com/v3.0/playlists/tracks/?client_id=73efbf98&format=jsonpretty&id=500423230&"
15
+    
16
+    local function_string="$(output_url_string "playlists/tracks/" "id=500423230&")"
17
+
18
+    assertEquals "$expected_string"  "$function_string"
19
+}
20
+
21
+
22
+oneTimeSetUp() {
23
+    # load my-jam.sh
24
+##    . ../lib/lib.sh 
25
+    . ../../../lib/backend/jamendo/urls.sh 
26
+}
27
+
28
+
29
+. ../../../lib/shunit2 
30
+