public async Task Process(WallabagClient client, WallabagItem item) { foreach (var mapping in mappings) { // Not a matching entry if (!item.Url.Contains(mapping.domain)) { continue; } // Already tagged if (item.Tags.Any(t => t.Label == mapping.tag)) { continue; } Console.Write(item.Title.Replace("\n", " ")); await client.AddTagsAsync(item, new[] { mapping.tag }); Console.WriteLine($" {mapping.tag} ✓"); } }
public async Task Process(WallabagClient client, WallabagItem item) { bool filter_match = false; String url = null; foreach (var filter in config.url_filter) { // Prefer matches on OriginalUrl if (!String.IsNullOrWhiteSpace(item.OriginalUrl) && item.OriginalUrl.Contains(filter)) { filter_match = true; url = item.OriginalUrl; break; } if (item.Url.Contains(filter)) { filter_match = true; url = item.Url; break; } } // Not from a matching domain if (!filter_match) { return; } foreach (var bl in blacklist) { if (url.Contains(bl)) { var oldurl = url; url = extract_yt_lastditch(url); if (url == null) { Console.WriteLine($"Warning: YoutubeProcessor detected blacklisted pattern; skipping {oldurl}"); } else { Console.WriteLine($"Info: YoutubeProcessor detected blacklisted pattern; extracted {url} from {oldurl}"); } return; } } // Already tagged if (item.Tags.Any(t => t.Label == config.tag_name)) { return; } Console.Write(item.Title.Replace("\n", " ")); // Send DL request to Youtube-DL-Server var content = new FormUrlEncodedContent(new[] { new KeyValuePair <string, string>("url", url), new KeyValuePair <string, string>("format", config.format), }); try { var dl_request = await fetcher.PostAsync(config.youtube_dl_server, content); if (dl_request.StatusCode != System.Net.HttpStatusCode.OK) { Console.WriteLine($" ✗ yt-dl-server returned error response"); return; } var response = await dl_request.Content.ReadAsStringAsync(); await client.AddTagsAsync(item, new[] { config.tag_name }); if (config.mark_read) { await client.ArchiveAsync(item); } Console.WriteLine($" ✓"); } catch (Exception e) { Console.WriteLine($"Error submitting {url}\n{e.ToString()}\n{e.StackTrace.ToString()}"); } }