mirror of
https://github.com/IllusionMan1212/yt-db-completer.git
synced 2026-10-24 10:12:27 +00:00
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:
@@ -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(`<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() {
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user