MCPcopy Create free account
hub / github.com/Cpasjuste/pplay / scrap_thread

Function scrap_thread

src/scrapper/scrapper.cpp:77–144  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

75}
76
77static int scrap_thread(void *ptr) {
78
79 auto scrapper = (Scrapper *) ptr;
80 auto main = scrapper->main;
81
82 while (scrapper->running) {
83
84 scrapper->mutex->lock();
85 scrapper->cond->wait(scrapper->mutex);
86
87#ifdef __SWITCH__
88 appletSetMediaPlaybackState(true);
89#endif
90 if (scrapper->running) {
91
92 scrapper->scrapping = true;
93 main->getStatus()->show("Scrapping...", "Building media list...", true);
94
95 c2d::C2DClock clock;
96
97 scrapList.clear();
98 find_medias(main, scrapper->path);
99
100 size_t size = scrapList.size();
101 for (size_t i = 0; i < size; i++) {
102
103 if (!main->getScrapper()->running) {
104 break;
105 }
106
107 c2d::Io::File file = scrapList.at(i);
108 std::string scrap_path = pplay::Utility::getMediaScrapPath(file);
109 if (!main->getIo()->exist(scrap_path)) {
110 std::string title = "Scrapping... (" + std::to_string(i) + "/" + std::to_string(size) + ")";
111 main->getStatus()->show(title, "Searching: " + file.name, true);
112 std::string lang = main->getConfig()->getOption(OPT_TMDB_LANGUAGE)->getString();
113 Search search(API_KEY, clean_name(file.name), lang);
114 int res = search.get();
115 if (res == 0) {
116 search.save(scrap_path);
117 if (search.total_results > 0) {
118 main->getStatus()->show(title, "Downloading poster: "
119 + search.movies.at(0).title, true);
120 search.movies.at(0).getPoster(pplay::Utility::getMediaPosterPath(file));
121 main->getStatus()->show(title, "Downloading backdrop: "
122 + search.movies.at(0).title, true);
123 search.movies.at(0).getBackdrop(pplay::Utility::getMediaBackdropPath(file), 780);
124 // refresh ui now
125 main->getFiler()->setScrapInfo(file, search.movies);
126 }
127 }
128 }
129 }
130
131 scrapper->main->getStatus()->show(
132 "Scrapping...", "Done in "
133 + pplay::Utility::formatTime(clock.getElapsedTime().asSeconds()));
134 scrapper->scrapping = false;

Callers

nothing calls this directly

Calls 12

find_mediasFunction · 0.85
to_stringFunction · 0.85
clean_nameFunction · 0.85
getStatusMethod · 0.80
getScrapperMethod · 0.80
getConfigMethod · 0.80
setScrapInfoMethod · 0.80
getFilerMethod · 0.80
showMethod · 0.45
clearMethod · 0.45
sizeMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected