Skip to content

Commit

Permalink
Application should now work with the new IMDb HTML website code.
Browse files Browse the repository at this point in the history
  • Loading branch information
samsalmag committed Mar 26, 2022
1 parent 8620f0d commit 20f6168
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 33 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.zemahzalek</groupId>
<groupId>com.samsalek</groupId>
<artifactId>ratingreader</artifactId>
<version>${dev.version}</version>
<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ public void fetchImdbWebsiteCode(String searchTerm) throws IOException {
public IImdbController setWebsiteCodeVersion() {

Elements old = mainWebsiteCode.select(".title_wrapper");
Elements newest = mainWebsiteCode.select(".TitleHeader__TitleText-sc-1wu6n3d-0");
Elements newest = mainWebsiteCode.select(".ipc-page-content-container" +
".ipc-page-content-container--full" +
".sc-b1984961-0" +
".kXDasd");

if(old.size() != 0) {
controller = new OldImdbController(mainWebsiteCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

public class NewImdbController implements IImdbController {


private Document mainWebsiteCode;

public NewImdbController(Document websiteCode) {
Expand All @@ -16,17 +15,17 @@ public NewImdbController(Document websiteCode) {

@Override
public String fetchMediaName() {
String c = "TitleHeader__TitleText-sc-1wu6n3d-0";
String c = "sc-94726ce4-0 cMYixt";
c = "." + c.replaceAll("\\s+", ".");

Elements elements = mainWebsiteCode.select(c);
String name = elements.first().text();
String name = elements.first().child(0).child(0).text();
return name;
}

@Override
public MediaType fetchMediaType() {
String c = "ipc-inline-list ipc-inline-list--show-dividers TitleBlockMetaData__MetaDataList-sc-12ein40-0 dxizHm baseAlt";
String c = "ipc-inline-list ipc-inline-list--show-dividers sc-52284603-0 blbaZJ baseAlt";
c = "." + c.replaceAll("\\s+", ".");

Elements elements = mainWebsiteCode.select(c);
Expand All @@ -52,7 +51,7 @@ else if(type.contains("Video Game")) {

@Override
public String fetchMediaCategory() {
String c = "ipc-chip-list GenresAndPlot__GenresChipList-cum89p-4 gtBDBL";
String c = "ipc-chip-list sc-16ede01-4 bMBIRz";
c = "." + c.replaceAll("\\s+", ".");

Elements elements = mainWebsiteCode.select(c);
Expand All @@ -71,7 +70,7 @@ public String fetchMediaCategory() {

@Override
public int fetchMediaReleaseYear() {
String c = "TitleBlockMetaData__ListItemText-sc-12ein40-2 jedhex";
String c = "sc-52284603-2 iTRONr";
c = "." + c.replaceAll("\\s+", ".");

Elements elements = mainWebsiteCode.select(c);
Expand All @@ -91,14 +90,13 @@ public int fetchMediaReleaseYear() {

@Override
public String fetchMediaLength() {
String c = "styles__MetaDataContainer-sc-12uhu9s-0 cgqHBf";
String c = "ipc-inline-list ipc-inline-list--show-dividers sc-52284603-0 blbaZJ baseAlt";
c = "." + c.replaceAll("\\s+", ".");

Elements elements = mainWebsiteCode.select(c);
Element lengthList = elements.get(elements.size()-2);
String length = lengthList.child(0).child(0).child(1).child(0).child(0).child(0).text();
String length = elements.first().child(elements.first().childNodeSize() - 1).text();

if(Character.isDigit(length.charAt(0))) {
if(Character.isDigit(length.charAt(0)) && Character.isLetter(length.charAt(length.length() - 1))) {
return length;
} else {
return "";
Expand Down
11 changes: 3 additions & 8 deletions src/main/java/com/samsalek/ratingreader/model/Episode.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,13 @@ public Episode(Media media) {

public void fetchLength() throws IOException {
Document websiteCode = Jsoup.connect(url).get();
String c = "TitleBlock__TitleMetaDataContainer-sc-1nlhx7j-2 hWHMKr";
String c = "ipc-inline-list ipc-inline-list--show-dividers sc-52284603-0 blbaZJ baseAlt";
c = "." + c.replaceAll("\\s+", ".");

Elements elements = websiteCode.select(c);
String length = elements.first().child(elements.first().childNodeSize() - 1).text();

Element informationContainer = elements.first().child(0);
if(informationContainer.children().size() == 0) {
return;
}
String length = informationContainer.children().last().text();

if(Character.isDigit(length.charAt(0))) {
if(Character.isDigit(length.charAt(0)) && Character.isLetter(length.charAt(length.length() - 1))) {
this.length = length;
} else {
this.length = "NA";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;

import java.io.IOException;
Expand All @@ -23,10 +24,10 @@ public void start(Stage stage) throws Exception {
Scene scene = new Scene(rootFXML, ViewConstants.INITIAL_WIDTH, ViewConstants.INITIAL_HEIGHT);

stage.setScene(scene);
stage.show();

String title = readPropertiesFile("dev.name") + " " + readPropertiesFile("dev.version");
stage.setTitle(title);
stage.getIcons().add(new Image(getClass().getClassLoader().getResourceAsStream("images/icon.png")));
stage.show();

// Decoration width and height (window border width and height)
double dWidth = scene.getWindow().getWidth()-scene.getWidth();
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/dev.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dev.name = Rating Reader
dev.executable.name = RatingReader
dev.version = 0.9.2
dev.version = 0.8.5
dev.url = https://github.com/sam-salek/RatingReader
2 changes: 1 addition & 1 deletion src/main/resources/fxml/episodeItem.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<Cursor fx:constant="HAND" />
</cursor>
</Label>
<ToggleButton fx:id="nameToggleButton" layoutX="71.0" layoutY="6.0" mnemonicParsing="false" onMousePressed="#onPressEpisodeNameToggleButton" prefHeight="25.0" prefWidth="116.0" text="Show Episode Name">
<ToggleButton fx:id="nameToggleButton" layoutX="100.0" layoutY="6.0" mnemonicParsing="false" onMousePressed="#onPressEpisodeNameToggleButton" prefHeight="25.0" prefWidth="85.0" text="Episode name">
<font>
<Font size="11.0" />
</font>
Expand Down
Binary file modified src/main/resources/images/icon.ico
Binary file not shown.
Binary file added src/main/resources/images/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 9 additions & 9 deletions src/test/java/com/samsalek/ratingreader/IImdbControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public void fetchMediaCategory(){

imdbHandler.fetchImdbWebsiteCode("Black sails");
controller = imdbHandler.setWebsiteCodeVersion();
assertEquals("Adventure, Drama", controller.fetchMediaCategory());
assertEquals("Action, Adventure, Drama", controller.fetchMediaCategory());

imdbHandler.fetchImdbWebsiteCode("Breaking bad");
controller = imdbHandler.setWebsiteCodeVersion();
Expand Down Expand Up @@ -209,11 +209,11 @@ public void fetchMediaLength() {
try {
imdbHandler.fetchImdbWebsiteCode("WandaVision");
controller = imdbHandler.setWebsiteCodeVersion();
assertEquals("5h 50min", controller.fetchMediaLength());
assertEquals("5h 50m", controller.fetchMediaLength());

imdbHandler.fetchImdbWebsiteCode("Game of thrones");
controller = imdbHandler.setWebsiteCodeVersion();
assertEquals("57min", controller.fetchMediaLength());
assertEquals("57m", controller.fetchMediaLength());

imdbHandler.fetchImdbWebsiteCode("Loki");
controller = imdbHandler.setWebsiteCodeVersion();
Expand All @@ -225,27 +225,27 @@ public void fetchMediaLength() {

imdbHandler.fetchImdbWebsiteCode("Avengers endgame");
controller = imdbHandler.setWebsiteCodeVersion();
assertEquals("3h 1min", controller.fetchMediaLength());
assertEquals("3h 1m", controller.fetchMediaLength());

imdbHandler.fetchImdbWebsiteCode("Spiderman far from home");
controller = imdbHandler.setWebsiteCodeVersion();
assertEquals("2h 9min", controller.fetchMediaLength());
assertEquals("2h 9m", controller.fetchMediaLength());

imdbHandler.fetchImdbWebsiteCode("Black sails");
controller = imdbHandler.setWebsiteCodeVersion();
assertEquals("56min", controller.fetchMediaLength());
assertEquals("56m", controller.fetchMediaLength());

imdbHandler.fetchImdbWebsiteCode("Breaking bad");
controller = imdbHandler.setWebsiteCodeVersion();
assertEquals("49min", controller.fetchMediaLength());
assertEquals("49m", controller.fetchMediaLength());

imdbHandler.fetchImdbWebsiteCode("Fury");
controller = imdbHandler.setWebsiteCodeVersion();
assertEquals("2h 14min", controller.fetchMediaLength());
assertEquals("2h 14m", controller.fetchMediaLength());

imdbHandler.fetchImdbWebsiteCode("Transformers age of extinction");
controller = imdbHandler.setWebsiteCodeVersion();
assertEquals("2h 45min", controller.fetchMediaLength());
assertEquals("2h 45m", controller.fetchMediaLength());
} catch (IOException e) {
e.printStackTrace();
}
Expand Down

0 comments on commit 20f6168

Please sign in to comment.