Skip to content

Commit

Permalink
- added external config option for the auth credentials
Browse files Browse the repository at this point in the history
- minor command name fixes
  • Loading branch information
kappaflow committed Aug 2, 2020
1 parent aa1f880 commit 4b981ac
Show file tree
Hide file tree
Showing 9 changed files with 281 additions and 78 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
src/main/ignore_commit
outputDir

#Resources config
resources/config.properties
config.properties

.idea/**/vcs.xml

# User-specific stuff
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.0.2-alpha1 (2020.08.02)

* Added external config option for the auth credentials
* Minor command name fixes

## 0.0.1-alpha1 (2020.07.24)

* Initial commit
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ The information about parameters is available in the app when the action is spec
#### Recommendations
* The fetching period (*DELTA_PERIOD*) specified should have less than ~1000 clips to avoid missing clips (the global fetching period can have any date range).
* Fetching can crawl the same clips multiple times. To clean the list `-distinct` can be used.
* CLIENT_ID, CLIENT_SECRET, AUTH_TOKEN can be specified in *ClipsManager* before compiling. It may not be safe, but can be used in some cases to avoid entering credentials every time.
* *clientId*, *clientSecret*, *authToken* can be specified in *config.properties*. There are 2 ways to do it: 1st way - before compiling in the *resources* folder; 2nd way - put *config.properties* in the directory with an executable file (it applies above the embedded one). It may not be safe, but can be used in some cases to avoid entering credentials every time.
* Log level can be specified for most classes for the debugging to show more/less info.

## Modules
Expand Down
1 change: 1 addition & 0 deletions TwitchClipsManager.iml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
Expand Down
5 changes: 5 additions & 0 deletions config.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#Auth External Properties
#clientId=<clientId>
#clientSecret=<clientSecret>

#authToken=<authToken>
5 changes: 5 additions & 0 deletions resources/config.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#Auth Embedded Properties
#clientId=<clientId>
#clientSecret=<clientSecret>

#authToken=<authToken>
168 changes: 92 additions & 76 deletions src/main/com/twitchcm/ClipsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import main.com.twitchcm.filter.DashboardFetchClipsFilter;
import main.com.twitchcm.filter.FetchClipsFilter;
import main.com.twitchcm.filter.ProceedClipsFilter;
import main.com.twitchcm.tool.ConfigReader;
import main.com.twitchcm.tool.TwitchWebConnection;
import main.com.twitchcm.tool.Utils;

Expand All @@ -15,45 +16,46 @@
import java.util.HashMap;
import java.util.Map;

public class ClipsManager {
public class ClipsManager
{

//can be blank and init later
private final static String CLIENT_ID = "";
private final static String CLIENT_SECRET = "";
private static String m_clientId = ConfigReader.getClientIdProp();
private static String m_clientSecret = ConfigReader.getClientSecretProp();

//can be blank and init later
private final static String AUTH_TOKEN = "";
private static String m_authToken = ConfigReader.getAuthTokenProp();

//in case of using DB - DataSource.DATABASE should be used
private final static DataSourceEnum DATA_SOURCE = DataSourceEnum.FILES;

private boolean m_allowOverwrite = false;
private String m_rootDir = null;

private static final Map<AuthJsonEnum,String>m_auth = new HashMap<>();
private static final Map<AuthJsonEnum,String> m_auth = new HashMap<>();

//todo DataSource enum in the constructor args
public ClipsManager() {
m_auth.put(AuthJsonEnum.CLIENT_ID, CLIENT_ID);
m_auth.put(AuthJsonEnum.CLIENT_SECRET, CLIENT_SECRET);

m_auth.put(AuthJsonEnum.AUTH_TOKEN, AUTH_TOKEN);
public ClipsManager()
{
setClientAuth( m_clientId, m_clientSecret );
setAuthToken( m_authToken );
}

public void setAuthToken(String _authToken)
{
if (_authToken != null) {
m_auth.put(AuthJsonEnum.AUTH_TOKEN, _authToken);
if (_authToken != null)
{
m_auth.put( AuthJsonEnum.AUTH_TOKEN, _authToken );
}
}

public void setClientAuth(String _clientId, String _clientSecret)
{
if(_clientId != null) {
m_auth.put(AuthJsonEnum.CLIENT_ID, _clientId);
if (_clientId != null)
{
m_auth.put( AuthJsonEnum.CLIENT_ID, _clientId );
}
if(_clientSecret != null){
m_auth.put(AuthJsonEnum.CLIENT_SECRET, _clientSecret);
if (_clientSecret != null)
{
m_auth.put( AuthJsonEnum.CLIENT_SECRET, _clientSecret );
}
}

Expand All @@ -74,148 +76,162 @@ public String getCustomRootDir()

public static Map<AuthJsonEnum,String> getAuthCredential()
{
if(!m_auth.containsKey(AuthJsonEnum.CLIENT_ID)) {
m_auth.put(AuthJsonEnum.CLIENT_ID, CLIENT_ID);
if (!m_auth.containsKey( AuthJsonEnum.CLIENT_ID ))
{
m_auth.put( AuthJsonEnum.CLIENT_ID, m_clientId );
}
if(!m_auth.containsKey(AuthJsonEnum.CLIENT_SECRET)) {
m_auth.put(AuthJsonEnum.CLIENT_SECRET, CLIENT_SECRET);
if (!m_auth.containsKey( AuthJsonEnum.CLIENT_SECRET ))
{
m_auth.put( AuthJsonEnum.CLIENT_SECRET, m_clientSecret );
}

if(!m_auth.containsKey(AuthJsonEnum.AUTH_TOKEN)) {
m_auth.put(AuthJsonEnum.AUTH_TOKEN, AUTH_TOKEN);
if (!m_auth.containsKey( AuthJsonEnum.AUTH_TOKEN ))
{
m_auth.put( AuthJsonEnum.AUTH_TOKEN, m_authToken );
}

return m_auth;
}

public void gameIdToName(String _gameId) throws LoginException
{
if(_gameId != null) {
System.out.println(Utils.getGameName(_gameId, TwitchWebConnection.auth(m_auth)));
if (_gameId != null)
{
System.out.println( Utils.getGameName( _gameId, TwitchWebConnection.auth( m_auth ) ) );
}
}

public void gameNameToId(String _gameName) throws LoginException
{
if(_gameName != null) {
System.out.println(Utils.getGameId(_gameName, TwitchWebConnection.auth(m_auth)));
if (_gameName != null)
{
System.out.println( Utils.getGameId( _gameName, TwitchWebConnection.auth( m_auth ) ) );
}
}

public void channelIdToName(String _channelId) throws LoginException
{
if(_channelId != null) {
System.out.println(Utils.getBroadcasterLogin(_channelId, TwitchWebConnection.auth(m_auth)));
if (_channelId != null)
{
System.out.println( Utils.getBroadcasterLogin( _channelId, TwitchWebConnection.auth( m_auth ) ) );
}
}

public void channelNameToId(String _channelName) throws LoginException
{
if(_channelName != null) {
System.out.println(Utils.getBroadcasterId(_channelName, TwitchWebConnection.auth(m_auth)));
if (_channelName != null)
{
System.out.println( Utils.getBroadcasterId( _channelName, TwitchWebConnection.auth( m_auth ) ) );
}
}

private void setRootDir(ClipsActionAbstract _clipsActionObj)
{
if(m_rootDir != null) {
_clipsActionObj.setRootDir(m_rootDir);
if (m_rootDir != null)
{
_clipsActionObj.setRootDir( m_rootDir );
}
}

public void fetchTopClips(String _broadcasterId)
{
fetchTopClips(new FetchClipsFilter(_broadcasterId));
fetchTopClips( new FetchClipsFilter( _broadcasterId ) );
}

public void fetchTopClips(FetchClipsFilter _filter)
{
ClipsFetcher clipsFetcher = new ClipsFetcher(DATA_SOURCE, m_allowOverwrite);
setRootDir(clipsFetcher);
clipsFetcher.setAuth(m_auth);
clipsFetcher.setFetchFilter(_filter);
ClipsFetcher clipsFetcher = new ClipsFetcher( DATA_SOURCE, m_allowOverwrite );
setRootDir( clipsFetcher );
clipsFetcher.setAuth( m_auth );
clipsFetcher.setFetchFilter( _filter );
clipsFetcher.fetchTopClips();
}

public void fetchClips(FetchClipsFilter _filter)
{
ClipsFetcher clipsFetcher = new ClipsFetcher(DATA_SOURCE, m_allowOverwrite);
setRootDir(clipsFetcher);
clipsFetcher.setAuth(m_auth);
clipsFetcher.setFetchFilter(_filter);
ClipsFetcher clipsFetcher = new ClipsFetcher( DATA_SOURCE, m_allowOverwrite );
setRootDir( clipsFetcher );
clipsFetcher.setAuth( m_auth );
clipsFetcher.setFetchFilter( _filter );
clipsFetcher.fetchClips();
}

public void fetchDashboardClips(DashboardFetchClipsFilter _filter)
{
DashboardClipsFetcher clipsFetcher = new DashboardClipsFetcher(DATA_SOURCE, m_allowOverwrite);
setRootDir(clipsFetcher);
clipsFetcher.setAuth(m_auth);
clipsFetcher.setFetchFilter(_filter);
DashboardClipsFetcher clipsFetcher = new DashboardClipsFetcher( DATA_SOURCE, m_allowOverwrite );
setRootDir( clipsFetcher );
clipsFetcher.setAuth( m_auth );
clipsFetcher.setFetchFilter( _filter );
clipsFetcher.fetchClips();
}

public void distinctFetchedClips()
{
ClipsFetcher clipsFetcher = new ClipsFetcher(DATA_SOURCE, false);
setRootDir(clipsFetcher);
ClipsFetcher clipsFetcher = new ClipsFetcher( DATA_SOURCE, false );
setRootDir( clipsFetcher );
clipsFetcher.distinctClips();
}

public void downloadClips(String _eachTime, ProceedClipsFilter _proceedFilter)
{
try {
downloadClips(Integer.parseInt(_eachTime), _proceedFilter);
}catch (NumberFormatException e)
try
{
downloadClips( Integer.parseInt( _eachTime ), _proceedFilter );
}
catch (NumberFormatException e)
{
System.err.println(e.getMessage());
System.err.println( e.getMessage() );
}
}

public void downloadClips(int _eachTime, ProceedClipsFilter _proceedFilter)
{
ClipsDownloader clipsDownloader = new ClipsDownloader(DATA_SOURCE, m_allowOverwrite);
setRootDir(clipsDownloader);
clipsDownloader.setProceedFilter(_proceedFilter);
clipsDownloader.downloadClips(_eachTime);
ClipsDownloader clipsDownloader = new ClipsDownloader( DATA_SOURCE, m_allowOverwrite );
setRootDir( clipsDownloader );
clipsDownloader.setProceedFilter( _proceedFilter );
clipsDownloader.downloadClips( _eachTime );
}

public void deleteClips(String _eachTime, ProceedClipsFilter _proceedFilter)
{
try {
deleteClips(Integer.parseInt(_eachTime), _proceedFilter);
}catch (NumberFormatException e)
try
{
System.err.println(e.getMessage());
deleteClips( Integer.parseInt( _eachTime ), _proceedFilter );
}
catch (NumberFormatException e)
{
System.err.println( e.getMessage() );
}
}

public void deleteClips(int _eachTime, ProceedClipsFilter _proceedFilter)
{
ClipsDeleter clipsDeleter = new ClipsDeleter(DATA_SOURCE, m_allowOverwrite);
setRootDir(clipsDeleter);
clipsDeleter.setAuth(m_auth);
clipsDeleter.setProceedFilter(_proceedFilter);
clipsDeleter.deleteClips(_eachTime);
ClipsDeleter clipsDeleter = new ClipsDeleter( DATA_SOURCE, m_allowOverwrite );
setRootDir( clipsDeleter );
clipsDeleter.setAuth( m_auth );
clipsDeleter.setProceedFilter( _proceedFilter );
clipsDeleter.deleteClips( _eachTime );
}

public void createClip(String _vodId, String _title, String _vodTime, String _durationSec)
{
try {
createClip(_vodId, _title,
(float) Duration.parse(_vodTime).toMillis()/1000,
(float) Duration.parse(_durationSec).toMillis()/1000);
}catch (DateTimeParseException e)
try
{
createClip( _vodId, _title,
(float) Duration.parse( _vodTime ).toMillis() / 1000,
(float) Duration.parse( _durationSec ).toMillis() / 1000 );
}
catch (DateTimeParseException e)
{
System.err.println(e.getMessage());
System.err.println( e.getMessage() );
}
}

public void createClip(String _vodId, String _title, float _vodTimeSec, float _durationSec)
{
ClipsCreator clipsCreator = new ClipsCreator(DATA_SOURCE, m_allowOverwrite);
setRootDir(clipsCreator);
clipsCreator.setAuth(m_auth);
clipsCreator.createClip(_vodId, _title, _vodTimeSec, _durationSec);
ClipsCreator clipsCreator = new ClipsCreator( DATA_SOURCE, m_allowOverwrite );
setRootDir( clipsCreator );
clipsCreator.setAuth( m_auth );
clipsCreator.createClip( _vodId, _title, _vodTimeSec, _durationSec );
}
}
2 changes: 1 addition & 1 deletion src/main/com/twitchcm/enums/InputArgsEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public enum InputArgsEnum {
//Auth
CLIENT_ID("clientId", "clientId", "API client id", true),
CLIENT_SECRET("clientSecret", "clientSecret", "API client secret", true),
AUTH_TOKEN("auth", "authToken", "auth-token from cookies", true),
AUTH_TOKEN("authToken", "authToken", "auth-token from cookies", true),

//FetchFilter
BROADCASTER_ID("chId", "broadcasterId", "Channel id (user id) of a broadcaster from which the clip was created. Channel id can be obtained by using chNameToId Util", true),
Expand Down
Loading

0 comments on commit 4b981ac

Please sign in to comment.