get_cache_path

Function get_cache_path 

Source
pub fn get_cache_path(player: &str, variant: &str) -> String
Expand description

Get cache path for a player file

Examples found in repository?
examples/download_players.rs (line 19)
9fn main() {
10    let player_paths = get_player_paths();
11    let mut downloaded = 0;
12    let mut skipped = 0;
13    let mut failed = 0;
14
15    for test_case in TEST_CASES {
16        let variants = test_case.variants.unwrap_or(ALL_VARIANTS);
17
18        for variant in variants {
19            let cache_path = get_cache_path(test_case.player, variant);
20            let path = Path::new(&cache_path);
21
22            if path.exists() {
23                skipped += 1;
24                continue;
25            }
26
27            // Create parent directory if it doesn't exist
28            if let Some(parent) = path.parent()
29                && !parent.exists()
30                && let Err(e) = fs::create_dir_all(parent)
31            {
32                eprintln!("Failed to create directory {:?}: {}", parent, e);
33                failed += 1;
34                continue;
35            }
36
37            let Some(player_path) = player_paths.get(variant) else {
38                eprintln!("Unknown variant: {}", variant);
39                failed += 1;
40                continue;
41            };
42
43            let url = format!(
44                "https://www.youtube.com/s/player/{}/{}",
45                test_case.player, player_path
46            );
47
48            println!("Downloading: {}", url);
49
50            match download_file(&url, &cache_path) {
51                Ok(_) => {
52                    println!("  -> Saved to {}", cache_path);
53                    downloaded += 1;
54                }
55                Err(e) => {
56                    eprintln!("  -> Failed: {}", e);
57                    failed += 1;
58                }
59            }
60        }
61    }
62
63    println!();
64    println!("Summary:");
65    println!("  Downloaded: {}", downloaded);
66    println!("  Skipped (already exists): {}", skipped);
67    println!("  Failed: {}", failed);
68}
More examples
Hide additional examples
examples/generate_csv.rs (line 37)
12fn main() {
13    let args: Vec<String> = env::args().collect();
14
15    // Parse output file argument
16    let output_file = if args.len() >= 3 && args[1] == "--output" {
17        Some(&args[2])
18    } else {
19        None
20    };
21
22    let mut output: Box<dyn Write> = match output_file {
23        Some(path) => {
24            let file = File::create(path).expect("Failed to create output file");
25            Box::new(file)
26        }
27        None => Box::new(io::stdout()),
28    };
29
30    let mut count = 0;
31    let mut missing = 0;
32
33    for test_case in TEST_CASES {
34        let variants = test_case.variants.unwrap_or(ALL_VARIANTS);
35
36        for variant in variants {
37            let cache_path = get_cache_path(test_case.player, variant);
38            let path = Path::new(&cache_path);
39
40            // Check if player file exists
41            if !path.exists() {
42                missing += 1;
43                continue;
44            }
45
46            let filename = format!("{}-{}", test_case.player, variant);
47
48            // Export n tests (space-separated)
49            for step in test_case.n {
50                writeln!(output, "{} n {} {}", filename, step.input, step.expected)
51                    .expect("Failed to write");
52                count += 1;
53            }
54
55            // Export sig tests (space-separated)
56            for step in test_case.sig {
57                writeln!(output, "{} sig {} {}", filename, step.input, step.expected)
58                    .expect("Failed to write");
59                count += 1;
60            }
61        }
62    }
63
64    if count == 0 {
65        eprintln!("Error: No player files found!");
66        eprintln!();
67        eprintln!("Please download player files first:");
68        eprintln!("  cargo run --example download_players");
69        std::process::exit(1);
70    }
71
72    if missing > 0 {
73        eprintln!(
74            "Warning: {} player variants not found, run 'cargo run --example download_players' to download",
75            missing
76        );
77    }
78
79    if output_file.is_some() {
80        eprintln!("Exported {} test cases", count);
81    }
82}