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
This commit is contained in:
2025-05-26 02:01:27 +02:00
parent cbf185e111
commit 810ce23ed2
+30
View File
@@ -5,7 +5,11 @@ import (
"encoding/json" "encoding/json"
"flag" "flag"
"fmt" "fmt"
"io"
"log"
"net/http"
"os" "os"
"regexp"
"sort" "sort"
"strings" "strings"
) )
@@ -75,6 +79,32 @@ func CategoryFlag(name string, value Category, usage string) *Category {
return &c 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(`<meta[^>]*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() { func main() {
cat := CategoryFlag("category", All, "Category of videos to check against.\nValid options are all, shorts, video, livestream, membership") 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") dumpToFile := flag.Bool("dump-to-file", false, "The program will dump the missing IDs to a file that can be used with yt-dlp")