Skip to content

Commit 51195f2

Browse files
author
Roman Miroshnychenko
committed
Use an external movies.json file
1 parent 0660700 commit 51195f2

File tree

3 files changed

+105
-119
lines changed

3 files changed

+105
-119
lines changed

addon.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<addon id="plugin.video.example"
3-
version="3.0.1"
3+
version="3.0.2"
44
name="Example Kodi Video Plugin"
55
provider-name="Roman_V_M">
66
<requires>

main.py

Lines changed: 18 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
"""
1616
Example video plugin that is compatible with Kodi 20.x "Nexus" and above
1717
"""
18-
import os
18+
import json
1919
import sys
20+
from pathlib import Path
2021
from urllib.parse import urlencode, parse_qsl
2122

2223
import xbmcgui
@@ -28,123 +29,17 @@
2829
URL = sys.argv[0]
2930
# Get a plugin handle as an integer number.
3031
HANDLE = int(sys.argv[1])
31-
# Get addon base path
32-
ADDON_PATH = translatePath(Addon().getAddonInfo('path'))
33-
ICONS_DIR = os.path.join(ADDON_PATH, 'resources', 'images', 'icons')
34-
FANART_DIR = os.path.join(ADDON_PATH, 'resources', 'images', 'fanart')
32+
# Get the addon base path. Here we use pathlib.Path for convenient path handling
33+
ADDON_PATH = Path(translatePath(Addon().getAddonInfo('path')))
34+
ICONS_DIR = ADDON_PATH / 'resources' / 'images' / 'icons'
35+
FANART_DIR = ADDON_PATH / 'resources' / 'images' / 'fanart'
3536

3637
# Public domain movies are from https://publicdomainmovie.net
37-
# Here we use a hardcoded list of movies simply for demonstrating purposes
38+
# Here we use a hardcoded list of movies from a JSON file simply for demonstrating purposes
3839
# In a "real life" plugin you will need to get info and links to video files/streams
3940
# from some website or online service.
40-
VIDEOS = [
41-
{
42-
'genre': 'Drama',
43-
'icon': os.path.join(ICONS_DIR, 'Drama.png'),
44-
'fanart': os.path.join(FANART_DIR, 'Drama.jpg'),
45-
'movies': [
46-
{
47-
'title': 'The Stranger',
48-
'url': 'https://ia800908.us.archive.org/30/items/TheStranger_0/The_Stranger_512kb.mp4',
49-
'poster': 'https://publicdomainmovie.net/wikimedia.php?id=Movie-Mystery-Magazine-July-1946.jpg',
50-
'plot': 'In 1946, Mr. Wilson (Edward G. Robinson) of the United Nations War Crimes Commission is hunting for '
51-
'a Nazism fugitive Franz Kindler (Orson Welles), a war criminal who has erased all evidence which '
52-
'might identify him. Kindler has assumed a new identity, Charles Rankin, '
53-
'and has become a University-preparatory school#United States and Canada teacher '
54-
'in a small town in the United States. ',
55-
'year': 1946,
56-
},
57-
{
58-
'title': 'The Iron Mask',
59-
'url': 'https://ia600702.us.archive.org/3/items/iron_mask/iron_mask_512kb.mp4',
60-
'poster': 'https://publicdomainmovie.net/wikimedia.php?id=Ironmaskposter.jpg',
61-
'plot': 'The Iron Mask is a 1929 American part-talkie adventure film directed by Allan Dwan. '
62-
'It is an adaptation of the last section of the novel The Vicomte de Bragelonne by '
63-
'Alexandre Dumas, père, which is itself based on the French legend of The Man in the Iron Mask.',
64-
'year': 1929,
65-
},
66-
{
67-
'title': 'Meet John Doe',
68-
'url': 'https://ia804707.us.archive.org/30/items/meet_john_doe_ipod/video_512kb.mp4',
69-
'poster': 'https://publicdomainmovie.net/wikimedia.php?id=Poster_-_Meet_John_Doe_01.jpg',
70-
'plot': 'Meet John Doe is a 1941 in film United States comedy film drama film film directed and produced '
71-
'by Frank Capra, and starring Gary Cooper and Barbara Stanwyck. The film is about a "grassroots" '
72-
'political campaign created unwittingly by a newspaper columnist and pursued by a wealthy businessman.',
73-
'year': 1941,
74-
},
75-
],
76-
},
77-
{
78-
'genre': 'Horror',
79-
'icon': os.path.join(ICONS_DIR, 'Horror.png'),
80-
'fanart': os.path.join(FANART_DIR, 'Horror.jpg'),
81-
'movies': [
82-
{
83-
'title': 'House on Haunted Hill',
84-
'url': 'https://ia800203.us.archive.org/18/items/house_on_haunted_hill_ipod/house_on_haunted_hill_512kb.mp4',
85-
'poster': 'https://publicdomainmovie.net/wikimedia.php?id=House_on_Haunted_Hill.jpg',
86-
'plot': 'Eccentric millionaire Frederick Loren (Vincent Price) invites five people to a "party" '
87-
'he is throwing for his fourth wife, Annabelle (Carol Ohmart), '
88-
'in an allegedly haunted house he has rented, promising to give them each $10,000 '
89-
'with the stipulation that they must stay the entire night in the house after '
90-
'the doors are locked at midnight.',
91-
'year': 1959,
92-
},
93-
{
94-
'title': 'Carnival of Souls',
95-
'url': 'https://ia600301.us.archive.org/8/items/CarnivalofSouls/CarnivalOfSouls_512kb.mp4',
96-
'poster': 'https://publicdomainmovie.net/wikimedia.php?id=Carnival_of_Souls_%25281962_pressbook_cover%2529.jpg',
97-
'plot': 'Carnival of Souls is a 1962 Independent film horror film starring Candace Hilligoss. Produced and directed by Herk Harvey '
98-
'for an estimated $33,000, the film did not gain widespread attention when originally released, '
99-
'as a B-movie; today, however, it is a cult classic.',
100-
'year': 1962,
101-
},
102-
{
103-
'title': 'The Screaming Skull',
104-
'url': 'https://ia801603.us.archive.org/10/items/TheScreamingSkull/TheScreamingSkull.mp4',
105-
'poster': 'https://publicdomainmovie.net/wikimedia.php?id=Poster_for_The_Screaming_Skull.jpg',
106-
'plot': 'A widower remarries and the couple move into the house he shared with his previous wife. '
107-
'Only the ghost of the last wife might still be hanging around.',
108-
'year': 1958,
109-
},
110-
],
111-
},
112-
{
113-
'genre': 'Comedy',
114-
'icon': os.path.join(ICONS_DIR, 'Comedy.png'),
115-
'fanart': os.path.join(FANART_DIR, 'Comedy.jpg'),
116-
'movies': [
117-
{
118-
'title': 'Charlie Chaplin\'s "The Vagabond"',
119-
'url': 'https://ia904601.us.archive.org/16/items/CC_1916_07_10_TheVagabond/CC_1916_07_10_TheVagabond.mp4',
120-
'poster': 'https://publicdomainmovie.net/wikimedia.php?id=The_Vagabond_%25281916%2529.jpg',
121-
'plot': 'Charlie Chaplins 53rd Film Released July 10 1916 The Vagabond was a silent '
122-
'film by Charlie Chaplin and his third film with Mutual Films. Released in 1916, '
123-
'it co-starred Edna Purviance, Eric Campbell, Leo White and Lloyd Bacon. '
124-
'This film echoed Chaplin\'s work on The Tramp, with more drama mixed in with comedy.',
125-
'year': 1916,
126-
},
127-
{
128-
'title': 'Sing A Song of Six Pants',
129-
'url': 'https://ia601508.us.archive.org/26/items/sing_a_song_of_six_pants/sing_a_song_of_six_pants_512kb.mp4',
130-
'poster': 'https://publicdomainmovie.net/wikimedia.php?id=SingSong6PantsOneSheet47.JPG',
131-
'plot': 'The Three Stooges (Moe, Larry, Shemp) are tailors and are heavily in debt. '
132-
'Could a big reward for the capture of a fugitive bank robber answer their financial prayers?',
133-
'year': 1947,
134-
},
135-
{
136-
'title': 'Steamboat Bill, Jr.',
137-
'url': 'https://ia904501.us.archive.org/32/items/SteamboatBillJr/Steamboat_Bill.Jr_512kb.mp4',
138-
'poster': 'https://publicdomainmovie.net/wikimedia.php?id=Steamboat_bill_poster.jpg',
139-
'plot': 'Steamboat Bill, Jr. is the story of a naive, college-educated dandy who must prove himself '
140-
'to his working-class father, a hot-headed riverboat captain, while courting the daughter of '
141-
'his father\'s rival, who threatens to put Steamboat Bill, Sr. '
142-
'and his paddle-wheeler out of business.',
143-
'year': 1928,
144-
},
145-
],
146-
},
147-
]
41+
42+
MOVIES_INFO_PATH = ADDON_PATH / 'movies.json'
14843

14944

15045
def get_url(**kwargs):
@@ -155,7 +50,7 @@ def get_url(**kwargs):
15550
:return: plugin call URL
15651
:rtype: str
15752
"""
158-
return '{}?{}'.format(URL, urlencode(kwargs))
53+
return f'{URL}?{urlencode(kwargs)}'
15954

16055

16156
def get_genres():
@@ -168,7 +63,8 @@ def get_genres():
16863
:return: The list of video genres
16964
:rtype: list
17065
"""
171-
return VIDEOS
66+
with MOVIES_INFO_PATH.open('r', encoding='utf-8') as fo:
67+
return json.load(fo)
17268

17369

17470
def get_videos(genre_index):
@@ -183,7 +79,7 @@ def get_videos(genre_index):
18379
:return: the list of videos in the category
18480
:rtype: list
18581
"""
186-
return VIDEOS[genre_index]
82+
return get_genres()[genre_index]
18783

18884

18985
def list_genres():
@@ -203,7 +99,11 @@ def list_genres():
20399
# Create a list item with a text label.
204100
list_item = xbmcgui.ListItem(label=genre_info['genre'])
205101
# Set images for the list item.
206-
list_item.setArt({'icon': genre_info['icon'], 'fanart': genre_info['fanart']})
102+
# Convert Path objects to str because Kodi API accepts only str.
103+
list_item.setArt({
104+
'icon': str(ICONS_DIR / genre_info['icon']),
105+
'fanart': str(FANART_DIR / genre_info['fanart']),
106+
})
207107
# Set additional info for the list item using its InfoTag.
208108
# InfoTag allows to set various information for an item.
209109
# For available properties and methods see the following link:

movies.json

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
[
2+
{
3+
"genre": "Drama",
4+
"icon": "Drama.png",
5+
"fanart": "Drama.jpg",
6+
"movies": [
7+
{
8+
"title": "The Stranger",
9+
"url": "https://ia800908.us.archive.org/30/items/TheStranger_0/The_Stranger_512kb.mp4",
10+
"poster": "https://publicdomainmovie.net/wikimedia.php?id=Movie-Mystery-Magazine-July-1946.jpg",
11+
"plot": "In 1946, Mr. Wilson (Edward G. Robinson) of the United Nations War Crimes Commission is hunting for a Nazism fugitive Franz Kindler (Orson Welles), a war criminal who has erased all evidence which might identify him. Kindler has assumed a new identity, Charles Rankin, and has become a University-preparatory school#United States and Canada teacher in a small town in the United States. ",
12+
"year": 1946
13+
},
14+
{
15+
"title": "The Iron Mask",
16+
"url": "https://ia600702.us.archive.org/3/items/iron_mask/iron_mask_512kb.mp4",
17+
"poster": "https://publicdomainmovie.net/wikimedia.php?id=Ironmaskposter.jpg",
18+
"plot": "The Iron Mask is a 1929 American part-talkie adventure film directed by Allan Dwan. It is an adaptation of the last section of the novel The Vicomte de Bragelonne by Alexandre Dumas, p\u00e8re, which is itself based on the French legend of The Man in the Iron Mask.",
19+
"year": 1929
20+
},
21+
{
22+
"title": "Meet John Doe",
23+
"url": "https://ia804707.us.archive.org/30/items/meet_john_doe_ipod/video_512kb.mp4",
24+
"poster": "https://publicdomainmovie.net/wikimedia.php?id=Poster_-_Meet_John_Doe_01.jpg",
25+
"plot": "Meet John Doe is a 1941 in film United States comedy film drama film film directed and produced by Frank Capra, and starring Gary Cooper and Barbara Stanwyck. The film is about a \"grassroots\" political campaign created unwittingly by a newspaper columnist and pursued by a wealthy businessman.",
26+
"year": 1941
27+
}
28+
]
29+
},
30+
{
31+
"genre": "Horror",
32+
"icon": "Horror.png",
33+
"fanart": "Horror.jpg",
34+
"movies": [
35+
{
36+
"title": "House on Haunted Hill",
37+
"url": "https://ia800203.us.archive.org/18/items/house_on_haunted_hill_ipod/house_on_haunted_hill_512kb.mp4",
38+
"poster": "https://publicdomainmovie.net/wikimedia.php?id=House_on_Haunted_Hill.jpg",
39+
"plot": "Eccentric millionaire Frederick Loren (Vincent Price) invites five people to a \"party\" he is throwing for his fourth wife, Annabelle (Carol Ohmart), in an allegedly haunted house he has rented, promising to give them each $10,000 with the stipulation that they must stay the entire night in the house after the doors are locked at midnight.",
40+
"year": 1959
41+
},
42+
{
43+
"title": "Carnival of Souls",
44+
"url": "https://ia600301.us.archive.org/8/items/CarnivalofSouls/CarnivalOfSouls_512kb.mp4",
45+
"poster": "https://publicdomainmovie.net/wikimedia.php?id=Carnival_of_Souls_%25281962_pressbook_cover%2529.jpg",
46+
"plot": "Carnival of Souls is a 1962 Independent film horror film starring Candace Hilligoss. Produced and directed by Herk Harvey for an estimated $33,000, the film did not gain widespread attention when originally released, as a B-movie; today, however, it is a cult classic.",
47+
"year": 1962
48+
},
49+
{
50+
"title": "The Screaming Skull",
51+
"url": "https://ia801603.us.archive.org/10/items/TheScreamingSkull/TheScreamingSkull.mp4",
52+
"poster": "https://publicdomainmovie.net/wikimedia.php?id=Poster_for_The_Screaming_Skull.jpg",
53+
"plot": "A widower remarries and the couple move into the house he shared with his previous wife. Only the ghost of the last wife might still be hanging around.",
54+
"year": 1958
55+
}
56+
]
57+
},
58+
{
59+
"genre": "Comedy",
60+
"icon": "Comedy.png",
61+
"fanart": "Comedy.jpg",
62+
"movies": [
63+
{
64+
"title": "Charlie Chaplin's \"The Vagabond\"",
65+
"url": "https://ia904601.us.archive.org/16/items/CC_1916_07_10_TheVagabond/CC_1916_07_10_TheVagabond.mp4",
66+
"poster": "https://publicdomainmovie.net/wikimedia.php?id=The_Vagabond_%25281916%2529.jpg",
67+
"plot": "Charlie Chaplins 53rd Film Released July 10 1916 The Vagabond was a silent film by Charlie Chaplin and his third film with Mutual Films. Released in 1916, it co-starred Edna Purviance, Eric Campbell, Leo White and Lloyd Bacon. This film echoed Chaplin's work on The Tramp, with more drama mixed in with comedy.",
68+
"year": 1916
69+
},
70+
{
71+
"title": "Sing A Song of Six Pants",
72+
"url": "https://ia601508.us.archive.org/26/items/sing_a_song_of_six_pants/sing_a_song_of_six_pants_512kb.mp4",
73+
"poster": "https://publicdomainmovie.net/wikimedia.php?id=SingSong6PantsOneSheet47.JPG",
74+
"plot": "The Three Stooges (Moe, Larry, Shemp) are tailors and are heavily in debt. Could a big reward for the capture of a fugitive bank robber answer their financial prayers?",
75+
"year": 1947
76+
},
77+
{
78+
"title": "Steamboat Bill, Jr.",
79+
"url": "https://ia904501.us.archive.org/32/items/SteamboatBillJr/Steamboat_Bill.Jr_512kb.mp4",
80+
"poster": "https://publicdomainmovie.net/wikimedia.php?id=Steamboat_bill_poster.jpg",
81+
"plot": "Steamboat Bill, Jr. is the story of a naive, college-educated dandy who must prove himself to his working-class father, a hot-headed riverboat captain, while courting the daughter of his father's rival, who threatens to put Steamboat Bill, Sr. and his paddle-wheeler out of business.",
82+
"year": 1928
83+
}
84+
]
85+
}
86+
]

0 commit comments

Comments
 (0)