1
1
package mServer .crawler .sender .arte ;
2
2
3
- import com .google .gson .JsonDeserializationContext ;
4
- import com .google .gson .JsonDeserializer ;
5
- import com .google .gson .JsonElement ;
6
- import com .google .gson .JsonObject ;
3
+ import com .google .gson .*;
7
4
import mServer .crawler .sender .base .Qualities ;
8
5
import org .apache .logging .log4j .LogManager ;
9
6
import org .apache .logging .log4j .Logger ;
10
7
11
8
import java .lang .reflect .Type ;
12
- import java .time .Duration ;
13
- import java .util .Map ;
14
9
import java .util .Optional ;
15
- import java .util .Set ;
16
10
17
11
public class ArteVideoDeserializer
18
12
implements JsonDeserializer <ArteVideoDTO > {
19
13
20
14
private static final Logger LOG = LogManager .getLogger (ArteVideoDeserializer .class );
21
15
22
- private static final String JSON_OBJECT_KEY_PLAYER = "videoJsonPlayer" ;
23
- private static final String JSON_OBJECT_KEY_VSR = "VSR" ;
24
- private static final String ATTRIBUTE_DURATION = "videoDurationSeconds" ;
16
+ private static final String JSON_OBJECT_KEY_PLAYER = "videoStreams" ;
25
17
private static final String ATTRIBUTE_URL = "url" ;
26
18
private static final String ATTRIBUTE_QUALITY = "quality" ;
27
- private static final String ATTRIBUTE_VERSION_CODE = "versionCode " ;
19
+ private static final String ATTRIBUTE_VERSION_CODE = "audioCode " ;
28
20
29
21
private final String sender ;
30
22
@@ -38,29 +30,13 @@ public ArteVideoDTO deserialize(
38
30
ArteVideoDTO arteVideoDTO = new ArteVideoDTO ();
39
31
if (aJsonElement .isJsonObject ()
40
32
&& aJsonElement .getAsJsonObject ().has (JSON_OBJECT_KEY_PLAYER )
41
- && aJsonElement .getAsJsonObject ().get (JSON_OBJECT_KEY_PLAYER ).isJsonObject ()
42
- && aJsonElement
43
- .getAsJsonObject ()
44
- .get (JSON_OBJECT_KEY_PLAYER )
45
- .getAsJsonObject ()
46
- .has (JSON_OBJECT_KEY_VSR )
47
- && aJsonElement
48
- .getAsJsonObject ()
49
- .get (JSON_OBJECT_KEY_PLAYER )
50
- .getAsJsonObject ()
51
- .get (JSON_OBJECT_KEY_VSR )
52
- .isJsonObject ()) {
53
- JsonObject playerObject =
54
- aJsonElement .getAsJsonObject ().get (JSON_OBJECT_KEY_PLAYER ).getAsJsonObject ();
55
- JsonObject vsrJsonObject = playerObject .get (JSON_OBJECT_KEY_VSR ).getAsJsonObject ();
33
+ && aJsonElement .getAsJsonObject ().get (JSON_OBJECT_KEY_PLAYER ).isJsonArray ()) {
34
+ JsonArray videoStreams =
35
+ aJsonElement .getAsJsonObject ().get (JSON_OBJECT_KEY_PLAYER ).getAsJsonArray ();
56
36
57
- final long duration = playerObject .has (ATTRIBUTE_DURATION ) ? playerObject .get (ATTRIBUTE_DURATION ).getAsLong () : 0 ;
58
- arteVideoDTO .setDuration (Duration .ofSeconds (duration ));
59
-
60
- final Set <Map .Entry <String , JsonElement >> entries = vsrJsonObject .entrySet ();
61
- entries .forEach (
37
+ videoStreams .forEach (
62
38
entry -> {
63
- final JsonObject value = entry .getValue (). getAsJsonObject ();
39
+ final JsonObject value = entry .getAsJsonObject ();
64
40
65
41
final String code = value .get (ATTRIBUTE_VERSION_CODE ).getAsString ();
66
42
final String quality = value .get (ATTRIBUTE_QUALITY ).getAsString ();
0 commit comments