Browse Source

Merge pull request #150 from tsoding/unhardcode-channel

Unhardcode channel
Alexey Kutepov 4 years ago
parent
commit
a0d7a06047
3 changed files with 37 additions and 7 deletions
  1. 3 3
      .github/workflows/ci.yml
  2. 1 1
      README.md
  3. 33 3
      src/emote_downloader.cpp

+ 3 - 3
.github/workflows/ci.yml

@@ -26,7 +26,7 @@ jobs:
       - name: build vodus
       - name: build vodus
         run: |
         run: |
           make -B
           make -B
-          ./emote_downloader
+          ./emote_downloader tsoding 110240192
           make render
           make render
           pushd ./test/pajaWalk/
           pushd ./test/pajaWalk/
           ./test.sh
           ./test.sh
@@ -64,7 +64,7 @@ jobs:
       - name: build vodus
       - name: build vodus
         run: |
         run: |
           make -B
           make -B
-          ./emote_downloader
+          ./emote_downloader tsoding 110240192
           make render
           make render
           pushd ./test/pajaWalk/
           pushd ./test/pajaWalk/
           ./test.sh
           ./test.sh
@@ -104,7 +104,7 @@ jobs:
       - name: build vodus
       - name: build vodus
         run: |
         run: |
           make -B
           make -B
-          ./emote_downloader
+          ./emote_downloader tsoding 110240192
           make render
           make render
           pushd ./test/pajaWalk/
           pushd ./test/pajaWalk/
           ./test.sh
           ./test.sh

+ 1 - 1
README.md

@@ -48,7 +48,7 @@ $ make
 ### Download Emotes
 ### Download Emotes
 
 
 ```console
 ```console
-$ ./emote_downloader
+$ ./emote_downloader <channel-name> <channel-id>
 ```
 ```
 
 
 ### Render the Sample Video
 ### Render the Sample Video

+ 33 - 3
src/emote_downloader.cpp

@@ -435,8 +435,28 @@ void create_all_directories(Path dirpath)
 
 
 Fixed_Array<Curl_Download, 1024> downloads;
 Fixed_Array<Curl_Download, 1024> downloads;
 
 
-int main(void)
+void usage(FILE *stream)
 {
 {
+    println(stdout, "./emote_downloader <channel-name> <channel-id>");
+}
+
+int main(int argc, char **argv)
+{
+    Args args = {argc, argv};
+    args.shift();               // skip program name
+
+    if (args.empty()) {
+        usage(stderr);
+        panic("ERROR: channel-name is not provided");
+    }
+    auto channel_name = args.shift();
+
+    if (args.empty()) {
+        usage(stderr);
+        panic("ERROR: channel-id is not provided");
+    }
+    auto channel_id = args.shift();
+
     curl_global_init(CURL_GLOBAL_DEFAULT);
     curl_global_init(CURL_GLOBAL_DEFAULT);
     defer(curl_global_cleanup());
     defer(curl_global_cleanup());
 
 
@@ -463,10 +483,20 @@ int main(void)
 
 
     curl_multi_setopt(cm, CURLMOPT_MAXCONNECTS, MAX_PARALLEL);
     curl_multi_setopt(cm, CURLMOPT_MAXCONNECTS, MAX_PARALLEL);
 
 
+    char channel_url_buffer[1024];
+    String_Buffer channel_url = {sizeof(channel_url_buffer), channel_url_buffer};
+
     append_global_bttv_mapping(curl, "https://api.betterttv.net/3/cached/emotes/global", mapping, &downloads);
     append_global_bttv_mapping(curl, "https://api.betterttv.net/3/cached/emotes/global", mapping, &downloads);
-    append_channel_bttv_mapping(curl, "https://api.betterttv.net/3/cached/users/twitch/110240192", mapping, &downloads);
+
+    sprint(&channel_url, "https://api.betterttv.net/3/cached/users/twitch/", channel_id);
+    append_channel_bttv_mapping(curl, channel_url.data, mapping, &downloads);
+    channel_url.size = 0;
+
     append_global_ffz_mapping(curl, mapping, &downloads);
     append_global_ffz_mapping(curl, mapping, &downloads);
-    append_room_ffz_mapping(curl, "https://api.frankerfacez.com/v1/room/tsoding", mapping, &downloads);
+
+    sprint(&channel_url, "https://api.frankerfacez.com/v1/room/", channel_name);
+    append_room_ffz_mapping(curl, channel_url.data, mapping, &downloads);
+    channel_url.size = 0;
 
 
     size_t transfers = 0;
     size_t transfers = 0;
     for (transfers = 0; transfers < min(downloads.size, MAX_PARALLEL); ++transfers) {
     for (transfers = 0; transfers < min(downloads.size, MAX_PARALLEL); ++transfers) {