· 5 years ago · Jan 18, 2021, 05:24 PM
1if ($this->isGranted('IS_AUTHENTICATED_FULLY'))
2 {
3 $episodes_collection = $saison->getEpisodes();
4 $db_links_doodstream_vf = [];
5 $db_links_doodstream_vostfr = [];
6 $links = [];
7 $ids = [];
8 $i_vf = 0;
9 $i_vostfr = 0;
10 $folder_saison_ids = [
11 "S01" => "37559",
12 "S02" => "37560",
13 "S03" => "37561",
14 "S04" => "37562",
15 "S05" => "37563",
16 "S06" => "37564",
17 "S07" => "37565"];
18 $folder_id = "";
19 $links_doodstream_vf2 = [];
20 $links_doodstream_vostfr2 = [];
21
22 if ($saison->getId() >= 10){
23 $model = "#S" . $saison->getId() . "#";
24 $folder_id = $folder_saison_ids["S" . $saison->getId()];
25 }
26 if ($saison->getId() < 10){
27 $model = "#S0" . $saison->getId() . "#";
28 $folder_id = $folder_saison_ids["S0" . $saison->getId()];
29 }
30
31 foreach ($episodes_collection as $episode)
32 {
33 $db_links_doodstream_vf[$episode->getId()] = $episode->getOpenloadLinkVf();
34 $db_links_doodstream_vostfr[$episode->getId()] = $episode->getOpenloadLinkVostfr();
35 $ids[] = $episode->getId();
36
37 }
38 if (count($db_links_doodstream_vostfr) > 0 && count($db_links_doodstream_vf) > 0)
39 {
40 ksort($db_links_doodstream_vf);
41 ksort($db_links_doodstream_vostfr);
42 }
43
44 $curl = new Curl();
45 $fileInfo = $curl->get('https://doodapi.com/api/folder/list',[
46 'key' => '6449trbpjc3kcir0rl0j',
47 'fld_id' => $folder_id
48 ]);
49
50 $files = json_decode($fileInfo->getResponse(), true);
51 $array_files = $files["result"]["files"];
52
53 if(is_array($array_files) && count($array_files) > 0)
54 {
55 foreach ($array_files as $key => $value)
56 {
57 $links[$value["title"]] = "https://dood.to/e/" . $value["file_code"];
58 }
59 ksort($links);
60 //return dump($links);
61 if (count($links) > 0)
62 {
63 foreach ($links as $key => $value)
64 {
65 if (preg_match("#VOSTFR#", $key))
66 {
67 $links_doodstream_vostfr2[$ids[$i_vostfr++]] = $value;
68 }
69 if (preg_match("#VF#", $key))
70 {
71 $links_doodstream_vf2[$ids[$i_vf++]] = $value;
72 }
73 }
74 if (count($links_doodstream_vf2) > 0 && count($links_doodstream_vostfr2) > 0)
75 {
76 if($db_links_doodstream_vf !== $links_doodstream_vf2 && $db_links_doodstream_vostfr !== $links_doodstream_vostfr2)
77 {
78
79 foreach ($links_doodstream_vostfr2 as $key => $value)
80 {
81 $episode = $this->episodeRepository->find($key);
82 $episode->setOpenloadLinkVostfr($value);
83 $this->em->persist($episode);
84 }
85 foreach ($links_doodstream_vf2 as $key => $value)
86 {
87 $episode = $this->episodeRepository->find($key);
88 $episode->setOpenloadLinkVf($value);
89 $this->em->persist($episode);
90 }
91
92 $this->em->flush();
93 $this->addFlash('success', 'Les liens DOODSTREAM pour la ' . strtoupper($saison->getName()). ' ont été edités!');
94 return $this->redirectToRoute("admin.saisons.index");
95 }
96 else{
97 $this->addFlash('warning', 'Les liens DOODSTREAM pour la ' . strtoupper($saison->getName()). ' sont déjà à jour!');
98 return $this->redirectToRoute("admin.saisons.index");
99 }
100 }
101 }
102 }
103 else{
104 $this->addFlash('error', 'Les liens DOODSTREAM pour la ' . strtoupper($saison->getName()) . ' ont pas été edités! (too many request vers API 3max each 2-3mins)');
105 return $this->redirectToRoute("admin.saisons.index");
106 }
107 }
108 return $this->redirectToRoute('home');