From 810ce23ed2af8771593a9e32b263369a8ce74a1b Mon Sep 17 00:00:00 2001 From: IllusionMan1212 Date: Mon, 26 May 2025 02:01:27 +0200 Subject: [PATCH] helper functions One for getting the channel id from a user handle. Another for getting the members playlist id from the channel id. This is in preparation for making the program function as a quick way to get ids to pass to yt-dlp to get json data of videos, which in turn will be fed to the program to determine which videos are missing from an archive --- main.go | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 3e1ce33..a047aae 100644 --- a/main.go +++ b/main.go @@ -5,7 +5,11 @@ import ( "encoding/json" "flag" "fmt" + "io" + "log" + "net/http" "os" + "regexp" "sort" "strings" ) @@ -75,6 +79,32 @@ func CategoryFlag(name string, value Category, usage string) *Category { return &c } +func getChannelID(handle string) string { + resp, err := http.Get(fmt.Sprintf("https://www.youtube.com/%s", handle)) + if err != nil { + log.Fatal(err) + } + + body, err := io.ReadAll(resp.Body) + if err != nil { + log.Fatal(err) + } + + re := regexp.MustCompile(`]*property=["']og:url["'][^>]*content=["']([^"']+)["']`) + + results := re.FindAllStringSubmatch(string(body), -1) + parsedUrl := results[0][1] + + splits := strings.Split(parsedUrl, "/") + channelID := splits[len(splits)-1] + + return channelID +} + +func getMembersPlaylistID(channelID string) string { + return fmt.Sprintf("UUMO%s", channelID[2:]) +} + func main() { cat := CategoryFlag("category", All, "Category of videos to check against.\nValid options are all, shorts, video, livestream, membership") dumpToFile := flag.Bool("dump-to-file", false, "The program will dump the missing IDs to a file that can be used with yt-dlp") @@ -195,7 +225,7 @@ func main() { if len(missingMetadata) == 0 { fmt.Printf("Found %d IDs. No missing IDs. Congrats\n", len(existingIds)) } else { - fmt.Printf("Found %d IDs. Still missing %d IDs. For a total of %d IDs\n", len(existingIds), len(allMetadata)-(len(existingIds) - len(extraIds)), len(allMetadata)) + fmt.Printf("Found %d IDs. Still missing %d IDs. For a total of %d IDs\n", len(existingIds), len(allMetadata)-(len(existingIds)-len(extraIds)), len(allMetadata)) fmt.Println("Missing Videos are:") fmt.Println(missingMetadata)