Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge with scrobbler #23

Merged
merged 27 commits into from
Jul 19, 2020
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"message": "Add with release date."
},
"aboutMessage": {
"message": "Sync the history from your favorite streaming services to Trakt.tv!"
"message": "Scrobble / sync the history from your favorite streaming services to Trakt.tv!"
rafaelgomesxyz marked this conversation as resolved.
Show resolved Hide resolved
},
"allowRollbarDescription": {
"message": "With this option enabled, whenever a bug occurs, information about it will be collected and sent to us, so that we can fix it faster and improve the extension. This information includes: when the bug happened, the traceback of the bug, the name and version of your browser, and the name of your OS. This data is not shared with any other service."
Expand Down Expand Up @@ -66,6 +66,15 @@
"correctWrongItemFailed": {
"message": "Failed to correct wrong item."
},
"couldNotScrobble": {
"message": "Could not scrobble."
},
"disableScrobblingDescription": {
"message": "With this option enabled, the extension will not automatically scrobble what you are watching. This is useful if you only want to use the history sync."
},
"disableScrobblingName": {
"message": "Disable scrobbling."
},
"errorNotification": {
"message": "An error has occurred. :("
},
Expand All @@ -90,6 +99,9 @@
"hideSyncedName": {
"message": "Hide synced."
},
"history": {
"message": "History"
},
"historySyncSuccess": {
"message": "$EPISODES$ episodes and $MOVIES$ movies synced.",
"placeholders": {
Expand Down Expand Up @@ -146,6 +158,12 @@
"notWatched": {
"message": "Not Watched"
},
"notWatching": {
"message": "Watch something!"
},
"nowScrobbling": {
"message": "Now Scrobbling"
},
"on": {
"message": "On"
},
Expand All @@ -172,6 +190,15 @@
"saveOptionSuccess": {
"message": "Option saved."
},
"scrobblePaused": {
"message": "Scrobble paused."
},
"scrobbleStarted": {
"message": "Scrobble started."
},
"scrobbleStopped": {
"message": "Scrobble stopped."
},
"select": {
"message": "Select:"
},
Expand All @@ -190,6 +217,12 @@
"sendReceiveSuggestionsName": {
"message": "Send / receive correction suggestions."
},
"showNotificationsDescription": {
"message": "With this option enabled, you will receive browser notifications whenever you start / stop scrobbling something."
},
"showNotificationsName": {
"message": "Show browser notifications."
},
"streamingServicesDescription": {
"message": "Choose which streaming services to enable."
},
Expand Down
35 changes: 34 additions & 1 deletion src/_locales/nb/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"message": "Legg til med utgivelsesdato."
},
"aboutMessage": {
"message": "Synkroniser historikken fra dine favorittstrømmetjenester til Trakt.tv!"
"message": "Scrobble / synkroniser historikken fra dine favorittstrømmetjenester til Trakt.tv!"
},
"allowRollbarDescription": {
"message": "Dersom det oppstår en feil, kan utviklerne få informasjon om det, slik at det er enklere å feilsøke, fikse og forbedre utvidelsen. Informasjonen som sendes inkluderer: Når feilen inntraff, omstendinghetene rundt feilen, navn og versjonsnummeret på nettleseren, og navnet på operativsystemet. Dataene blir ikke delt videre med andre tjenester."
Expand Down Expand Up @@ -66,6 +66,15 @@
"confirmClearTraktCacheTitle": {
"message": "Fjerne Trakt cache?"
},
"couldNotScrobble": {
"message": "Scrobbling feilet."
},
"disableScrobblingDescription": {
"message": "With this option enabled, the extension will not automatically scrobble what you are watching. This is useful if you only want to use the history sync."
},
"disableScrobblingName": {
"message": "Disable scrobbling."
},
"errorNotification": {
"message": "Noe har gått galt. :("
},
Expand All @@ -87,6 +96,9 @@
"grantCookiesName": {
"message": "Tillat \"cookies\" slik at utvidelsen kan virke sammen med Firefox Containers."
},
"history": {
"message": "History"
},
"hideSyncedName": {
"message": "Skjul allerede synkroniserte elementer."
},
Expand Down Expand Up @@ -146,6 +158,12 @@
"notWatched": {
"message": "Ikke registrert som sett"
},
"notWatching": {
"message": "Se på noe!"
},
"nowScrobbling": {
"message": "Scrobbler nå"
},
"on": {
"message": "På"
},
Expand All @@ -172,6 +190,15 @@
"saveOptionSuccess": {
"message": "Alternativ lagret."
},
"scrobblePaused": {
"message": "Scrobbling pauset."
},
"scrobbleStarted": {
"message": "Scrobbling startet."
},
"scrobbleStopped": {
"message": "Scrobbling stoppet."
},
"select": {
"message": "Velg:"
},
Expand All @@ -190,6 +217,12 @@
"sendReceiveSuggestionsName": {
"message": "Send / motta forslag til rettelser."
},
"showNotificationsDescription": {
"message": "Viser nettleservarsler hver gang du starter / stopper å scrobble noe."
},
"showNotificationsName": {
"message": "Vis nettleservarsler"
},
"streamingServicesDescription": {
"message": "Velg strømmetjenester som du vil ha aktive."
},
Expand Down
35 changes: 34 additions & 1 deletion src/_locales/pt_BR/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"message": "Adicionar com data de lançamento."
},
"aboutMessage": {
"message": "Sincronize o histórico dos seus serviços de streaming favoritos para o Trakt.tv!"
"message": "Faça scrobble / sincronize o histórico dos seus serviços de streaming favoritos para o Trakt.tv!"
},
"allowRollbarDescription": {
"message": "Com essa opção ativada, sempre que um erro acontecer, informações sobre ele serão coletadas e enviadas para nós, para que possamos consertá-lo mais rápido e melhorar a extensão. Essas informações incluem: quando o erro aconteceu, o traço do erro, o nome e a versão do neu navegador, e o nome do seu sistema operacional. Esses dados não são compartilhados com nenhum outro serviço."
Expand Down Expand Up @@ -66,6 +66,15 @@
"correctWrongItemFailed": {
"message": "Ocorreu um erro ao corrigir o item errado."
},
"couldNotScrobble": {
"message": "Não foi possível realizar o scrobble."
},
"disableScrobblingDescription": {
"message": "With this option enabled, the extension will not automatically scrobble what you are watching. This is useful if you only want to use the history sync."
rafaelgomesxyz marked this conversation as resolved.
Show resolved Hide resolved
},
"disableScrobblingName": {
"message": "Disable scrobbling."
},
"errorNotification": {
"message": "Ocorreu um erro. :("
},
Expand All @@ -90,6 +99,9 @@
"hideSyncedName": {
"message": "Esconder itens sincronizados."
},
"history": {
"message": "Histórico"
},
"historySyncSuccess": {
"message": "$EPISODES$ episódios e $MOVIES$ filmes sincronizados.",
"placeholders": {
Expand Down Expand Up @@ -146,6 +158,12 @@
"notWatched": {
"message": "Não Assistido"
},
"notWatching": {
"message": "Assista algo!"
},
"nowScrobbling": {
"message": "Fazendo Scrobbling"
},
"on": {
"message": "No"
},
Expand All @@ -172,6 +190,15 @@
"saveOptionSuccess": {
"message": "Opção salva."
},
"scrobblePaused": {
"message": "O scrobble foi pausado."
},
"scrobbleStarted": {
"message": "O scrobble começou."
},
"scrobbleStopped": {
"message": "O scrobble parou."
},
"select": {
"message": "Selecionar:"
},
Expand All @@ -190,6 +217,12 @@
"sendReceiveSuggestionsName": {
"message": "Enviar / receber sugestões de correção."
},
"showNotificationsDescription": {
"message": "Com essa opção ativada, você receberá notificações no seu navegador sempre que um scrobble começar/parar ."
},
"showNotificationsName": {
"message": "Mostrar notificações no navegador."
},
"streamingServicesDescription": {
"message": "Escolha quais serviços de streaming deseja ativar."
},
Expand Down
2 changes: 2 additions & 0 deletions src/api/TraktApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export class TraktApi {
REVOKE_TOKEN_URL: string;
SEARCH_URL: string;
SHOWS_URL: string;
SCROBBLE_URL: string;
SYNC_URL: string;
SETTINGS_URL: string;

Expand All @@ -21,6 +22,7 @@ export class TraktApi {
this.REVOKE_TOKEN_URL = `${this.API_URL}/oauth/revoke`;
this.SEARCH_URL = `${this.API_URL}/search`;
this.SHOWS_URL = `${this.API_URL}/shows`;
this.SCROBBLE_URL = `${this.API_URL}/scrobble`;
this.SYNC_URL = `${this.API_URL}/sync/history`;
this.SETTINGS_URL = `${this.API_URL}/users/settings`;
}
Expand Down
95 changes: 95 additions & 0 deletions src/api/TraktScrobble.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { TraktItem } from '../models/TraktItem';
import { EventDispatcher } from '../services/Events';
import { Messaging } from '../services/Messaging';
import { RequestException, Requests } from '../services/Requests';
import { Shared } from '../services/Shared';
import { TraktApi } from './TraktApi';

export interface TraktScrobbleData {
movie?: {
ids: {
trakt: number;
};
};
episode?: {
ids: {
trakt: number;
};
};
progress: number;
}

class _TraktScrobble extends TraktApi {
START: number;
PAUSE: number;
STOP: number;

paths: Record<number, string>;

constructor() {
super();

this.START = 1;
this.PAUSE = 2;
this.STOP = 3;

this.paths = {
[this.START]: '/start',
[this.PAUSE]: '/pause',
[this.STOP]: '/stop',
};
}

start = async (item: TraktItem): Promise<void> => {
if (!Shared.isBackgroundPage) {
await Messaging.toBackground({ action: 'start-scrobble' });
}
await this.send(item, this.START);
};

pause = async (item: TraktItem): Promise<void> => {
await this.send(item, this.PAUSE);
};

stop = async (item: TraktItem): Promise<void> => {
await this.send(item, this.STOP);
if (!Shared.isBackgroundPage) {
await Messaging.toBackground({ action: 'stop-scrobble' });
}
};

send = async (item: TraktItem, scrobbleType: number): Promise<void> => {
const path = this.paths[scrobbleType];
try {
const data = {} as TraktScrobbleData;
if (item.type === 'show') {
data.episode = {
ids: {
trakt: item.id,
},
};
} else {
data.movie = {
ids: {
trakt: item.id,
},
};
}
data.progress = item.progress;
await Requests.send({
url: `${this.SCROBBLE_URL}${path}`,
method: 'POST',
body: data,
});
await EventDispatcher.dispatch('SCROBBLE_SUCCESS', null, { item, scrobbleType });
} catch (err) {
await EventDispatcher.dispatch('SCROBBLE_ERROR', null, {
item,
scrobbleType,
error: err as RequestException,
});
}
};
}

export const TraktScrobble = new _TraktScrobble();
Loading