From bddefe36665b87726d2e2bd33b375293724abbeb Mon Sep 17 00:00:00 2001 From: Amila Welihinda Date: Sun, 21 Apr 2019 08:00:26 -0700 Subject: [PATCH] v1.4.0 (#574) * Tidy up home component (#571) * v1.3.3 (#570) * bump to v1.3.3 * Sticky navbar (#569) * collapse toggler on click * sticky navbar * remove custom scrollbar styling to fix padding issues with container * Remove dead code * onChange is a class method * initInfinitePagination as arrow to avoid explicit binding * component is already aware of redux, no need to bindActionCreators * Only import what's needed * fix subtitles (#572) fix subtitles, add multi-lang subtitle support * semver bump to 1.3.4 --- .env.example | 6 +++ .github/PULL_REQUEST_TEMPLATE.md | 2 +- app/api/Subtitle.js | 43 ++++++++++++++++++ app/components/home/Home.js | 78 ++++++++++++-------------------- app/components/item/Item.js | 58 ++---------------------- app/containers/HomePage.js | 15 ++++-- app/index.js | 2 +- app/main.dev.js | 2 +- app/package.json | 2 +- package.json | 4 +- yarn.lock | 42 ++++++++++++----- 11 files changed, 131 insertions(+), 123 deletions(-) diff --git a/.env.example b/.env.example index f60cdb8e..735876dd 100644 --- a/.env.example +++ b/.env.example @@ -149,3 +149,9 @@ FLAG_NATIVE_PLAYBACK_FILTERING=false # *.mock.js. API_USE_MOCK_DATA=false + +# Default Torrent Language +# +# This sets the language that torrents will be loaded for + +DEFAULT_TORRENT_LANG=en diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 61f9263d..f428a499 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -5,7 +5,7 @@ -- [ ] Your pull request targets the `master` branch. +- [ ] Your pull request targets the `next` branch. - [ ] Branch starts with either `fix/` or `feature/` (e.g. `fix/signin-issue`) - [ ] All new and existing tests pass. diff --git a/app/api/Subtitle.js b/app/api/Subtitle.js index 296fac3c..96c40e4f 100644 --- a/app/api/Subtitle.js +++ b/app/api/Subtitle.js @@ -78,3 +78,46 @@ export default class SubtitleServer { }); } } + +export const languages = [ + // 'sq', + 'ar', + // 'bn', + // 'pb', + // 'bg', + 'zh', + // 'hr', + // 'cs', + // 'da', + // 'nl', + 'en', + // 'et', + // 'fa', + // 'fi', + // 'fr', + // 'de', + // 'el', + // 'he', + // 'hu', + // 'id', + // 'it', + // 'ja', + // 'ko', + // 'lt', + // 'mk', + // 'ms', + // 'no', + // 'pl', + // 'pt', + // 'ro', + 'ru', + // 'sr', + // 'sl', + 'es' + // 'sv', + // 'th', + // 'tr', + // 'ur', + // 'uk', + // 'vi' +]; diff --git a/app/components/home/Home.js b/app/components/home/Home.js index ab3b2575..d24d8858 100644 --- a/app/components/home/Home.js +++ b/app/components/home/Home.js @@ -21,18 +21,16 @@ export type itemType = { }; type Props = { - actions: { - setActiveMode: ( - mode: string, - activeModeOptions?: activeModeOptionsType - ) => void, - paginate: ( - activeMode: string, - activeModeOptions?: activeModeOptionsType - ) => void, - clearAllItems: () => void, - setLoading: (isLoading: boolean) => void - }, + setActiveMode: ( + mode: string, + activeModeOptions?: activeModeOptionsType + ) => void, + paginate: ( + activeMode: string, + activeModeOptions?: activeModeOptionsType + ) => void, + clearAllItems: () => void, + setLoading: (isLoading: boolean) => void, activeMode: string, activeModeOptions: activeModeOptionsType, modes: { @@ -69,21 +67,10 @@ export default class Home extends Component { butter: Butter; - didMount: boolean; - - // onChange: () => void; - constructor(props: Props) { super(props); this.butter = new Butter(); - this.onChange = async (isVisible: boolean) => { - const { isLoading, activeMode, activeModeOptions } = this.props; - if (isVisible && !isLoading) { - await this.paginate(activeMode, activeModeOptions); - } - }; - // Temporary hack to preserve scroll position if (!global.pct) { global.pct = { @@ -107,9 +94,9 @@ export default class Home extends Component { queryType: string, activeModeOptions: activeModeOptionsType = {} ) { - const { actions, modes } = this.props; + const { modes, paginate, setLoading } = this.props; - actions.setLoading(true); + setLoading(true); // HACK: This is a temporary solution. // Waiting on: https://github.com/yannickcr/eslint-plugin-react/issues/818 @@ -130,8 +117,8 @@ export default class Home extends Component { } })(); - actions.paginate(items); - actions.setLoading(false); + paginate(items); + setLoading(false); return items; } @@ -139,7 +126,7 @@ export default class Home extends Component { /** * If bottom of component is 2000px from viewport, query */ - initInfinitePagination() { + initInfinitePagination = () => { const { infinitePagination, activeMode, @@ -155,18 +142,12 @@ export default class Home extends Component { this.paginate(activeMode, activeModeOptions); } } - } - - setUserMeta(type: 'favorites' | 'watchList', item) { - this.setState({ - [type]: this.butter[type]('set', item) - }); - } + }; async componentDidMount() { const { activeMode } = this.props; - this.didMount = true; - document.addEventListener('scroll', this.initInfinitePagination.bind(this)); + + document.addEventListener('scroll', this.initInfinitePagination); window.scrollTo(0, global.pct[`${activeMode}ScrollTop`]); const [favorites, watchList, recentlyWatched] = await Promise.all([ @@ -182,10 +163,8 @@ export default class Home extends Component { }); } - componentWillMount() {} - componentWillReceiveProps(nextProps: Props) { - const { activeMode, activeModeOptions, actions } = this.props; + const { activeMode, activeModeOptions, clearAllItems } = this.props; global.pct[`${activeMode}ScrollTop`] = document.body.scrollTop; if (activeMode !== nextProps.activeMode) { @@ -197,7 +176,7 @@ export default class Home extends Component { JSON.stringify(activeModeOptions) ) { if (nextProps.activeMode === 'search') { - actions.clearAllItems(); + clearAllItems(); } this.paginate(nextProps.activeMode, nextProps.activeModeOptions); @@ -221,15 +200,18 @@ export default class Home extends Component { global.pct[`${activeMode}ScrollTop`] = document.body.scrollTop; - this.didMount = false; - document.removeEventListener( - 'scroll', - this.initInfinitePagination.bind(this) - ); + document.removeEventListener('scroll', this.initInfinitePagination); } + onChange = async (isVisible: boolean) => { + const { isLoading, activeMode, activeModeOptions } = this.props; + if (isVisible && !isLoading) { + await this.paginate(activeMode, activeModeOptions); + } + }; + render() { - const { activeMode, actions, items, isLoading } = this.props; + const { activeMode, items, isLoading, setActiveMode } = this.props; const { favorites, watchList, recentlyWatched } = this.state; const home = ( @@ -254,7 +236,7 @@ export default class Home extends Component { return ( -
+
{activeMode === 'home' ? ( home diff --git a/app/components/item/Item.js b/app/components/item/Item.js index 6c33257b..40b7515a 100644 --- a/app/components/item/Item.js +++ b/app/components/item/Item.js @@ -27,7 +27,7 @@ import ChromecastPlayerProvider from '../../api/players/ChromecastPlayerProvider import { getIdealTorrent } from '../../api/torrents/BaseTorrentProvider'; import Butter from '../../api/Butter'; import Torrent from '../../api/Torrent'; -import SubtitleServer from '../../api/Subtitle'; +import SubtitleServer, { languages as langs } from '../../api/Subtitle'; import Player from '../../api/Player'; import type { contentType, @@ -555,57 +555,12 @@ export default class Item extends Component { async getCaptions(item: contentType): Promise { const captions: Array = await yifysubtitles(item.ids.imdbId, { path: os.tmpdir(), - langs: ['en', 'fr'] - // langs: [ - // 'sq', - // 'ar', - // 'bn', - // 'pb', - // 'bg', - // 'zh', - // 'hr', - // 'cs', - // 'da', - // 'nl', - // 'en', - // 'et', - // 'fa', - // 'fi', - // 'fr', - // 'de', - // 'el', - // 'he', - // 'hu', - // 'id', - // 'it', - // 'ja', - // 'ko', - // 'lt', - // 'mk', - // 'ms', - // 'no', - // 'pl', - // 'pt', - // 'ro', - // 'ru', - // 'sr', - // 'sl', - // 'es', - // 'sv', - // 'th', - // 'tr', - // 'ur', - // 'uk', - // 'vi' - // ] + langs }) .then(res => res.map(subtitle => ({ - // Set en - // default: ( - // subtitle.langShort === process.env.DEFAULT_TORRENT_LANG || subtitle.langShort === process.env.DEFAULT_TORRENT_LANG === 'en' - // ), - default: subtitle.langShort === 'en', + // Set the default language for subtitles + default: subtitle.langShort === process.env.DEFAULT_TORRENT_LANG, kind: 'captions', label: subtitle.langShort, srclang: subtitle.langShort, @@ -817,11 +772,6 @@ export default class Item extends Component { dispatch(clearAllItems()), + paginate: (activeMode, activeModeOptions) => + dispatch(paginate(activeMode, activeModeOptions)), + setActiveMode: (mode, activeModeOptions) => + dispatch(setActiveMode(mode, activeModeOptions)), + setLoading: isLoading => dispatch(setLoading(isLoading)) }; } diff --git a/app/index.js b/app/index.js index 2f5b0388..d30fc252 100644 --- a/app/index.js +++ b/app/index.js @@ -7,7 +7,7 @@ import Root from './containers/Root'; import { history, configureStore } from './store/configureStore'; import './app.global.scss'; -if (process.env.NODE_ENV === 'production') { +if (process.env.NODE_ENV === 'production' && process.env.E2E_BUILD !== 'true') { Sentry.init({ dsn: 'https://b0d05cee653942148a43b8163bbc6cee@sentry.io/1277263' }); diff --git a/app/main.dev.js b/app/main.dev.js index 7bf93a41..ce2df7b0 100644 --- a/app/main.dev.js +++ b/app/main.dev.js @@ -17,7 +17,7 @@ import log from 'electron-log'; import * as Sentry from '@sentry/electron/dist/main'; import MenuBuilder from './menu'; -if (process.env.NODE_ENV === 'production') { +if (process.env.NODE_ENV === 'production' && process.env.E2E_BUILD !== 'true') { Sentry.init({ dsn: 'https://b0d05cee653942148a43b8163bbc6cee@sentry.io/1277263' }); diff --git a/app/package.json b/app/package.json index 6f561d5a..949af373 100644 --- a/app/package.json +++ b/app/package.json @@ -2,7 +2,7 @@ "name": "PopcornTime", "description": "An experimental PopcornTime client", "homepage": "https://github.com/amilajack/popcorn-time-desktop", - "version": "1.3.3", + "version": "1.4.0", "main": "./main.prod.js", "author": { "name": "Amila Welihinda ", diff --git a/package.json b/package.json index dfae4198..a9e094d0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "popcorn-time-desktop", - "version": "1.3.3", + "version": "1.4.0", "description": "An experimental Popcorn Time client", "scripts": { "bench-api": "cross-env NODE_ENV=test BABEL_DISABLE_CACHE=1 jest test/**/*.benchmark.js", @@ -240,7 +240,7 @@ }, "dependencies": { "@amilajack/react-plyr": "^2.1.2", - "@amilajack/yifysubtitles": "^2.1.2", + "@amilajack/yifysubtitles": "^2.1.4", "@sentry/electron": "^0.17.1", "axios": "^0.18.0", "bootstrap": "4.3.1", diff --git a/yarn.lock b/yarn.lock index dd8efa85..d954d5e3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -20,18 +20,19 @@ plyr "^3.3.21" prop-types "^15.6.2" -"@amilajack/yifysubtitles@^2.1.2": - version "2.1.2" - resolved "https://registry.yarnpkg.com/@amilajack/yifysubtitles/-/yifysubtitles-2.1.2.tgz#9afc0ec2e92740acc5b9bc7617dcf38eae0dc795" - integrity sha512-/nCoTXAs7jykTlseANL5m9+9pQEztC/duNoC1whfZ81rA3TAgWZEPd87tMZzr/B2lETQE0bzTFwX+wAA/S6tJg== +"@amilajack/yifysubtitles@^2.1.4": + version "2.1.4" + resolved "https://registry.yarnpkg.com/@amilajack/yifysubtitles/-/yifysubtitles-2.1.4.tgz#46c5fc97b2e050e29b20b73d64d3dad11e2892e3" + integrity sha512-k6pkv0fsgFczMmhNE/I5q3N9Lb8SESHuDGk4mz56Rfm+aOGs4ykKlJf3t3GJWUiUg9Wwyj88Wu1blAthKHb2nA== dependencies: - cheerio "^1.0.0-rc.2" + cheerio "^1.0.0-rc.3" global "^4.3.2" - got "^9.2.0" - p-map "^1.2.0" + got "^9.6.0" + isomorphic-fetch "^2.2.1" + p-map "^2.1.0" srt-to-vtt "^1.1.3" streamz "^1.8.5" - unzipper "^0.9.3" + unzipper "^0.9.11" "@babel/code-frame@^7.0.0": version "7.0.0" @@ -3485,6 +3486,18 @@ cheerio@^1.0.0-rc.2: lodash "^4.15.0" parse5 "^3.0.1" +cheerio@^1.0.0-rc.3: + version "1.0.0-rc.3" + resolved "https://registry.yarnpkg.com/cheerio/-/cheerio-1.0.0-rc.3.tgz#094636d425b2e9c0f4eb91a46c05630c9a1a8bf6" + integrity sha512-0td5ijfUPuubwLUu0OBoe98gZj8C/AA+RW3v67GPlGOrvxWjZmBXiBCRU+I8VEiNyJzjth40POfHiz2RB3gImA== + dependencies: + css-select "~1.2.0" + dom-serializer "~0.1.1" + entities "~1.1.1" + htmlparser2 "^3.9.1" + lodash "^4.15.0" + parse5 "^3.0.1" + "cheerio@github:cheeriojs/cheerio#e65ad72": version "0.20.0" resolved "https://codeload.github.com/cheeriojs/cheerio/tar.gz/e65ad72cad8fb696e0f3475b127c93492feca04d" @@ -4900,7 +4913,7 @@ dom-helpers@^3.2.0, dom-helpers@^3.3.1: dependencies: "@babel/runtime" "^7.1.2" -dom-serializer@0, dom-serializer@~0.1.0: +dom-serializer@0, dom-serializer@~0.1.0, dom-serializer@~0.1.1: version "0.1.1" resolved "https://registry.yarnpkg.com/dom-serializer/-/dom-serializer-0.1.1.tgz#1ec4059e284babed36eec2941d4a970a189ce7c0" integrity sha512-l0IU0pPzLWSHBcieZbpOKgkIn3ts3vAh7ZuFyXNwJxJXk/c4Gwj9xaTJwIDVQCXawWD0qb3IzMGH5rglQaO0XA== @@ -6897,7 +6910,7 @@ got@^8.3.1: url-parse-lax "^3.0.0" url-to-options "^1.0.1" -got@^9.2.0: +got@^9.6.0: version "9.6.0" resolved "https://registry.yarnpkg.com/got/-/got-9.6.0.tgz#edf45e7d67f99545705de1f7bbeeeb121765ed85" integrity sha512-R7eWptXuGYxwijs0eV+v3o6+XH1IqVK8dJOEecQfTmkncw9AV4dcw/Dhxi8MdlqPthxxpZyizMzyg8RTmEsG+Q== @@ -10445,7 +10458,7 @@ p-locate@^3.0.0: dependencies: p-limit "^2.0.0" -p-map@^1.1.1, p-map@^1.2.0: +p-map@^1.1.1: version "1.2.0" resolved "https://registry.yarnpkg.com/p-map/-/p-map-1.2.0.tgz#e4e94f311eabbc8633a1e79908165fca26241b6b" integrity sha512-r6zKACMNhjPJMTl8KcFH4li//gkrXWfbD6feV8l6doRHlzljFWGJ2AP6iKaCJXyZmAUMOPtvbW7EXkbWO/pLEA== @@ -10455,6 +10468,11 @@ p-map@^2.0.0: resolved "https://registry.yarnpkg.com/p-map/-/p-map-2.0.0.tgz#be18c5a5adeb8e156460651421aceca56c213a50" integrity sha512-GO107XdrSUmtHxVoi60qc9tUl/KkNKm+X2CF4P9amalpGxv5YqVPJNfSb0wcA+syCopkZvYYIzW8OVTQW59x/w== +p-map@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/p-map/-/p-map-2.1.0.tgz#310928feef9c9ecc65b68b17693018a665cea175" + integrity sha512-y3b8Kpd8OAN444hxfBbFfj1FY/RjtTd8tzYwhUqNYXx0fXx2iX4maP4Qr6qhIKbQXI02wTLAda4fYUbDagTUFw== + p-reduce@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/p-reduce/-/p-reduce-1.0.0.tgz#18c2b0dd936a4690a529f8231f58a0fdb6a47dfa" @@ -14441,7 +14459,7 @@ unzipper@^0.8.11: readable-stream "~2.1.5" setimmediate "~1.0.4" -unzipper@^0.9.3: +unzipper@^0.9.11: version "0.9.11" resolved "https://registry.yarnpkg.com/unzipper/-/unzipper-0.9.11.tgz#9577d9b85e5974abd6e23a30dbc9dc187940fc47" integrity sha512-G0z5zv8LYv4/XwpOiXgTGTcN4jyxgyg3P1DfdIeCN2QGOd6ZBl49BSbOe9JsIEvKh3tG7/b0bdJvz+UmwA+BRg==