Skip to content

Instantly share code, notes, and snippets.

@allanx2000
Created February 8, 2019 23:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allanx2000/8f97fe8479ea8ee00fea07627fd3c529 to your computer and use it in GitHub Desktop.
Save allanx2000/8f97fe8479ea8ee00fea07627fd3c529 to your computer and use it in GitHub Desktop.
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow
*/
import React, {Component} from 'react';
import {Linking, Clipboard, ToastAndroid, Alert, Platform, StyleSheet, Text, View} from 'react-native';
import InputSection from './Components/InputSection'
import RNFetchBlob from 'react-native-fetch-blob'
import AnimeShowsList from "./Components/AnimeShowsList";
type Props = {};
const MP4Upload = "https://www.mp4upload.com/";
const MP4Upload_Embed = MP4Upload + "embed-"
export default class App extends Component<Props> {
constructor(props) {
super(props)
this.state = {};
this.convertPressed = this.convertPressed.bind(this)
}
render() {
/*
<InputSection onConvertPressed={this.convertPressed} />
<View style={styles.linkRow}>
<Text style={{ alignContent: 'stretch', fontSize: 12}}>{this.state.url}</Text>
</View>
*/
return (
<View style={styles.container}>
<AnimeShowsList onClick={this.convertPressed}/>
</View>
);
}
convertPressed(url) {
if (!url || url === '')
this.toastAlert("URL invalid");
else {
this.toastAlert("Fetching: " + url, ToastAndroid.LONG);
RNFetchBlob.fetch('GET', url)
.then((res) => {
let html = res.text()
//https://www.mp4upload.com/embed-axgbbeg4cmty.html
var start = html.indexOf(MP4Upload_Embed)
if (start > 0)
{
start = start + MP4Upload_Embed.length;
var end = html.indexOf(".html", start);
var id = html.substr(start, end - start)
var link = MP4Upload + id;
this.setState({'url' : link})
Linking.openURL(link)
}
else
{
if (Platform.OS === "android") {
this.toastAlert("Cannot extract download link. Opening view-source", ToastAndroid.LONG)
url = "view-source:" + url;
Linking.openURL(link)
}
else
this.toastAlert("Cannot extract download link.")
}
})
// Status code is not 200
.catch((errorMessage, statusCode) => {
// error handling
this.toastAlert("Could not resolve URL: " + errorMessage)
})
}
}
toastAlert(msg, dur) {
if (Platform.OS == "ios")
Alert.alert(msg)
else
ToastAndroid.show(msg, dur? dur : ToastAndroid.SHORT)
}
}
const styles = StyleSheet.create({
container: {
alignContent: 'stretch',
marginBottom: 100
},
linkRow: {
backgroundColor: '#dea36a',
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment