-
Notifications
You must be signed in to change notification settings - Fork 54
/
VODChannel.js
executable file
·186 lines (159 loc) · 6.59 KB
/
VODChannel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import React, { Component } from 'react';
import { ActivityIndicator, Linking, Platform, StyleSheet, Text, ScrollView } from 'react-native';
import { Button, Card } from 'react-native-elements';
import getVODInfo from './api/getVODInfo';
import { play } from 'react-native-vlc-player';
import { ConfirmDialog } from 'react-native-simple-dialogs';
import getLocalizedString from './utils/getLocalizedString';
let loadingVODInfo = true;
let activityIndicator = <ActivityIndicator animating hidesWhenStopped size='large' />;
let activityIndicatorText = <Text>{getLocalizedString('VODChannel.activityIndicatorText')}</Text>;
const colors = {
deepSkyBlue: '#03A9F4',
};
const styles = StyleSheet.create({
activityContainer: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
text: {
marginBottom: 10,
fontSize: 16,
},
button: {
borderRadius: 0,
marginLeft: 0,
marginRight: 0,
marginBottom: 0,
},
});
let Info = [];
function utf8Decode(utf8String) {
if (typeof utf8String !== 'string') throw new TypeError('parameter ‘utf8String’ is not a string');
const unicodeString = utf8String.replace(
/[\u00e0-\u00ef][\u0080-\u00bf][\u0080-\u00bf]/g,
function(c) {
const cc = ((c.charCodeAt(0) & 0x0f) << 12) | ((c.charCodeAt(1) & 0x3f) << 6) | ( c.charCodeAt(2) & 0x3f);
return String.fromCharCode(cc);
}).replace(
/[\u00c0-\u00df][\u0080-\u00bf]/g,
function(c) {
const cc = (c.charCodeAt(0) & 0x1f) << 6 | c.charCodeAt(1) & 0x3f;
return String.fromCharCode(cc);
});
return unicodeString;
}
class VODChannel extends Component {
/* eslint-disable react/sort-comp */
state = {
dialogVisible: false,
};
/* eslint-enable react/sort-comp */
async componentWillMount() {
const {
url, username, password, vod,
} = this.props.navigation.state.params;
Info = await getVODInfo(url, username, password, vod.stream_id);
loadingVODInfo = false;
activityIndicator = null;
activityIndicatorText = null;
this.forceUpdate();
}
render() {
if (loadingVODInfo) {
return (
<ScrollView contentContainerStyle={styles.activityContainer}>
{activityIndicator}
{activityIndicatorText}
</ScrollView>
);
}
const {
url, username, password, vod
} = this.props.navigation.state.params;
const card = vod.stream_icon ? (
<Card image={{ uri: vod.stream_icon }} imageProps={{ resizeMode: 'contain' }} title={vod.name}>
{ Info.info.plot ? <Text>{getLocalizedString('vodChannel.plot')} {utf8Decode(Info.info.plot) + '\r\n'}</Text> : null }
{ Info.info.cast ? <Text>{getLocalizedString('vodChannel.cast')} {utf8Decode(Info.info.cast) + '\r\n'}</Text> : null }
{ Info.info.genre ? <Text>{getLocalizedString('vodChannel.genre')} {utf8Decode(Info.info.genre) + '\r\n'}</Text> : null }
{ Info.info.rating ? <Text>{getLocalizedString('vodChannel.rating')} {utf8Decode(Info.info.rating)} / 10 {'\r\n'}</Text> : null }
{ Info.info.director ? <Text>{getLocalizedString('vodChannel.director')} {utf8Decode(Info.info.director) + '\r\n'}</Text> : null }
{ Info.info.releasedate ? <Text>{getLocalizedString('vodChannel.releasedate')} {utf8Decode(Info.info.releasedate) + '\r\n'}</Text> : null }
{ Info.info.duration ? <Text>{getLocalizedString('vodChannel.duration')} {utf8Decode(Info.info.duration) + '\r\n'}</Text> : null }
<Button
backgroundColor={colors.deepSkyBlue}
buttonStyle={styles.button}
icon={{ name: 'eye', type: 'font-awesome' }}
onPress={() => this.viewNow(url, username, password, vod)}
title={getLocalizedString('vodChannel.viewNow')} />
</Card>
) : (
<Card title={vod.name}>
{ Info.info.plot ? <Text>{getLocalizedString('vodChannel.plot')} {utf8Decode(Info.info.plot) + '\r\n'}</Text> : null }
{ Info.info.cast ? <Text>{getLocalizedString('vodChannel.cast')} {utf8Decode(Info.info.cast) + '\r\n'}</Text> : null }
{ Info.info.genre ? <Text>{getLocalizedString('vodChannel.genre')} {utf8Decode(Info.info.genre) + '\r\n'}</Text> : null }
{ Info.info.rating ? <Text>{getLocalizedString('vodChannel.rating')} {utf8Decode(Info.info.rating)} / 10 {'\r\n'}</Text> : null }
{ Info.info.director ? <Text>{getLocalizedString('vodChannel.director')} {utf8Decode(Info.info.director) + '\r\n'}</Text> : null }
{ Info.info.releasedate ? <Text>{getLocalizedString('vodChannel.releasedate')} {utf8Decode(Info.info.releasedate) + '\r\n'}</Text> : null }
{ Info.info.duration ? <Text>{getLocalizedString('vodChannel.duration')} {utf8Decode(Info.info.duration) + '\r\n'}</Text> : null }
<Button
backgroundColor={colors.deepSkyBlue}
buttonStyle={styles.button}
icon={{ name: 'eye', type: 'font-awesome' }}
onPress={() => this.viewNow(url, username, password, vod)}
title={getLocalizedString('vodChannel.viewNow')} />
</Card>
);
if (this.state.dialogVisible) {
const message = getLocalizedString('vodChannel.message');
return (
<ConfirmDialog
message={message}
negativeButton={{
onPress: () => {
this.setState({ dialogVisible: false });
if (Platform.OS === 'android') {
play(url + '/movie/' + username + '/' + password + '/' + vod.stream_id + '.' + vod.container_extension);
} else if (Platform.OS === 'ios') {
this.props.navigation.navigate('PlayeriOS', { uri: url + '/movie/' + username + '/' + password + '/' + vod.stream_id + '.' + vod.container_extension });
} else {
throw new Error('Platform not recognized: ' + Platform.OS);
}
},
title: getLocalizedString('vodChannel.no'),
}}
onTouchOutside={() => this.setState({ dialogVisible: false })}
positiveButton={{
onPress: () => {
this.setState({ dialogVisible: false });
if (Platform.OS === 'android') {
Linking.openURL(url + '/movie/' + username + '/' + password + '/' + vod.stream_id + '.' + vod.container_extension);
} else if (Platform.OS === 'ios') {
Linking.openURL('vlc-x-callback://x-callback-url/stream?url=' + url + '/movie/' + username + '/' + password + '/' + vod.stream_id + '.' + vod.container_extension);
} else {
throw new Error('Platform not recognized: ' + Platform.OS);
}
},
title: getLocalizedString('vodChannel.yes'),
}}
title={getLocalizedString('vodChannel.title')}
visible={this.state.dialogVisible} />
);
}
return (
<ScrollView>
{card}
</ScrollView>
);
}
viewNow(url, username, password, vod) {
if (Platform.OS === 'android' || Platform.OS === 'ios') {
this.setState({ dialogVisible: true });
} else {
throw new Error('Platform not recognized: ' + Platform.OS);
}
return this;
}
}
export default VODChannel;